1{ lib
2, buildPythonPackage
3, isPyPy
4, fetchFromGitHub
5, attrs
6, exceptiongroup
7, pexpect
8, doCheck ? true
9, pytestCheckHook
10, pytest-xdist
11, python
12, sortedcontainers
13, stdenv
14, pythonOlder
15, sphinxHook
16, sphinx-rtd-theme
17, sphinx-hoverxref
18, sphinx-codeautolink
19, tzdata
20}:
21
22buildPythonPackage rec {
23 pname = "hypothesis";
24 version = "6.84.3";
25 outputs = [ "out" ];
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-wymZ/tJBGcP57B3BuDlBT7kbUxNwW4/SSmvwLSa5PvM=";
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 propagatedBuildInputs = [
53 attrs
54 sortedcontainers
55 ] ++ lib.optionals (pythonOlder "3.11") [
56 exceptiongroup
57 ];
58
59 nativeCheckInputs = [
60 pexpect
61 pytest-xdist
62 pytestCheckHook
63 ] ++ lib.optionals isPyPy [
64 tzdata
65 ];
66
67 inherit doCheck;
68
69 # This file changes how pytest runs and breaks it
70 preCheck = ''
71 rm tox.ini
72 '';
73
74 pytestFlagsArray = [
75 "tests/cover"
76 ];
77
78 pythonImportsCheck = [
79 "hypothesis"
80 ];
81
82 passthru = {
83 doc = stdenv.mkDerivation {
84 # Forge look and feel of multi-output derivation as best as we can.
85 #
86 # Using 'outputs = [ "doc" ];' breaks a lot of assumptions.
87 name = "${pname}-${version}-doc";
88 inherit src pname version;
89
90 postInstallSphinx = ''
91 mv $out/share/doc/* $out/share/doc/python$pythonVersion-$pname-$version
92 '';
93
94 nativeBuildInputs = [
95 sphinxHook
96 sphinx-rtd-theme
97 sphinx-hoverxref
98 sphinx-codeautolink
99 ];
100
101 inherit (python) pythonVersion;
102 inherit meta;
103 };
104 };
105
106 meta = with lib; {
107 description = "Library for property based testing";
108 homepage = "https://github.com/HypothesisWorks/hypothesis";
109 changelog = "https://hypothesis.readthedocs.io/en/latest/changes.html#v${lib.replaceStrings [ "." ] [ "-" ] version}";
110 license = licenses.mpl20;
111 maintainers = with maintainers; [ ];
112 };
113}