1{ lib
2, buildPythonPackage
3, isPyPy
4, fetchFromGitHub
5, attrs
6, exceptiongroup
7, pexpect
8, doCheck ? true
9, pytestCheckHook
10, pytest-xdist
11, sortedcontainers
12, pythonOlder
13, sphinxHook
14, sphinx-rtd-theme
15, sphinx-hoverxref
16, sphinx-codeautolink
17, tzdata
18# Used to break internal dependency loop.
19, enableDocumentation ? true
20}:
21
22buildPythonPackage rec {
23 pname = "hypothesis";
24 version = "6.68.2";
25 outputs = [ "out" ] ++ lib.optional enableDocumentation "doc";
26 format = "setuptools";
27
28 disabled = pythonOlder "3.7";
29
30 src = fetchFromGitHub {
31 owner = "HypothesisWorks";
32 repo = "hypothesis";
33 rev = "hypothesis-python-${version}";
34 hash = "sha256-SgX8esTyC3ulFIv9mZJUoBA5hiv7Izr2hyD+NOudkpE=";
35 };
36
37 # I tried to package sphinx-selective-exclude, but it throws
38 # error about "module 'sphinx' has no attribute 'directives'".
39 #
40 # It probably has to do with monkey-patching internals of Sphinx.
41 # On bright side, this extension does not introduces new commands,
42 # only changes "::only" command, so we probably okay with stock
43 # implementation.
44 #
45 # I wonder how upstream of "hypothesis" builds documentation.
46 postPatch = ''
47 sed -i -e '/sphinx_selective_exclude.eager_only/ d' docs/conf.py
48 '';
49
50 postUnpack = "sourceRoot=$sourceRoot/hypothesis-python";
51
52 nativeBuildInputs = lib.optionals enableDocumentation [
53 sphinxHook
54 sphinx-rtd-theme
55 sphinx-hoverxref
56 sphinx-codeautolink
57 ];
58
59 propagatedBuildInputs = [
60 attrs
61 sortedcontainers
62 ] ++ lib.optionals (pythonOlder "3.11") [
63 exceptiongroup
64 ];
65
66 nativeCheckInputs = [
67 pexpect
68 pytest-xdist
69 pytestCheckHook
70 ] ++ lib.optionals (isPyPy) [
71 tzdata
72 ];
73
74 inherit doCheck;
75
76 # This file changes how pytest runs and breaks it
77 preCheck = ''
78 rm tox.ini
79 '';
80
81 pytestFlagsArray = [
82 "tests/cover"
83 ];
84
85 pythonImportsCheck = [
86 "hypothesis"
87 ];
88
89 meta = with lib; {
90 description = "Library for property based testing";
91 homepage = "https://github.com/HypothesisWorks/hypothesis";
92 changelog = "https://hypothesis.readthedocs.io/en/latest/changes.html#v${lib.replaceStrings [ "." ] [ "-" ] version}";
93 license = licenses.mpl20;
94 maintainers = with maintainers; [ SuperSandro2000 ];
95 };
96}