1{ lib
2, stdenv
3, buildPythonPackage
4, autoflake
5, cython
6, devtools
7, email-validator
8, fetchFromGitHub
9, fetchpatch
10, pytest-mock
11, pytestCheckHook
12, python-dotenv
13, pythonAtLeast
14, pythonOlder
15, pyupgrade
16, typing-extensions
17# dependencies for building documentation.
18# docs fail to build in Darwin sandbox: https://github.com/samuelcolvin/pydantic/issues/4245
19, withDocs ? (stdenv.hostPlatform == stdenv.buildPlatform && !stdenv.isDarwin && pythonAtLeast "3.10")
20, ansi2html
21, markdown-include
22, mike
23, mkdocs
24, mkdocs-exclude
25, mkdocs-material
26, mdx-truly-sane-lists
27, sqlalchemy
28, ujson
29, orjson
30, hypothesis
31, libxcrypt
32}:
33
34buildPythonPackage rec {
35 pname = "pydantic";
36 version = "1.10.12";
37 format = "setuptools";
38
39 outputs = [
40 "out"
41 ] ++ lib.optionals withDocs [
42 "doc"
43 ];
44
45 disabled = pythonOlder "3.7";
46
47 src = fetchFromGitHub {
48 owner = "pydantic";
49 repo = pname;
50 rev = "refs/tags/v${version}";
51 hash = "sha256-3XnbPGU90wLCPEryFAOky6Iy73Dvgzzh+GbOKW8hZ4U=";
52 };
53
54 postPatch = ''
55 sed -i '/flake8/ d' Makefile
56 '';
57
58 buildInputs = lib.optionals (pythonOlder "3.9") [
59 libxcrypt
60 ];
61
62 nativeBuildInputs = [
63 cython
64 ] ++ lib.optionals withDocs [
65 # dependencies for building documentation
66 autoflake
67 ansi2html
68 markdown-include
69 mdx-truly-sane-lists
70 mike
71 mkdocs
72 mkdocs-exclude
73 mkdocs-material
74 sqlalchemy
75 ujson
76 orjson
77 hypothesis
78 ];
79
80 propagatedBuildInputs = [
81 devtools
82 pyupgrade
83 typing-extensions
84 ];
85
86 passthru.optional-dependencies = {
87 dotenv = [
88 python-dotenv
89 ];
90 email = [
91 email-validator
92 ];
93 };
94
95 nativeCheckInputs = [
96 pytest-mock
97 pytestCheckHook
98 ] ++ lib.flatten (lib.attrValues passthru.optional-dependencies);
99
100 pytestFlagsArray = [
101 # https://github.com/pydantic/pydantic/issues/4817
102 "-W" "ignore::pytest.PytestReturnNotNoneWarning"
103 ];
104
105 preCheck = ''
106 export HOME=$(mktemp -d)
107 '';
108
109 # Must include current directory into PYTHONPATH, since documentation
110 # building process expects "import pydantic" to work.
111 preBuild = lib.optionalString withDocs ''
112 PYTHONPATH=$PWD:$PYTHONPATH make docs
113 '';
114
115 # Layout documentation in same way as "sphinxHook" does.
116 postInstall = lib.optionalString withDocs ''
117 mkdir -p $out/share/doc/$name
118 mv ./site $out/share/doc/$name/html
119 '';
120
121 enableParallelBuilding = true;
122
123 pythonImportsCheck = [ "pydantic" ];
124
125 meta = with lib; {
126 description = "Data validation and settings management using Python type hinting";
127 homepage = "https://github.com/pydantic/pydantic";
128 changelog = "https://github.com/pydantic/pydantic/blob/v${version}/HISTORY.md";
129 license = licenses.mit;
130 maintainers = with maintainers; [ wd15 ];
131 };
132}