1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 fetchFromGitHub,
6 fetchpatch,
7 pythonOlder,
8 isPyPy,
9
10 # build-system
11 poetry-core,
12 rustPlatform,
13
14 # native dependencies
15 iconv,
16
17 # dependencies
18 importlib-resources,
19 python-dateutil,
20 time-machine,
21 tzdata,
22
23 # tests
24 pytestCheckHook,
25 pytz,
26}:
27
28buildPythonPackage rec {
29 pname = "pendulum";
30 version = "3.0.0";
31 pyproject = true;
32
33 src = fetchFromGitHub {
34 owner = "sdispater";
35 repo = "pendulum";
36 tag = version;
37 hash = "sha256-v0kp8dklvDeC7zdTDOpIbpuj13aGub+oCaYz2ytkEpI=";
38 };
39
40 postPatch = ''
41 substituteInPlace rust/Cargo.lock \
42 --replace "3.0.0-beta-1" "3.0.0"
43 '';
44
45 cargoRoot = "rust";
46 cargoDeps = rustPlatform.fetchCargoVendor {
47 inherit src;
48 sourceRoot = "${src.name}/rust";
49 name = "${pname}-${version}";
50 hash = "sha256-6WgGIfz9I+xRJqXWhjfGDZM1umYwVlUEpLAiecZNZmI=";
51 postPatch = ''
52 substituteInPlace Cargo.lock \
53 --replace "3.0.0-beta-1" "3.0.0"
54 '';
55 };
56
57 patches = [
58 # fix build on 32bit
59 # https://github.com/sdispater/pendulum/pull/842
60 (fetchpatch {
61 url = "https://github.com/sdispater/pendulum/commit/6f2fcb8b025146ae768a5889be4a437fbd3156d6.patch";
62 hash = "sha256-47591JvpADxGQT2q7EYWHfStaiWyP7dt8DPTq0tiRvk=";
63 })
64 ];
65
66 nativeBuildInputs = [
67 poetry-core
68 rustPlatform.maturinBuildHook
69 rustPlatform.cargoSetupHook
70 ];
71
72 buildInputs = lib.optionals stdenv.hostPlatform.isDarwin [ iconv ];
73
74 propagatedBuildInputs =
75 [
76 python-dateutil
77 tzdata
78 ]
79 ++ lib.optional (!isPyPy) [ time-machine ]
80 ++ lib.optionals (pythonOlder "3.9") [
81 importlib-resources
82 ];
83
84 pythonImportsCheck = [ "pendulum" ];
85
86 nativeCheckInputs = [
87 pytestCheckHook
88 pytz
89 ];
90
91 disabledTestPaths =
92 [ "tests/benchmarks" ]
93 ++ lib.optionals stdenv.hostPlatform.isDarwin [
94 # PermissionError: [Errno 1] Operation not permitted: '/etc/localtime'
95 "tests/testing/test_time_travel.py"
96 ];
97
98 meta = with lib; {
99 description = "Python datetimes made easy";
100 homepage = "https://github.com/sdispater/pendulum";
101 changelog = "https://github.com/sdispater/pendulum/blob/${src.rev}/CHANGELOG.md";
102 license = licenses.mit;
103 maintainers = [ ];
104 };
105}