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