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.11.0";
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-dj8hJPXUBbFG9awP3o0vgyPt+gcCgzKKEQTEHkrEimA=";
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 pytestFlags = [
90 #"-x" "-Wignore" # uncomment for debugging help
91 ];
92
93 enabledTestPaths = [
94 "test/"
95 ];
96
97 disabledTestMarks = [
98 "flaky"
99 ];
100
101 disabledTests = lib.optionals stdenv.hostPlatform.isDarwin [
102 # flaky: OSError: Cannot find empty port in range: 7860-7959
103 "test_layout_components_in_output"
104 "test_layout_and_state_components_in_output"
105 "test_upstream_exceptions"
106 "test_httpx_kwargs"
107 ];
108
109 pythonImportsCheck = [ "gradio_client" ];
110
111 __darwinAllowLocalNetworking = true;
112
113 passthru.updateScript = nix-update-script {
114 extraArgs = [
115 "--version-regex"
116 "gradio_client@(.*)"
117 ];
118 };
119
120 meta = {
121 homepage = "https://www.gradio.app/";
122 changelog = "https://github.com/gradio-app/gradio/releases/tag/gradio_client@${version}";
123 description = "Lightweight library to use any Gradio app as an API";
124 license = lib.licenses.asl20;
125 maintainers = with lib.maintainers; [ pbsds ];
126 };
127}