1{ lib
2, stdenv
3, anyio
4, buildPythonPackage
5, cargo
6, fetchFromGitHub
7, rustPlatform
8, rustc
9, pythonOlder
10, dirty-equals
11, pytest-mock
12, pytest-timeout
13, pytestCheckHook
14, CoreServices
15, libiconv
16}:
17
18buildPythonPackage rec {
19 pname = "watchfiles";
20 version = "0.21.0";
21 format = "pyproject";
22
23 disabled = pythonOlder "3.7";
24
25 src = fetchFromGitHub {
26 owner = "samuelcolvin";
27 repo = pname;
28 rev = "refs/tags/v${version}";
29 hash = "sha256-/qNgkPF5N8jzSV3M0YFWvQngZ4Hf4WM/GBS1LtgFbWM=";
30 };
31
32 cargoDeps = rustPlatform.fetchCargoTarball {
33 inherit src;
34 name = "${pname}-${version}";
35 hash = "sha256-sqHTW1+E7Fp33KW6IYlNa77AYc2iCfaSoBRXzrhEKr8=";
36 };
37
38 buildInputs = lib.optionals stdenv.isDarwin [
39 CoreServices
40 libiconv
41 ];
42
43 nativeBuildInputs = [
44 rustPlatform.cargoSetupHook
45 rustPlatform.maturinBuildHook
46 cargo
47 rustc
48 ];
49
50 propagatedBuildInputs = [
51 anyio
52 ];
53
54 # Tests need these permissions in order to use the FSEvents API on macOS.
55 sandboxProfile = ''
56 (allow mach-lookup (global-name "com.apple.FSEvents"))
57 '';
58
59 nativeCheckInputs = [
60 dirty-equals
61 pytest-mock
62 pytest-timeout
63 pytestCheckHook
64 ];
65
66 postPatch = ''
67 sed -i "/^requires-python =.*/a version = '${version}'" pyproject.toml
68 '';
69
70 preCheck = ''
71 rm -rf watchfiles
72 '';
73
74 disabledTests = [
75 # BaseExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception)
76 "test_awatch_interrupt_raise"
77 ];
78
79 pythonImportsCheck = [
80 "watchfiles"
81 ];
82
83 meta = with lib; {
84 description = "File watching and code reload";
85 homepage = "https://watchfiles.helpmanual.io/";
86 license = licenses.mit;
87 maintainers = with maintainers; [ fab ];
88 };
89}