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.100.1";
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-3Mwa1nS6rvFBcU5QXLH4/wa38qCvDX9sRina1aJS1Rs=";
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 if (pythonOlder "3.10") then
77 [
78 # not sure why these tests fail with only 3.9
79 # FileNotFoundError: [Errno 2] No such file or directory: 'git'
80 "test_observability"
81 "test_assume_has_status_reason"
82 "test_observability_captures_stateful_reprs"
83 ]
84 else
85 null;
86
87 pythonImportsCheck = [ "hypothesis" ];
88
89 passthru = {
90 doc = stdenv.mkDerivation {
91 # Forge look and feel of multi-output derivation as best as we can.
92 #
93 # Using 'outputs = [ "doc" ];' breaks a lot of assumptions.
94 name = "${pname}-${version}-doc";
95 inherit src pname version;
96
97 postInstallSphinx = ''
98 mv $out/share/doc/* $out/share/doc/python$pythonVersion-$pname-$version
99 '';
100
101 nativeBuildInputs = [
102 sphinxHook
103 sphinx-rtd-theme
104 sphinx-hoverxref
105 sphinx-codeautolink
106 ];
107
108 inherit (python) pythonVersion;
109 inherit meta;
110 };
111 };
112
113 meta = with lib; {
114 description = "Library for property based testing";
115 mainProgram = "hypothesis";
116 homepage = "https://github.com/HypothesisWorks/hypothesis";
117 changelog = "https://hypothesis.readthedocs.io/en/latest/changes.html#v${
118 lib.replaceStrings [ "." ] [ "-" ] version
119 }";
120 license = licenses.mpl20;
121 maintainers = with maintainers; [ ];
122 };
123}