1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 pythonOlder,
6 fetchFromGitHub,
7 substituteAll,
8 alsa-utils,
9 libnotify,
10 which,
11 poetry-core,
12 pythonRelaxDepsHook,
13 jeepney,
14 loguru,
15 pytest,
16 dbus,
17 coreutils,
18}:
19
20buildPythonPackage rec {
21 pname = "notify-py";
22 version = "0.3.42";
23 format = "pyproject";
24
25 disabled = pythonOlder "3.6";
26
27 src = fetchFromGitHub {
28 owner = "ms7m";
29 repo = pname;
30 rev = "refs/tags/v${version}";
31 hash = "sha256-XtjJImH9UwPPZS/Yqs8S5xGXOLBRmJRawzxWXoPWvrM=";
32 };
33
34 patches =
35 lib.optionals stdenv.isLinux [
36 # hardcode paths to aplay and notify-send
37 (substituteAll {
38 src = ./linux-paths.patch;
39 aplay = "${alsa-utils}/bin/aplay";
40 notifysend = "${libnotify}/bin/notify-send";
41 })
42 ]
43 ++ lib.optionals stdenv.isDarwin [
44 # hardcode path to which
45 (substituteAll {
46 src = ./darwin-paths.patch;
47 which = "${which}/bin/which";
48 })
49 ];
50
51 nativeBuildInputs = [
52 poetry-core
53 pythonRelaxDepsHook
54 ];
55
56 pythonRelaxDeps = [ "loguru" ];
57
58 propagatedBuildInputs = [ loguru ] ++ lib.optionals stdenv.isLinux [ jeepney ];
59
60 nativeCheckInputs = [ pytest ] ++ lib.optionals stdenv.isLinux [ dbus ];
61
62 checkPhase =
63 if stdenv.isDarwin then
64 ''
65 # Tests search for "afplay" binary which is built in to macOS and not available in nixpkgs
66 mkdir $TMP/bin
67 ln -s ${coreutils}/bin/true $TMP/bin/afplay
68 PATH="$TMP/bin:$PATH" pytest
69 ''
70 else if stdenv.isLinux then
71 ''
72 dbus-run-session \
73 --config-file=${dbus}/share/dbus-1/session.conf \
74 pytest
75 ''
76 else
77 ''
78 pytest
79 '';
80
81 # GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name
82 # org.freedesktop.Notifications was not provided by any .service files
83 doCheck = false;
84
85 pythonImportsCheck = [ "notifypy" ];
86
87 meta = with lib; {
88 description = "Cross-platform desktop notification library for Python";
89 mainProgram = "notifypy";
90 homepage = "https://github.com/ms7m/notify-py";
91 changelog = "https://github.com/ms7m/notify-py/releases/tag/v${version}";
92 license = licenses.mit;
93 maintainers = with maintainers; [
94 austinbutler
95 dotlambda
96 ];
97 };
98}