1{ lib
2, attrs
3, buildPythonPackage
4, cbor2
5, fetchFromGitHub
6, exceptiongroup
7, hypothesis
8, immutables
9, motor
10, msgpack
11, orjson
12, poetry-core
13, pytest-xdist
14, pytestCheckHook
15, pythonOlder
16, pyyaml
17, tomlkit
18, typing-extensions
19, ujson
20}:
21
22buildPythonPackage rec {
23 pname = "cattrs";
24 version = "23.1.2";
25 format = "pyproject";
26
27 disabled = pythonOlder "3.7";
28
29 src = fetchFromGitHub {
30 owner = "python-attrs";
31 repo = pname;
32 rev = "v${version}";
33 hash = "sha256-YO4Clbo5fmXbysxwwM2qCHJwO5KwDC05VctRVFruJcw=";
34 };
35
36 nativeBuildInputs = [
37 poetry-core
38 ];
39
40 propagatedBuildInputs = [
41 attrs
42 ] ++ lib.optionals (pythonOlder "3.11") [
43 exceptiongroup
44 typing-extensions
45 ];
46
47 nativeCheckInputs = [
48 cbor2
49 hypothesis
50 immutables
51 motor
52 msgpack
53 orjson
54 pytest-xdist
55 pytestCheckHook
56 pyyaml
57 tomlkit
58 typing-extensions
59 ujson
60 ];
61
62
63 postPatch = ''
64 substituteInPlace pyproject.toml \
65 --replace "-l --benchmark-sort=fullname --benchmark-warmup=true --benchmark-warmup-iterations=5 --benchmark-group-by=fullname" "" \
66 --replace 'orjson = "^3.5.2"' "" \
67 --replace "[tool.poetry.group.dev.dependencies]" "[tool.poetry.dev-dependencies]"
68 substituteInPlace tests/test_preconf.py \
69 --replace "from orjson import dumps as orjson_dumps" "" \
70 --replace "from orjson import loads as orjson_loads" ""
71 '';
72
73 preCheck = ''
74 export HOME=$(mktemp -d);
75 '';
76
77 disabledTestPaths = [
78 # Don't run benchmarking tests
79 "bench/test_attrs_collections.py"
80 "bench/test_attrs_nested.py"
81 "bench/test_attrs_primitives.py"
82 "bench/test_primitives.py"
83 ];
84
85 disabledTests = [
86 # orjson is not available as it requires Rust nightly features to compile its requirements
87 "test_orjson"
88 # tomlkit is pinned to an older version and newer versions raise InvalidControlChar exception
89 "test_tomlkit"
90 ];
91
92 pythonImportsCheck = [
93 "cattr"
94 ];
95
96 meta = with lib; {
97 description = "Python custom class converters for attrs";
98 homepage = "https://github.com/python-attrs/cattrs";
99 changelog = "https://github.com/python-attrs/cattrs/blob/${src.rev}/HISTORY.md";
100 license = with licenses; [ mit ];
101 maintainers = with maintainers; [ fab ];
102 };
103}