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