1{ lib
2, stdenv
3, buildPythonPackage
4, fetchFromGitHub
5, fetchpatch
6, pyparsing
7, numpy
8, cython
9, astropy
10, astropy-helpers
11, pytestCheckHook
12, pytest-astropy
13}:
14
15buildPythonPackage rec {
16 pname = "pyregion";
17 version = "2.1.1";
18
19 # pypi src contains cython-produced .c files which don't compile
20 # with python3.9
21 src = fetchFromGitHub {
22 owner = "astropy";
23 repo = pname;
24 rev = "v${version}";
25 hash = "sha256-xo+XbBJ2HKql9rd7Ma84JofRg8M4u6vmz44Qo8JhEBc=";
26 };
27
28 propagatedBuildInputs = [
29 pyparsing
30 numpy
31 astropy
32 ];
33
34 # Upstream patches needed for the tests to pass
35 # See https://github.com/astropy/pyregion/pull/157/
36 patches = [
37 (fetchpatch {
38 url = "https://github.com/astropy/pyregion/pull/157/commits/082649730d353a0d0c0ee9619be1aa501aabba62.patch";
39 hash = "sha256-4mHZt3S29ZfK+QKavm6DLBwVxGl/ga7W7GEcQ5ewxuo=";
40 })
41 (fetchpatch {
42 url = "https://github.com/astropy/pyregion/pull/157/commits/c448a465dd56887979da62aec6138fc89bb37b19.patch";
43 hash = "sha256-GEtvScmVbAdE4E5Xx0hNOPommvzcnJ3jNZpBmY3PbyE=";
44 })
45 ];
46
47 nativeBuildInputs = [ astropy-helpers cython ];
48
49 nativeCheckInputs = [ pytestCheckHook pytest-astropy ];
50
51 disabledTests = lib.optionals (!stdenv.hostPlatform.isDarwin) [
52 # Skipping 2 tests because it's failing. Domain knowledge was unavailable on decision.
53 # Error logs: https://gist.github.com/superherointj/3f616f784014eeb2e3039b0f4037e4e9
54 "test_calculate_rotation_angle"
55 "test_region"
56 ];
57
58 # Disable automatic update of the astropy-helper module
59 postPatch = ''
60 substituteInPlace setup.cfg --replace "auto_use = True" "auto_use = False"
61 '';
62
63 # Tests must be run in the build directory
64 preCheck = ''
65 pushd build/lib.*
66 '';
67 postCheck = ''
68 popd
69 '';
70
71 meta = with lib; {
72 description = "Python parser for ds9 region files";
73 homepage = "https://github.com/astropy/pyregion";
74 license = licenses.mit;
75 maintainers = [ maintainers.smaret ];
76 };
77}