nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 fetchFromGitHub,
6 gitUpdater,
7
8 # build-system
9 hatchling,
10 hatch-requirements-txt,
11 hatch-fancy-pypi-readme,
12
13 # dependencies
14 fsspec,
15 httpx,
16 huggingface-hub,
17 packaging,
18 typing-extensions,
19 websockets,
20
21 # tests
22 gradio,
23 pydub,
24 pytest-asyncio,
25 pytestCheckHook,
26 requests,
27 rich,
28 safehttpx,
29 tomlkit,
30 writableTmpDirAsHomeHook,
31}:
32
33buildPythonPackage rec {
34 pname = "gradio-client";
35 version = "2.0.1";
36 pyproject = true;
37
38 # no tests on pypi
39 src = fetchFromGitHub {
40 owner = "gradio-app";
41 repo = "gradio";
42 # not to be confused with @gradio/client@${version}
43 # tag = "gradio_client@${version}";
44 # TODO: switch back to a tag next release, if they tag it.
45 rev = "7a8894d7249ee20c2f7a896237e290e99661fd43"; # 2.0.1
46 sparseCheckout = [
47 "client/python"
48 "gradio/media_assets"
49 ];
50 hash = "sha256-p3okK48DJjjyvUzedNR60r5P8aKUxjE+ocb3EplZ6Uk=";
51 };
52
53 sourceRoot = "${src.name}/client/python";
54
55 postPatch = ''
56 # Because we set sourceRoot above, the folders "client/python"
57 # don't exist, as far as this is concerned.
58 substituteInPlace test/conftest.py \
59 --replace-fail 'from client.python.test import media_data' 'import media_data'
60 '';
61
62 # upstream adds upper constraints because they can, not because the need to
63 # https://github.com/gradio-app/gradio/pull/4885
64 pythonRelaxDeps = [
65 # only backward incompat is dropping py3.7 support
66 "websockets"
67 ];
68
69 build-system = [
70 hatchling
71 hatch-requirements-txt
72 hatch-fancy-pypi-readme
73 ];
74
75 dependencies = [
76 fsspec
77 httpx
78 huggingface-hub
79 packaging
80 typing-extensions
81 websockets
82 ];
83
84 nativeCheckInputs = [
85 gradio.sans-reverse-dependencies
86 pydub
87 pytest-asyncio
88 pytestCheckHook
89 requests
90 rich
91 safehttpx
92 tomlkit
93 writableTmpDirAsHomeHook
94 ];
95 # ensuring we don't propagate this intermediate build
96 disallowedReferences = [ gradio.sans-reverse-dependencies ];
97
98 postInstall = ''
99 mkdir -p $out/lib/gradio
100 cp -r ../../gradio/media_assets $out/lib/gradio
101 '';
102
103 # Add a pytest hook skipping tests that access network, marking them as "Expected fail" (xfail).
104 preCheck = ''
105 cat ${./conftest-skip-network-errors.py} >> test/conftest.py
106 '';
107
108 pytestFlags = [
109 #"-x" "-Wignore" # uncomment for debugging help
110 ];
111
112 enabledTestPaths = [
113 "test/"
114 ];
115
116 disabledTestMarks = [
117 "flaky"
118 ];
119
120 disabledTests = lib.optionals stdenv.hostPlatform.isDarwin [
121 # flaky: OSError: Cannot find empty port in range: 7860-7959
122 "test_layout_components_in_output"
123 "test_layout_and_state_components_in_output"
124 "test_upstream_exceptions"
125 "test_httpx_kwargs"
126 ];
127
128 pythonImportsCheck = [ "gradio_client" ];
129
130 __darwinAllowLocalNetworking = true;
131
132 passthru.updateScript = gitUpdater {
133 rev-prefix = "gradio_client@";
134 ignoredVersions = ".*-(beta|dev).*";
135 };
136
137 meta = {
138 homepage = "https://www.gradio.app/";
139 changelog = "https://github.com/gradio-app/gradio/releases/tag/gradio_client@${version}";
140 description = "Lightweight library to use any Gradio app as an API";
141 license = lib.licenses.asl20;
142 maintainers = with lib.maintainers; [ pbsds ];
143 };
144}