1{
2 lib,
3 aetcd,
4 buildPythonPackage,
5 coredis,
6 deprecated,
7 etcd3,
8 fetchFromGitHub,
9 flaky,
10 hiro,
11 importlib-resources,
12 motor,
13 packaging,
14 pymemcache,
15 pymongo,
16 pytest-asyncio,
17 pytest-benchmark,
18 pytest-cov-stub,
19 pytest-lazy-fixtures,
20 pytestCheckHook,
21 pythonOlder,
22 redis,
23 setuptools,
24 typing-extensions,
25}:
26
27buildPythonPackage rec {
28 pname = "limits";
29 version = "4.0.1";
30 pyproject = true;
31
32 disabled = pythonOlder "3.8";
33
34 src = fetchFromGitHub {
35 owner = "alisaifee";
36 repo = "limits";
37 tag = version;
38 # Upstream uses versioneer, which relies on git attributes substitution.
39 # This leads to non-reproducible archives on github. Remove the substituted
40 # file here, and recreate it later based on our version info.
41 postFetch = ''
42 rm "$out/limits/_version.py"
43 '';
44 hash = "sha256-JXXjRVn3RQMqNYRYXF4LuV2DHzVF8PTeGepFkt4jDFM=";
45 };
46
47 patches = [
48 ./only-test-in-memory.patch
49 ];
50
51 postPatch = ''
52 substituteInPlace pytest.ini \
53 --replace-fail "-K" ""
54
55 substituteInPlace setup.py \
56 --replace-fail "versioneer.get_version()" "'${version}'"
57
58 # Recreate _version.py, deleted at fetch time due to non-reproducibility.
59 echo 'def get_versions(): return {"version": "${version}"}' > limits/_version.py
60 '';
61
62 build-system = [ setuptools ];
63
64 dependencies = [
65 deprecated
66 importlib-resources
67 packaging
68 typing-extensions
69 ];
70
71 optional-dependencies = {
72 redis = [ redis ];
73 rediscluster = [ redis ];
74 memcached = [ pymemcache ];
75 mongodb = [ pymongo ];
76 etcd = [ etcd3 ];
77 async-redis = [ coredis ];
78 # async-memcached = [
79 # emcache # Missing module
80 # ];
81 async-mongodb = [ motor ];
82 async-etcd = [ aetcd ];
83 };
84
85 env = {
86 # make protobuf compatible with old versions
87 # https://developers.google.com/protocol-buffers/docs/news/2022-05-06#python-updates
88 PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION = "python";
89 };
90
91 nativeCheckInputs = [
92 flaky
93 hiro
94 pytest-asyncio
95 pytest-benchmark
96 pytest-cov-stub
97 pytest-lazy-fixtures
98 pytestCheckHook
99 ] ++ lib.flatten (lib.attrValues optional-dependencies);
100
101 disabledTests = [ "test_moving_window_memcached" ];
102
103 pythonImportsCheck = [ "limits" ];
104
105 meta = with lib; {
106 description = "Rate limiting using various strategies and storage backends such as redis & memcached";
107 homepage = "https://github.com/alisaifee/limits";
108 changelog = "https://github.com/alisaifee/limits/releases/tag/${src.tag}";
109 license = licenses.mit;
110 maintainers = [ ];
111 };
112}