1{
2 lib,
3 buildPythonPackage,
4 fetchFromGitHub,
5 pythonAtLeast,
6 pythonOlder,
7 python,
8 substituteAll,
9 importlib-resources,
10 tzdata,
11 hypothesis,
12 pytestCheckHook,
13 fetchpatch,
14}:
15
16buildPythonPackage rec {
17 pname = "backports-zoneinfo";
18 version = "0.2.1";
19 format = "setuptools";
20
21 disabled = pythonAtLeast "3.9";
22
23 src = fetchFromGitHub {
24 owner = "pganssle";
25 repo = "zoneinfo";
26 rev = version;
27 hash = "sha256-00xdDOVdDanfsjQTd3yjMN2RFGel4cWRrAA3CvSnl24=";
28 };
29
30 # Make sure test data update patch applies
31 prePatch = ''
32 substituteInPlace tests/data/zoneinfo_data.json --replace \"2020a\" \"2021a\"
33 '';
34
35 patches = [
36 # Update test suite's test data to zoneinfo 2022a
37 # https://github.com/pganssle/zoneinfo/pull/115
38 (fetchpatch {
39 name = "backports-zoneinfo-2022a-update-test-data1.patch";
40 url = "https://github.com/pganssle/zoneinfo/pull/115/commits/837e2a0f9f1a1332e4233f83e3648fa564a9ec9e.patch";
41 sha256 = "196knwa212mr0b7zsh8papzr3f5mii87gcjjjx1r9zzvmk3g3ri0";
42 })
43 (fetchpatch {
44 name = "backports-zoneinfo-2022a-update-test-data2.patch";
45 url = "https://github.com/pganssle/zoneinfo/pull/115/commits/9fd330265b177916d6182249439bb40d5691eb58.patch";
46 sha256 = "1zxa5bkwi8hbnh4c0qv72wv6vdp5jlxqizfjsc05ymzvwa99cf75";
47 })
48
49 (substituteAll {
50 name = "zoneinfo-path";
51 src = ./zoneinfo.patch;
52 zoneinfo = "${tzdata}/${python.sitePackages}/tzdata/zoneinfo";
53 })
54 ];
55
56 propagatedBuildInputs = [ tzdata ] ++ lib.optionals (pythonOlder "3.7") [ importlib-resources ];
57
58 pythonImportsCheck = [ "backports.zoneinfo" ];
59
60 nativeCheckInputs = [
61 hypothesis
62 pytestCheckHook
63 ];
64
65 disabledTests = [
66 # AssertionError: 'AEDT' != 'AEST'
67 "test_folds_and_gaps"
68 # AssertionError: 0 != 1 : (datetime.datetime(1917, 3, 25, 2, 0, 1, tzinfo=backports.zoneinfo.ZoneInfo(key='Australia/Sydney')), datetime.datetime(1917, 3, 24, 15, 0, tzinfo=datetime.timezone.utc))
69 "test_folds_from_utc"
70 # backports.zoneinfo._common.ZoneInfoNotFoundError: 'No time zone found with key Eurasia/Badzone'
71 "test_bad_keys"
72 ];
73
74 meta = with lib; {
75 description = "Backport of the standard library module zoneinfo";
76 homepage = "https://github.com/pganssle/zoneinfo";
77 license = licenses.asl20;
78 maintainers = with maintainers; [ jonringer ];
79 };
80}