1{
2 lib,
3 buildPythonPackage,
4 fetchFromGitHub,
5 nix-update-script,
6 pythonOlder,
7 # pyproject
8 hatchling,
9 hatch-requirements-txt,
10 hatch-fancy-pypi-readme,
11 # runtime
12 setuptools,
13 fsspec,
14 httpx,
15 huggingface-hub,
16 packaging,
17 requests,
18 typing-extensions,
19 websockets,
20 # checkInputs
21 pytestCheckHook,
22 pytest-asyncio,
23 pydub,
24 rich,
25 tomlkit,
26 gradio,
27}:
28
29buildPythonPackage rec {
30 pname = "gradio-client";
31 version = "1.0.1";
32 pyproject = true;
33
34 disabled = pythonOlder "3.8";
35
36 # no tests on pypi
37 src = fetchFromGitHub {
38 owner = "gradio-app";
39 repo = "gradio";
40 # not to be confused with @gradio/client@${version}
41 rev = "refs/tags/gradio_client@${version}";
42 sparseCheckout = [ "client/python" ];
43 hash = "sha256-nbOWg2ZPcXTft7e4tR5p5xecVU62en0hEdXqAgLDZF4=";
44 };
45 prePatch = ''
46 cd client/python
47 '';
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 setuptools # needed for 'pkg_resources'
64 fsspec
65 httpx
66 huggingface-hub
67 packaging
68 typing-extensions
69 websockets
70 ];
71
72 nativeCheckInputs = [
73 pytestCheckHook
74 pytest-asyncio
75 pydub
76 rich
77 tomlkit
78 gradio.sans-reverse-dependencies
79 ];
80 # ensuring we don't propagate this intermediate build
81 disallowedReferences = [ gradio.sans-reverse-dependencies ];
82
83 # Add a pytest hook skipping tests that access network, marking them as "Expected fail" (xfail).
84 preCheck = ''
85 export HOME=$TMPDIR
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 pythonImportsCheck = [ "gradio_client" ];
96
97 __darwinAllowLocalNetworking = true;
98
99 passthru.updateScript = nix-update-script {
100 extraArgs = [ "--version-regex" "gradio_client@(.*)" ];
101 };
102
103 meta = with lib; {
104 homepage = "https://www.gradio.app/";
105 description = "Lightweight library to use any Gradio app as an API";
106 license = licenses.asl20;
107 maintainers = with maintainers; [ pbsds ];
108 };
109}