2022-07-18 02:35:11 +02:00
|
|
|
{ lib
|
2024-01-16 00:08:09 +01:00
|
|
|
, stdenv
|
2022-07-18 02:35:11 +02:00
|
|
|
, buildPythonPackage
|
|
|
|
, fetchPypi
|
|
|
|
, pythonOlder
|
|
|
|
, pythonRelaxDepsHook
|
2023-12-15 00:16:37 +01:00
|
|
|
, writeShellScriptBin
|
2023-12-17 00:16:26 +01:00
|
|
|
, gradio
|
2022-07-18 02:35:11 +02:00
|
|
|
|
|
|
|
# pyproject
|
|
|
|
, hatchling
|
|
|
|
, hatch-requirements-txt
|
|
|
|
, hatch-fancy-pypi-readme
|
|
|
|
|
|
|
|
# runtime
|
|
|
|
, setuptools
|
|
|
|
, aiofiles
|
|
|
|
, altair
|
|
|
|
, fastapi
|
|
|
|
, ffmpy
|
2023-09-08 15:46:39 +02:00
|
|
|
, gradio-client
|
|
|
|
, httpx
|
|
|
|
, huggingface-hub
|
|
|
|
, importlib-resources
|
|
|
|
, jinja2
|
2022-07-18 02:35:11 +02:00
|
|
|
, markupsafe
|
|
|
|
, matplotlib
|
|
|
|
, numpy
|
|
|
|
, orjson
|
2023-09-08 15:46:39 +02:00
|
|
|
, packaging
|
2022-07-18 02:35:11 +02:00
|
|
|
, pandas
|
|
|
|
, pillow
|
2023-09-08 15:46:39 +02:00
|
|
|
, pydantic
|
2022-07-18 02:35:11 +02:00
|
|
|
, python-multipart
|
|
|
|
, pydub
|
|
|
|
, pyyaml
|
2023-09-08 15:46:39 +02:00
|
|
|
, semantic-version
|
|
|
|
, typing-extensions
|
2022-07-18 02:35:11 +02:00
|
|
|
, uvicorn
|
2023-12-15 00:16:37 +01:00
|
|
|
, typer
|
|
|
|
, tomlkit
|
2022-07-18 02:35:11 +02:00
|
|
|
|
|
|
|
# check
|
|
|
|
, pytestCheckHook
|
2023-09-08 15:46:39 +02:00
|
|
|
, boto3
|
2023-12-15 00:16:37 +01:00
|
|
|
, gradio-pdf
|
2023-09-08 15:46:39 +02:00
|
|
|
, ffmpeg
|
|
|
|
, ipython
|
2022-07-18 02:35:11 +02:00
|
|
|
, pytest-asyncio
|
|
|
|
, respx
|
|
|
|
, scikit-image
|
2023-09-08 15:46:39 +02:00
|
|
|
, torch
|
|
|
|
, tqdm
|
|
|
|
, transformers
|
2023-11-04 05:41:12 +01:00
|
|
|
, vega-datasets
|
2022-07-18 02:35:11 +02:00
|
|
|
}:
|
|
|
|
|
|
|
|
buildPythonPackage rec {
|
|
|
|
pname = "gradio";
|
2024-02-29 01:54:45 +01:00
|
|
|
version = "4.19.2";
|
2022-07-18 02:35:11 +02:00
|
|
|
format = "pyproject";
|
|
|
|
|
|
|
|
disabled = pythonOlder "3.7";
|
|
|
|
|
2023-12-15 00:16:37 +01:00
|
|
|
# We use the Pypi release, since it provides prebuilt webui assets,
|
|
|
|
# and upstream has stopped tagging releases since 3.41.0
|
2022-07-18 02:35:11 +02:00
|
|
|
src = fetchPypi {
|
|
|
|
inherit pname version;
|
2024-02-29 01:54:45 +01:00
|
|
|
hash = "sha256-b+WBW7Tfru0fx0Ijv/2R2nChtGMVivjF4D0BuwkGih0=";
|
2022-07-18 02:35:11 +02:00
|
|
|
};
|
|
|
|
|
2023-09-08 15:46:39 +02:00
|
|
|
# fix packaging.ParserSyntaxError, which can't handle comments
|
|
|
|
postPatch = ''
|
|
|
|
sed -ie "s/ #.*$//g" requirements*.txt
|
2023-12-15 00:16:37 +01:00
|
|
|
|
|
|
|
# they bundle deps?
|
|
|
|
rm -rf venv/
|
2023-09-08 15:46:39 +02:00
|
|
|
'';
|
2022-07-18 02:35:11 +02:00
|
|
|
|
2023-12-15 00:16:37 +01:00
|
|
|
pythonRelaxDeps = [
|
|
|
|
"tomlkit"
|
|
|
|
];
|
|
|
|
|
2024-02-29 01:54:45 +01:00
|
|
|
pythonRemoveDeps = [
|
|
|
|
# our package is presented as a binary, not a python lib - and
|
|
|
|
# this isn't a real runtime dependency
|
|
|
|
"ruff"
|
|
|
|
];
|
|
|
|
|
2022-07-18 02:35:11 +02:00
|
|
|
nativeBuildInputs = [
|
|
|
|
pythonRelaxDepsHook
|
|
|
|
hatchling
|
|
|
|
hatch-requirements-txt
|
|
|
|
hatch-fancy-pypi-readme
|
|
|
|
];
|
|
|
|
|
|
|
|
propagatedBuildInputs = [
|
2023-09-08 15:46:39 +02:00
|
|
|
setuptools # needed for 'pkg_resources'
|
2022-07-18 02:35:11 +02:00
|
|
|
aiofiles
|
|
|
|
altair
|
|
|
|
fastapi
|
|
|
|
ffmpy
|
2023-09-08 15:46:39 +02:00
|
|
|
gradio-client
|
|
|
|
httpx
|
|
|
|
huggingface-hub
|
|
|
|
importlib-resources
|
|
|
|
jinja2
|
2022-07-18 02:35:11 +02:00
|
|
|
markupsafe
|
|
|
|
matplotlib
|
|
|
|
numpy
|
|
|
|
orjson
|
2023-09-08 15:46:39 +02:00
|
|
|
packaging
|
2022-07-18 02:35:11 +02:00
|
|
|
pandas
|
|
|
|
pillow
|
2023-09-08 15:46:39 +02:00
|
|
|
pydantic
|
2022-07-18 02:35:11 +02:00
|
|
|
python-multipart
|
|
|
|
pydub
|
|
|
|
pyyaml
|
2023-09-08 15:46:39 +02:00
|
|
|
semantic-version
|
|
|
|
typing-extensions
|
2022-07-18 02:35:11 +02:00
|
|
|
uvicorn
|
2023-12-15 00:16:37 +01:00
|
|
|
typer
|
|
|
|
tomlkit
|
|
|
|
] ++ typer.passthru.optional-dependencies.all;
|
2022-07-18 02:35:11 +02:00
|
|
|
|
|
|
|
nativeCheckInputs = [
|
|
|
|
pytestCheckHook
|
2023-09-08 15:46:39 +02:00
|
|
|
boto3
|
2023-12-15 00:16:37 +01:00
|
|
|
gradio-pdf
|
2023-09-08 15:46:39 +02:00
|
|
|
ffmpeg
|
|
|
|
ipython
|
2022-07-18 02:35:11 +02:00
|
|
|
pytest-asyncio
|
|
|
|
respx
|
|
|
|
scikit-image
|
|
|
|
# shap is needed as well, but breaks too often
|
2023-09-08 15:46:39 +02:00
|
|
|
torch
|
|
|
|
tqdm
|
|
|
|
transformers
|
2023-11-04 05:41:12 +01:00
|
|
|
vega-datasets
|
2023-12-15 00:16:37 +01:00
|
|
|
|
|
|
|
# mock npm to make `shutil.which("npm")` pass
|
|
|
|
(writeShellScriptBin "npm" "false")
|
|
|
|
] ++ pydantic.passthru.optional-dependencies.email;
|
2022-07-18 02:35:11 +02:00
|
|
|
|
|
|
|
# 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.
|
2023-09-08 15:46:39 +02:00
|
|
|
preCheck = ''
|
2022-07-18 02:35:11 +02:00
|
|
|
export HOME=$TMPDIR
|
|
|
|
cat ${./conftest-skip-network-errors.py} >> test/conftest.py
|
2024-01-16 00:08:09 +01:00
|
|
|
'' + lib.optionalString stdenv.isDarwin ''
|
|
|
|
# OSError: [Errno 24] Too many open files
|
|
|
|
ulimit -n 4096
|
2022-07-18 02:35:11 +02:00
|
|
|
'';
|
|
|
|
|
|
|
|
disabledTests = [
|
|
|
|
# Actually broken
|
|
|
|
"test_mount_gradio_app"
|
|
|
|
|
2023-09-08 15:46:39 +02:00
|
|
|
# requires network, it caught our xfail exception
|
|
|
|
"test_error_analytics_successful"
|
2022-07-18 02:35:11 +02:00
|
|
|
|
|
|
|
# Flaky, tries to pin dependency behaviour. Sensitive to dep versions
|
|
|
|
# These error only affect downstream use of the check dependencies.
|
|
|
|
"test_no_color"
|
|
|
|
"test_in_interface_as_output"
|
|
|
|
"test_should_warn_url_not_having_version"
|
|
|
|
|
|
|
|
# Flaky, unknown reason
|
|
|
|
"test_in_interface"
|
|
|
|
|
|
|
|
# shap is too often broken in nixpkgs
|
|
|
|
"test_shapley_text"
|
2024-02-29 01:54:45 +01:00
|
|
|
|
|
|
|
# fails without network
|
|
|
|
"test_download_if_url_correct_parse"
|
2022-07-18 02:35:11 +02:00
|
|
|
];
|
|
|
|
disabledTestPaths = [
|
2023-12-15 00:16:37 +01:00
|
|
|
# 100% touches network
|
|
|
|
"test/test_networking.py"
|
2022-07-18 02:35:11 +02:00
|
|
|
# makes pytest freeze 50% of the time
|
|
|
|
"test/test_interfaces.py"
|
|
|
|
];
|
2023-09-08 15:46:39 +02:00
|
|
|
pytestFlagsArray = [
|
|
|
|
"-x" # abort on first failure
|
2023-12-15 00:16:37 +01:00
|
|
|
"-m 'not flaky'"
|
2023-09-08 15:46:39 +02:00
|
|
|
#"-W" "ignore" # uncomment for debugging help
|
|
|
|
];
|
2022-07-18 02:35:11 +02:00
|
|
|
|
|
|
|
# check the binary works outside the build env
|
|
|
|
doInstallCheck = true;
|
|
|
|
postInstallCheck = ''
|
2023-09-08 15:46:39 +02:00
|
|
|
env --ignore-environment $out/bin/gradio environment >/dev/null
|
2022-07-18 02:35:11 +02:00
|
|
|
'';
|
|
|
|
|
|
|
|
pythonImportsCheck = [ "gradio" ];
|
|
|
|
|
2023-12-17 00:16:26 +01:00
|
|
|
# Cyclic dependencies are fun!
|
|
|
|
# This is gradio without gradio-client and gradio-pdf
|
|
|
|
passthru = {
|
|
|
|
sans-reverse-dependencies = (gradio.override (old: {
|
|
|
|
gradio-client = null;
|
2023-12-15 00:16:37 +01:00
|
|
|
gradio-pdf = null;
|
2023-12-17 00:16:26 +01:00
|
|
|
})).overridePythonAttrs (old: {
|
|
|
|
pname = old.pname + "-sans-client";
|
|
|
|
pythonRemoveDeps = (old.pythonRemoveDeps or []) ++ [ "gradio-client" ];
|
|
|
|
doInstallCheck = false;
|
|
|
|
doCheck = false;
|
|
|
|
pythonImportsCheck = null;
|
|
|
|
dontCheckRuntimeDeps = true;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-07-18 02:35:11 +02:00
|
|
|
meta = with lib; {
|
|
|
|
homepage = "https://www.gradio.app/";
|
|
|
|
description = "Python library for easily interacting with trained machine learning models";
|
|
|
|
license = licenses.asl20;
|
|
|
|
maintainers = with maintainers; [ pbsds ];
|
|
|
|
};
|
|
|
|
}
|