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