1{
2 lib,
3 buildPythonPackage,
4 isPyPy,
5 fetchFromGitHub,
6 setuptools,
7 attrs,
8 exceptiongroup,
9 pexpect,
10 doCheck ? true,
11 pytestCheckHook,
12 pytest-xdist,
13 python,
14 sortedcontainers,
15 stdenv,
16 pythonOlder,
17 sphinxHook,
18 sphinx-rtd-theme,
19 sphinx-hoverxref,
20 sphinx-codeautolink,
21 tzdata,
22}:
23
24buildPythonPackage rec {
25 pname = "hypothesis";
26 version = "6.103.0";
27 pyproject = true;
28
29 disabled = pythonOlder "3.7";
30
31 src = fetchFromGitHub {
32 owner = "HypothesisWorks";
33 repo = "hypothesis";
34 rev = "hypothesis-python-${version}";
35 hash = "sha256-sll0GAI1nvBQvRqgpTkLpj7GQI988AftDQHV1zh2t1w=";
36 };
37
38 # I tried to package sphinx-selective-exclude, but it throws
39 # error about "module 'sphinx' has no attribute 'directives'".
40 #
41 # It probably has to do with monkey-patching internals of Sphinx.
42 # On bright side, this extension does not introduces new commands,
43 # only changes "::only" command, so we probably okay with stock
44 # implementation.
45 #
46 # I wonder how upstream of "hypothesis" builds documentation.
47 postPatch = ''
48 sed -i -e '/sphinx_selective_exclude.eager_only/ d' docs/conf.py
49 '';
50
51 postUnpack = "sourceRoot=$sourceRoot/hypothesis-python";
52
53 nativeBuildInputs = [ setuptools ];
54
55 propagatedBuildInputs = [
56 attrs
57 sortedcontainers
58 ] ++ lib.optionals (pythonOlder "3.11") [ exceptiongroup ];
59
60 nativeCheckInputs = [
61 pexpect
62 pytest-xdist
63 pytestCheckHook
64 ] ++ lib.optionals isPyPy [ tzdata ];
65
66 inherit doCheck;
67
68 # This file changes how pytest runs and breaks it
69 preCheck = ''
70 rm tox.ini
71 '';
72
73 pytestFlagsArray = [ "tests/cover" ];
74
75 disabledTests =
76 [
77 # racy, fails to find a file sometimes
78 "test_recreate_charmap"
79 "test_uses_cached_charmap"
80 ]
81 ++ lib.optionals (pythonOlder "3.10") [
82 # not sure why these tests fail with only 3.9
83 # FileNotFoundError: [Errno 2] No such file or directory: 'git'
84 "test_observability"
85 "test_assume_has_status_reason"
86 "test_observability_captures_stateful_reprs"
87 ];
88
89 pythonImportsCheck = [ "hypothesis" ];
90
91 passthru = {
92 doc = stdenv.mkDerivation {
93 # Forge look and feel of multi-output derivation as best as we can.
94 #
95 # Using 'outputs = [ "doc" ];' breaks a lot of assumptions.
96 name = "${pname}-${version}-doc";
97 inherit src pname version;
98
99 postInstallSphinx = ''
100 mv $out/share/doc/* $out/share/doc/python$pythonVersion-$pname-$version
101 '';
102
103 nativeBuildInputs = [
104 sphinxHook
105 sphinx-rtd-theme
106 sphinx-hoverxref
107 sphinx-codeautolink
108 ];
109
110 inherit (python) pythonVersion;
111 inherit meta;
112 };
113 };
114
115 meta = with lib; {
116 description = "Library for property based testing";
117 mainProgram = "hypothesis";
118 homepage = "https://github.com/HypothesisWorks/hypothesis";
119 changelog = "https://hypothesis.readthedocs.io/en/latest/changes.html#v${
120 lib.replaceStrings [ "." ] [ "-" ] version
121 }";
122 license = licenses.mpl20;
123 maintainers = [ ];
124 };
125}