1{
2 lib,
3 fetchFromGitHub,
4 buildPythonPackage,
5
6 # build-system
7 cython,
8 git,
9 pkgconfig,
10 setuptools,
11 setuptools-scm,
12 udevCheckHook,
13
14 # dependneices
15 numpy,
16 libusb-compat-0_1,
17
18 # optional-dependencies
19 pyusb,
20
21 # tests
22 mock,
23 pytestCheckHook,
24 zipp,
25}:
26
27## Usage
28# In NixOS, add the package to services.udev.packages for non-root plugdev
29# users to get device access permission:
30# services.udev.packages = [ pkgs.python3Packages.seabreeze ];
31
32buildPythonPackage rec {
33 pname = "seabreeze";
34 version = "2.10.1";
35 pyproject = true;
36
37 src = fetchFromGitHub {
38 owner = "ap--";
39 repo = "python-seabreeze";
40 tag = "v${version}";
41 hash = "sha256-q4qBblebCb5z67KgWBIzsvCWNZf146I7LHPCyAabDUM=";
42 leaveDotGit = true;
43 };
44
45 enableParallelBuilding = true;
46
47 postPatch = ''
48 # pkgconfig cant find libusb, doing it manually
49 substituteInPlace setup.py \
50 --replace-fail 'pkgconfig.parse("libusb")' \
51 "{'include_dirs': ['${libusb-compat-0_1}/include'], 'library_dirs': ['${libusb-compat-0_1}/lib'], 'libraries': ['usb']}"
52 '';
53
54 nativeBuildInputs = [
55 cython
56 git
57 pkgconfig
58 setuptools
59 setuptools-scm
60 udevCheckHook
61 ];
62
63 propagatedBuildInputs = [
64 numpy
65 libusb-compat-0_1
66 ];
67
68 optional-dependencies = {
69 pyseabreeze = [ pyusb ];
70 };
71
72 postInstall = ''
73 mkdir -p $out/etc/udev/rules.d
74 cp os_support/10-oceanoptics.rules $out/etc/udev/rules.d/10-oceanoptics.rules
75 '';
76
77 # few backends enabled, but still some tests
78 nativeCheckInputs = [
79 pytestCheckHook
80 mock
81 zipp
82 ]
83 ++ lib.flatten (lib.attrValues optional-dependencies);
84
85 disabledTests = [ "TestHardware" ];
86
87 setupPyBuildFlags = [ "--without-cseabreeze" ];
88
89 meta = with lib; {
90 homepage = "https://github.com/ap--/python-seabreeze";
91 description = "Python library to access Ocean Optics spectrometers";
92 maintainers = [ ];
93 license = licenses.mit;
94 };
95}