1{ lib, buildPythonPackage, fetchFromGitHub
2, pythonAtLeast
3, pythonOlder
4, python
5, substituteAll
6, importlib-resources
7, tzdata
8, hypothesis
9, pytestCheckHook
10, fetchpatch
11}:
12
13buildPythonPackage rec {
14 pname = "backports-zoneinfo";
15 version = "0.2.1";
16
17 disabled = pythonAtLeast "3.9";
18
19 src = fetchFromGitHub {
20 owner = "pganssle";
21 repo = "zoneinfo";
22 rev = version;
23 hash = "sha256-00xdDOVdDanfsjQTd3yjMN2RFGel4cWRrAA3CvSnl24=";
24 };
25
26 # Make sure test data update patch applies
27 prePatch = ''
28 substituteInPlace tests/data/zoneinfo_data.json --replace \"2020a\" \"2021a\"
29 '';
30
31 patches = [
32 # Update test suite's test data to zoneinfo 2022a
33 # https://github.com/pganssle/zoneinfo/pull/115
34 (fetchpatch {
35 name = "backports-zoneinfo-2022a-update-test-data1.patch";
36 url = "https://github.com/pganssle/zoneinfo/pull/115/commits/837e2a0f9f1a1332e4233f83e3648fa564a9ec9e.patch";
37 sha256 = "196knwa212mr0b7zsh8papzr3f5mii87gcjjjx1r9zzvmk3g3ri0";
38 })
39 (fetchpatch {
40 name = "backports-zoneinfo-2022a-update-test-data2.patch";
41 url = "https://github.com/pganssle/zoneinfo/pull/115/commits/9fd330265b177916d6182249439bb40d5691eb58.patch";
42 sha256 = "1zxa5bkwi8hbnh4c0qv72wv6vdp5jlxqizfjsc05ymzvwa99cf75";
43 })
44
45 (substituteAll {
46 name = "zoneinfo-path";
47 src = ./zoneinfo.patch;
48 zoneinfo = "${tzdata}/lib/${python.libPrefix}/site-packages/tzdata/zoneinfo";
49 })
50 ];
51
52 propagatedBuildInputs = [
53 tzdata
54 ] ++ lib.optionals (pythonOlder "3.7") [
55 importlib-resources
56 ];
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}