1{
2 lib,
3 buildPythonPackage,
4 fetchPypi,
5 isPyPy,
6
7 # build-system
8 hatchling,
9 hatch-vcs,
10
11 # optional-dependencies
12 brotli,
13 brotlicffi,
14 pysocks,
15 zstandard,
16
17 # tests
18 pytestCheckHook,
19 pytest-timeout,
20 tornado,
21 trustme,
22}:
23
24let
25 self = buildPythonPackage rec {
26 pname = "urllib3";
27 version = "2.5.0";
28 pyproject = true;
29
30 src = fetchPypi {
31 inherit pname version;
32 hash = "sha256-P8R3M8fkGdS8P2s9wrT4kLt0OQajDVa6Slv6S7/5J2A=";
33 };
34
35 build-system = [
36 hatchling
37 hatch-vcs
38 ];
39
40 postPatch = ''
41 substituteInPlace pyproject.toml \
42 --replace-fail ', "setuptools-scm>=8,<9"' ""
43 '';
44
45 optional-dependencies = {
46 brotli = if isPyPy then [ brotlicffi ] else [ brotli ];
47 socks = [ pysocks ];
48 zstd = [ zstandard ];
49 };
50
51 nativeCheckInputs = [
52 pytest-timeout
53 pytestCheckHook
54 tornado
55 trustme
56 ]
57 ++ lib.flatten (builtins.attrValues optional-dependencies);
58
59 # Tests in urllib3 are mostly timeout-based instead of event-based and
60 # are therefore inherently flaky. On your own machine, the tests will
61 # typically build fine, but on a loaded cluster such as Hydra random
62 # timeouts will occur.
63 #
64 # The urllib3 test suite has two different timeouts in their test suite
65 # (see `test/__init__.py`):
66 # - SHORT_TIMEOUT
67 # - LONG_TIMEOUT
68 # When CI is in the env, LONG_TIMEOUT will be significantly increased.
69 # Still, failures can occur and for that reason tests are disabled.
70 doCheck = false;
71
72 passthru.tests.pytest = self.overridePythonAttrs (_: {
73 doCheck = true;
74 });
75
76 preCheck = ''
77 export CI # Increases LONG_TIMEOUT
78 '';
79
80 pythonImportsCheck = [ "urllib3" ];
81
82 meta = with lib; {
83 description = "Powerful, user-friendly HTTP client for Python";
84 homepage = "https://github.com/urllib3/urllib3";
85 changelog = "https://github.com/urllib3/urllib3/blob/${version}/CHANGES.rst";
86 license = licenses.mit;
87 maintainers = with maintainers; [ fab ];
88 };
89 };
90in
91self