Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{ lib
2, stdenv
3, buildPythonPackage
4, cython
5, devtools
6, email-validator
7, fetchFromGitHub
8, pytest-mock
9, pytestCheckHook
10, python-dotenv
11, pythonOlder
12, typing-extensions
13# dependencies for building documentation.
14# docs fail to build in Darwin sandbox: https://github.com/samuelcolvin/pydantic/issues/4245
15, withDocs ? (stdenv.hostPlatform == stdenv.buildPlatform && !stdenv.isDarwin)
16, ansi2html
17, markdown-include
18, mkdocs
19, mkdocs-exclude
20, mkdocs-material
21, mdx-truly-sane-lists
22, sqlalchemy
23, ujson
24, orjson
25, hypothesis
26}:
27
28buildPythonPackage rec {
29 pname = "pydantic";
30 version = "1.9.2";
31
32 outputs = [
33 "out"
34 ] ++ lib.optionals withDocs [
35 "doc"
36 ];
37
38 disabled = pythonOlder "3.7";
39
40 src = fetchFromGitHub {
41 owner = "samuelcolvin";
42 repo = pname;
43 rev = "refs/tags/v${version}";
44 sha256 = "sha256-ZGFxyQ1qD3zZWTdfTeoGj3UcUwAzO8K0DySdVAsMHyI=";
45 };
46
47 postPatch = ''
48 sed -i '/flake8/ d' Makefile
49 '';
50
51 nativeBuildInputs = [
52 cython
53 ] ++ lib.optionals withDocs [
54 # dependencies for building documentation
55 ansi2html
56 markdown-include
57 mdx-truly-sane-lists
58 mkdocs
59 mkdocs-exclude
60 mkdocs-material
61 sqlalchemy
62 ujson
63 orjson
64 hypothesis
65 ];
66
67 propagatedBuildInputs = [
68 devtools
69 email-validator
70 python-dotenv
71 typing-extensions
72 ];
73
74 checkInputs = [
75 pytest-mock
76 pytestCheckHook
77 ];
78
79 preCheck = ''
80 export HOME=$(mktemp -d)
81 '';
82
83 # Must include current directory into PYTHONPATH, since documentation
84 # building process expects "import pydantic" to work.
85 preBuild = lib.optionalString withDocs ''
86 PYTHONPATH=$PWD:$PYTHONPATH make docs
87 '';
88
89 # Layout documentation in same way as "sphinxHook" does.
90 postInstall = lib.optionalString withDocs ''
91 mkdir -p $out/share/doc/$name
92 mv ./site $out/share/doc/$name/html
93 '';
94
95 enableParallelBuilding = true;
96
97 pythonImportsCheck = [ "pydantic" ];
98
99 meta = with lib; {
100 homepage = "https://github.com/samuelcolvin/pydantic";
101 description = "Data validation and settings management using Python type hinting";
102 license = licenses.mit;
103 maintainers = with maintainers; [ wd15 ];
104 };
105}