1{
2 lib,
3 attrs,
4 buildPythonPackage,
5 cbor2,
6 fetchFromGitHub,
7 fetchpatch2,
8 exceptiongroup,
9 hatchling,
10 hatch-vcs,
11 hypothesis,
12 immutables,
13 motor,
14 msgpack,
15 msgspec,
16 orjson,
17 pytest-xdist,
18 pytestCheckHook,
19 pythonOlder,
20 pyyaml,
21 tomlkit,
22 typing-extensions,
23 ujson,
24}:
25
26buildPythonPackage rec {
27 pname = "cattrs";
28 version = "24.1.2";
29 format = "pyproject";
30
31 disabled = pythonOlder "3.7";
32
33 src = fetchFromGitHub {
34 owner = "python-attrs";
35 repo = pname;
36 rev = "refs/tags/v${version}";
37 hash = "sha256-LSP8a/JduK0h9GytfbN7/CjFlnGGChaa3VbbCHQ3AFE=";
38 };
39
40 patches = [
41 # https://github.com/python-attrs/cattrs/pull/576
42 (fetchpatch2 {
43 name = "attrs-24_2-compatibility1.patch";
44 url = "https://github.com/python-attrs/cattrs/commit/2d37226ff19506e23bbc291125a29ce514575819.patch";
45 excludes = [
46 "pyproject.toml"
47 "pdm.lock"
48 ];
49 hash = "sha256-nbk7rmOFk42DXYdOgw4Oe3gl3HbxNEtaJ7ZiVSBb3YA=";
50 })
51 (fetchpatch2 {
52 name = "attrs-24_2-compatibility2.patch";
53 url = "https://github.com/python-attrs/cattrs/commit/4bd6dde556042241c6381e1993cedd6514921f58.patch";
54 hash = "sha256-H1xSAYjvVUI8/jON3LWg2F2TlSxejf6TU1jpCeqly6I=";
55 })
56 ];
57
58 nativeBuildInputs = [
59 hatchling
60 hatch-vcs
61 ];
62
63 propagatedBuildInputs =
64 [ attrs ]
65 ++ lib.optionals (pythonOlder "3.11") [
66 exceptiongroup
67 typing-extensions
68 ];
69
70 nativeCheckInputs = [
71 cbor2
72 hypothesis
73 immutables
74 motor
75 msgpack
76 msgspec
77 orjson
78 pytest-xdist
79 pytestCheckHook
80 pyyaml
81 tomlkit
82 typing-extensions
83 ujson
84 ];
85
86 postPatch = ''
87 substituteInPlace pyproject.toml \
88 --replace "-l --benchmark-sort=fullname --benchmark-warmup=true --benchmark-warmup-iterations=5 --benchmark-group-by=fullname" ""
89 substituteInPlace tests/test_preconf.py \
90 --replace "from orjson import dumps as orjson_dumps" "" \
91 --replace "from orjson import loads as orjson_loads" ""
92 '';
93
94 preCheck = ''
95 export HOME=$(mktemp -d);
96 '';
97
98 disabledTestPaths = [
99 # Don't run benchmarking tests
100 "bench/test_attrs_collections.py"
101 "bench/test_attrs_nested.py"
102 "bench/test_attrs_primitives.py"
103 "bench/test_primitives.py"
104 ];
105
106 disabledTests = [
107 # orjson is not available as it requires Rust nightly features to compile its requirements
108 "test_orjson"
109 # tomlkit is pinned to an older version and newer versions raise InvalidControlChar exception
110 "test_tomlkit"
111 # msgspec causes a segmentation fault for some reason
112 "test_simple_classes"
113 "test_msgspec_json_converter"
114 ];
115
116 pythonImportsCheck = [ "cattr" ];
117
118 meta = with lib; {
119 description = "Python custom class converters for attrs";
120 homepage = "https://github.com/python-attrs/cattrs";
121 changelog = "https://github.com/python-attrs/cattrs/blob/${src.rev}/HISTORY.md";
122 license = with licenses; [ mit ];
123 maintainers = with maintainers; [ fab ];
124 };
125}