about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/python-modules/gradio/default.nix
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/development/python-modules/gradio/default.nix')
-rw-r--r--nixpkgs/pkgs/development/python-modules/gradio/default.nix59
1 files changed, 48 insertions, 11 deletions
diff --git a/nixpkgs/pkgs/development/python-modules/gradio/default.nix b/nixpkgs/pkgs/development/python-modules/gradio/default.nix
index 19474d8d9fbf..bead2da9dfd7 100644
--- a/nixpkgs/pkgs/development/python-modules/gradio/default.nix
+++ b/nixpkgs/pkgs/development/python-modules/gradio/default.nix
@@ -1,8 +1,11 @@
 { lib
+, stdenv
 , buildPythonPackage
 , fetchPypi
 , pythonOlder
 , pythonRelaxDepsHook
+, writeShellScriptBin
+, gradio
 
 # pyproject
 , hatchling
@@ -31,15 +34,16 @@
 , python-multipart
 , pydub
 , pyyaml
-, requests
 , semantic-version
 , typing-extensions
 , uvicorn
-, websockets
+, typer
+, tomlkit
 
 # check
 , pytestCheckHook
 , boto3
+, gradio-pdf
 , ffmpeg
 , ipython
 , pytest-asyncio
@@ -53,23 +57,30 @@
 
 buildPythonPackage rec {
   pname = "gradio";
-  version = "3.44.3";
+  version = "4.9.1";
   format = "pyproject";
 
   disabled = pythonOlder "3.7";
 
-  # We use the Pypi release, as it provides prebuilt webui assets,
-  # and has more frequent releases compared to github tags
+  # We use the Pypi release, since it provides prebuilt webui assets,
+  # and upstream has stopped tagging releases since 3.41.0
   src = fetchPypi {
     inherit pname version;
-    hash = "sha256-3mXs9PwlzUo89VosBWtnsOzDQf/T22Yv7s5j6OLLp3M=";
+    hash = "sha256-KosxlmU5pYvuy5zysscuWM25IGXin7RLGEM9V2xPQrU=";
   };
 
   # fix packaging.ParserSyntaxError, which can't handle comments
   postPatch = ''
     sed -ie "s/ #.*$//g" requirements*.txt
+
+    # they bundle deps?
+    rm -rf venv/
   '';
 
+  pythonRelaxDeps = [
+    "tomlkit"
+  ];
+
   nativeBuildInputs = [
     pythonRelaxDepsHook
     hatchling
@@ -99,16 +110,17 @@ buildPythonPackage rec {
     python-multipart
     pydub
     pyyaml
-    requests
     semantic-version
     typing-extensions
     uvicorn
-    websockets
-  ];
+    typer
+    tomlkit
+  ] ++ typer.passthru.optional-dependencies.all;
 
   nativeCheckInputs = [
     pytestCheckHook
     boto3
+    gradio-pdf
     ffmpeg
     ipython
     pytest-asyncio
@@ -119,13 +131,19 @@ buildPythonPackage rec {
     tqdm
     transformers
     vega-datasets
-  ];
+
+    # mock npm to make `shutil.which("npm")` pass
+    (writeShellScriptBin "npm" "false")
+  ] ++ pydantic.passthru.optional-dependencies.email;
 
   # Add a pytest hook skipping tests that access network, marking them as "Expected fail" (xfail).
   # We additionally xfail FileNotFoundError, since the gradio devs often fail to upload test assets to pypi.
   preCheck = ''
     export HOME=$TMPDIR
     cat ${./conftest-skip-network-errors.py} >> test/conftest.py
+  '' + lib.optionalString stdenv.isDarwin ''
+    # OSError: [Errno 24] Too many open files
+    ulimit -n 4096
   '';
 
   disabledTests = [
@@ -148,12 +166,14 @@ buildPythonPackage rec {
     "test_shapley_text"
   ];
   disabledTestPaths = [
+    # 100% touches network
+    "test/test_networking.py"
     # makes pytest freeze 50% of the time
     "test/test_interfaces.py"
   ];
   pytestFlagsArray = [
     "-x"  # abort on first failure
-    #"-m" "not flaky" # doesn't work, even when advertised
+    "-m 'not flaky'"
     #"-W" "ignore" # uncomment for debugging help
   ];
 
@@ -165,6 +185,23 @@ buildPythonPackage rec {
 
   pythonImportsCheck = [ "gradio" ];
 
+  # Cyclic dependencies are fun!
+  # This is gradio without gradio-client and gradio-pdf
+  passthru = {
+    sans-reverse-dependencies = (gradio.override (old: {
+      gradio-client = null;
+      gradio-pdf = null;
+    })).overridePythonAttrs (old: {
+      pname = old.pname + "-sans-client";
+      nativeBuildInputs = (old.nativeBuildInputs or []) ++ [ pythonRelaxDepsHook ];
+      pythonRemoveDeps = (old.pythonRemoveDeps or []) ++ [ "gradio-client" ];
+      doInstallCheck = false;
+      doCheck = false;
+      pythonImportsCheck = null;
+      dontCheckRuntimeDeps = true;
+    });
+  };
+
   meta = with lib; {
     homepage = "https://www.gradio.app/";
     description = "Python library for easily interacting with trained machine learning models";