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