1{
2 stdenv,
3 lib,
4 buildPythonPackage,
5 fetchFromGitHub,
6 cargo,
7 rustPlatform,
8 rustc,
9 libiconv,
10 typing-extensions,
11 pytestCheckHook,
12 hypothesis,
13 pytest-timeout,
14 pytest-mock,
15 dirty-equals,
16}:
17
18let
19 pydantic-core = buildPythonPackage rec {
20 pname = "pydantic-core";
21 version = "2.16.3";
22 pyproject = true;
23
24 src = fetchFromGitHub {
25 owner = "pydantic";
26 repo = "pydantic-core";
27 rev = "refs/tags/v${version}";
28 hash = "sha256-RXytujvx/23Z24TWpvnHdjJ4/dXqjs5uiavUmukaD9A=";
29 };
30
31 patches = [ ./01-remove-benchmark-flags.patch ];
32
33 cargoDeps = rustPlatform.fetchCargoTarball {
34 inherit src;
35 name = "${pname}-${version}";
36 hash = "sha256-wj9u6s/3E3EWfQydkLrwHbJBvm8DwcGCoQQpSw1+q7U=";
37 };
38
39 nativeBuildInputs = [
40 cargo
41 rustPlatform.cargoSetupHook
42 rustc
43 ];
44
45 build-system = [
46 rustPlatform.maturinBuildHook
47 typing-extensions
48 ];
49
50 buildInputs = lib.optionals stdenv.isDarwin [ libiconv ];
51
52 dependencies = [ typing-extensions ];
53
54 pythonImportsCheck = [ "pydantic_core" ];
55
56 # escape infinite recursion with pydantic via dirty-equals
57 doCheck = false;
58 passthru.tests.pytest = pydantic-core.overrideAttrs { doCheck = true; };
59
60 nativeCheckInputs = [
61 pytestCheckHook
62 hypothesis
63 pytest-timeout
64 dirty-equals
65 pytest-mock
66 ];
67
68 disabledTests = [
69 # RecursionError: maximum recursion depth exceeded while calling a Python object
70 "test_recursive"
71 ];
72
73 disabledTestPaths = [
74 # no point in benchmarking in nixpkgs build farm
75 "tests/benchmarks"
76 ];
77
78 meta = with lib; {
79 changelog = "https://github.com/pydantic/pydantic-core/releases/tag/v${version}";
80 description = "Core validation logic for pydantic written in rust";
81 homepage = "https://github.com/pydantic/pydantic-core";
82 license = licenses.mit;
83 maintainers = with maintainers; [ blaggacao ];
84 };
85 };
86in
87pydantic-core