1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 fetchFromGitHub,
6 nix-update-script,
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 rich,
27 safehttpx,
28 tomlkit,
29 writableTmpDirAsHomeHook,
30}:
31
32buildPythonPackage rec {
33 pname = "gradio-client";
34 version = "1.10.1";
35 pyproject = true;
36
37 # no tests on pypi
38 src = fetchFromGitHub {
39 owner = "gradio-app";
40 repo = "gradio";
41 # not to be confused with @gradio/client@${version}
42 tag = "gradio_client@${version}";
43 sparseCheckout = [ "client/python" ];
44 hash = "sha256-jIJkJvXy4mKQN0gVb4nm3hCzgk9qofBrXc3Tws2n2qw=";
45 };
46
47 sourceRoot = "${src.name}/client/python";
48
49 # upstream adds upper constraints because they can, not because the need to
50 # https://github.com/gradio-app/gradio/pull/4885
51 pythonRelaxDeps = [
52 # only backward incompat is dropping py3.7 support
53 "websockets"
54 ];
55
56 build-system = [
57 hatchling
58 hatch-requirements-txt
59 hatch-fancy-pypi-readme
60 ];
61
62 dependencies = [
63 fsspec
64 httpx
65 huggingface-hub
66 packaging
67 typing-extensions
68 websockets
69 ];
70
71 nativeCheckInputs = [
72 gradio.sans-reverse-dependencies
73 pydub
74 pytest-asyncio
75 pytestCheckHook
76 rich
77 safehttpx
78 tomlkit
79 writableTmpDirAsHomeHook
80 ];
81 # ensuring we don't propagate this intermediate build
82 disallowedReferences = [ gradio.sans-reverse-dependencies ];
83
84 # Add a pytest hook skipping tests that access network, marking them as "Expected fail" (xfail).
85 preCheck = ''
86 cat ${./conftest-skip-network-errors.py} >> test/conftest.py
87 '';
88
89 pytestFlagsArray = [
90 "test/"
91 "-m 'not flaky'"
92 #"-x" "-W" "ignore" # uncomment for debugging help
93 ];
94
95 disabledTests = lib.optionals stdenv.hostPlatform.isDarwin [
96 # flaky: OSError: Cannot find empty port in range: 7860-7959
97 "test_layout_components_in_output"
98 "test_layout_and_state_components_in_output"
99 "test_upstream_exceptions"
100 "test_httpx_kwargs"
101 ];
102
103 pythonImportsCheck = [ "gradio_client" ];
104
105 __darwinAllowLocalNetworking = true;
106
107 passthru.updateScript = nix-update-script {
108 extraArgs = [
109 "--version-regex"
110 "gradio_client@(.*)"
111 ];
112 };
113
114 meta = {
115 homepage = "https://www.gradio.app/";
116 changelog = "https://github.com/gradio-app/gradio/releases/tag/gradio_client@${version}";
117 description = "Lightweight library to use any Gradio app as an API";
118 license = lib.licenses.asl20;
119 maintainers = with lib.maintainers; [ pbsds ];
120 };
121}