summaryrefslogtreecommitdiff
path: root/pkgs/development/python-modules/urllib3/default.nix
blob: 30ab03edc69436dc282c7be12bc1293b91309f57 (plain)
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
{
  lib,
  buildPythonPackage,
  fetchPypi,
  isPyPy,

  # build-system
  hatchling,
  hatch-vcs,

  # optional-dependencies
  backports-zstd,
  brotli,
  brotlicffi,
  h2,
  pysocks,

  # tests
  httpx,
  pyopenssl,
  pytestCheckHook,
  pytest-socket,
  pytest-timeout,
  quart,
  quart-trio,
  tornado,
  trio,
  trustme,
}:

let
  self = buildPythonPackage rec {
    pname = "urllib3";
    version = "2.6.0";
    pyproject = true;

    src = fetchPypi {
      inherit pname version;
      hash = "sha256-y5vO9aSzRdXaXRRdw+MINPWOgBiCjLxyTTC0y31NSfE=";
    };

    build-system = [
      hatchling
      hatch-vcs
    ];

    postPatch = ''
      substituteInPlace pyproject.toml \
        --replace-fail ', "setuptools-scm>=8,<10"' ""
    '';

    optional-dependencies = {
      brotli = if isPyPy then [ brotlicffi ] else [ brotli ];
      h2 = [ h2 ];
      socks = [ pysocks ];
      zstd = [ backports-zstd ];
    };

    nativeCheckInputs = [
      httpx
      pyopenssl
      pytest-socket
      pytest-timeout
      pytestCheckHook
      quart
      quart-trio
      tornado
      trio
      trustme
    ]
    ++ lib.concatAttrValues optional-dependencies;

    disabledTestMarks = [
      "requires_network"
    ];

    # Tests in urllib3 are mostly timeout-based instead of event-based and
    # are therefore inherently flaky. On your own machine, the tests will
    # typically build fine, but on a loaded cluster such as Hydra random
    # timeouts will occur.
    #
    # The urllib3 test suite has two different timeouts in their test suite
    # (see `test/__init__.py`):
    # - SHORT_TIMEOUT
    # - LONG_TIMEOUT
    # When CI is in the env, LONG_TIMEOUT will be significantly increased.
    # Still, failures can occur and for that reason tests are disabled.
    doCheck = false;

    passthru.tests.pytest = self.overridePythonAttrs (_: {
      doCheck = true;
    });

    preCheck = ''
      export CI # Increases LONG_TIMEOUT
    '';

    pythonImportsCheck = [ "urllib3" ];

    meta = {
      description = "Powerful, user-friendly HTTP client for Python";
      homepage = "https://github.com/urllib3/urllib3";
      changelog = "https://github.com/urllib3/urllib3/blob/${version}/CHANGES.rst";
      license = lib.licenses.mit;
      maintainers = with lib.maintainers; [ fab ];
    };
  };
in
self