about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/python-modules/gradio/default.nix
blob: ffb99d729328727ca20856109648b95cfcc381f6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
{ lib
, buildPythonPackage
, fetchPypi
, pythonOlder
, pythonRelaxDepsHook
, writeText

# pyproject
, hatchling
, hatch-requirements-txt
, hatch-fancy-pypi-readme

# runtime
, setuptools
, aiofiles
, aiohttp
, altair
, fastapi
, ffmpy
, markdown-it-py
, mdit-py-plugins
, markupsafe
, matplotlib
, numpy
, orjson
, pandas
, pillow
, pycryptodome
, python-multipart
, pydub
, pyyaml
, requests
, uvicorn
, jinja2
, fsspec
, httpx
, pydantic
, websockets
, typing-extensions

# check
, pytestCheckHook
, pytest-asyncio
, mlflow
, huggingface-hub
, transformers
, wandb
, respx
, scikit-image
, ipython
, ffmpeg
, vega_datasets
, boto3
}:

buildPythonPackage rec {
  pname = "gradio";
  version = "3.20.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
  src = fetchPypi {
    inherit pname version;
    hash = "sha256-oG97GwehyBWjWXzDqyfj+x2mAfM6OQhYKdA3j0Rv8Vs=";
  };

  pythonRelaxDeps = [
    "mdit-py-plugins"
  ];

  nativeBuildInputs = [
    pythonRelaxDepsHook
    hatchling
    hatch-requirements-txt
    hatch-fancy-pypi-readme
  ];

  propagatedBuildInputs = [
    setuptools # needs pkg_resources
    aiofiles
    aiohttp
    altair
    fastapi
    ffmpy
    markdown-it-py
    mdit-py-plugins
    markupsafe
    matplotlib
    numpy
    orjson
    pandas
    pillow
    pycryptodome
    python-multipart
    pydub
    pyyaml
    requests
    uvicorn
    jinja2
    fsspec
    httpx
    pydantic
    websockets
    typing-extensions
  ] ++ markdown-it-py.optional-dependencies.linkify;

  nativeCheckInputs = [
    pytestCheckHook
    pytest-asyncio
    mlflow
    #comet-ml # FIXME: enable once packaged
    huggingface-hub
    transformers
    wandb
    respx
    scikit-image
    ipython
    ffmpeg
    vega_datasets
    boto3
    # shap is needed as well, but breaks too often
  ];

  # 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 = let
  in ''
    export HOME=$TMPDIR
    cat ${./conftest-skip-network-errors.py} >> test/conftest.py
  '';

  disabledTests = [
    # Actually broken
    "test_mount_gradio_app"

    # FIXME: enable once comet-ml is packaged
    "test_inline_display"
    "test_integration_comet"

    # 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"
  ];
  disabledTestPaths = [
    # makes pytest freeze 50% of the time
    "test/test_interfaces.py"
  ];
  #pytestFlagsArray = [ "-x" "-W" "ignore" ]; # uncomment for debugging help

  # check the binary works outside the build env
  doInstallCheck = true;
  postInstallCheck = ''
    env --ignore-environment $out/bin/gradio --help >/dev/null
  '';

  pythonImportsCheck = [ "gradio" ];

  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 ];
  };
}