From ca213e5c800941bee987fc87dcfb6e6c1a485900 Mon Sep 17 00:00:00 2001 From: Dane Parin Date: Thu, 12 Nov 2026 20:36:41 +0700 Subject: [PATCH 1/7] Fix dateutil timezone detection when it uses bundled zoneinfo AI disclosure: GPT-6 Luna reviewed the patch. Prompt: Review the patch for potential issues and suggestions. --- .github/workflows/tests.yml | 19 ++++++++++++ news/812.bugfix | 1 + .../test_issue_722_generate_vtimezone.py | 14 +++++++-- .../timezone/equivalent_timezone_ids.py | 4 +-- src/icalendar/timezone/tzid.py | 30 +++++++++++-------- 5 files changed, 50 insertions(+), 18 deletions(-) create mode 100644 news/812.bugfix diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 127c04803..9c232dae9 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -95,6 +95,25 @@ jobs: format: cobertura fail-on-error: false + test-alpine: + name: Test on Alpine Linux without system tzdata + permissions: + contents: read + runs-on: ubuntu-latest + env: + WORKSPACE: ${{ github.workspace }} + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + with: + persist-credentials: false + - name: Run tests in Alpine + run: | + docker run --rm \ + --volume "$WORKSPACE:/icalendar:ro" \ + --workdir /icalendar \ + alpine:edge \ + sh -c 'apk add --no-cache python3 py3-pytest py3-hypothesis py3-tz py3-dateutil py3-tzdata && PYTHONPATH=src python3 -m pytest -q -p no:cacheprovider' + test-distribution: name: Check built packages permissions: diff --git a/news/812.bugfix b/news/812.bugfix new file mode 100644 index 000000000..eea96a3d8 --- /dev/null +++ b/news/812.bugfix @@ -0,0 +1 @@ +Fixed ``dateutil`` timezone detection when it falls back to its bundled zoneinfo. The timezone tests no longer depend on the installed tzdata version, and CI now runs the test suite on Alpine Linux. Reviewed by GPT-6 Luna. @SemTiOne diff --git a/src/icalendar/tests/test_issue_722_generate_vtimezone.py b/src/icalendar/tests/test_issue_722_generate_vtimezone.py index 094e33a71..2141dedb3 100644 --- a/src/icalendar/tests/test_issue_722_generate_vtimezone.py +++ b/src/icalendar/tests/test_issue_722_generate_vtimezone.py @@ -14,10 +14,12 @@ import zoneinfo from datetime import date, datetime, timedelta from re import findall +from types import SimpleNamespace import pytest from dateutil.tz import gettz +import icalendar.timezone.tzid as tzid_module from icalendar import Calendar, Component, Event, Timezone from icalendar.timezone import tzid_from_tzinfo, tzids_from_tzinfo @@ -348,14 +350,13 @@ def test_dateutil_timezone_is_not_found_with_tzname(calendars, no_pytz): assert "dateutil" in repr(cal.events[0].start.tzinfo.__class__) -@pytest.mark.parametrize("tzname", ["America/New_York", "Arctic/Longyearbyen"]) -# @pytest.mark.parametrize("component", ["STANDARD", "DAYLIGHT"]) -def test_dateutil_timezone_is_matched_with_tzname(tzname): +def test_dateutil_timezone_is_matched_with_tzname(): """dateutil is an example of a timezone that has no tzid. In this test we make sure that the timezone is matched by its tzname() in the timezone in the STANDARD and DAYLIGHT components. """ + tzname = "America/New_York" cal = Calendar() event = Event() event.start = datetime(2024, 11, 12, tzinfo=gettz(tzname)) @@ -435,3 +436,10 @@ def test_we_can_identify_dateutil_timezones(tzid): """ tz = gettz(tzid) assert tz is None or tzid in tzids_from_tzinfo(tz) + + +def test_dateutil_timezone_with_bare_id_is_identified(monkeypatch): + """dateutil returns a bare timezone id when it uses its bundled zoneinfo.""" + monkeypatch.setattr(tzid_module, "DATEUTIL_ZONEINFO_PATH", None) + tzfile = SimpleNamespace(_filename="Europe/Berlin") + assert "Europe/Berlin" in tzids_from_tzinfo(tzfile) diff --git a/src/icalendar/timezone/equivalent_timezone_ids.py b/src/icalendar/timezone/equivalent_timezone_ids.py index 210a305cb..f8bd80596 100644 --- a/src/icalendar/timezone/equivalent_timezone_ids.py +++ b/src/icalendar/timezone/equivalent_timezone_ids.py @@ -54,8 +54,8 @@ def main( if we mix timezone implementations. """ unsorted_tzids = available_timezones() - unsorted_tzids.remove("localtime") - unsorted_tzids.remove("Factory") + unsorted_tzids.discard("localtime") + unsorted_tzids.discard("Factory") class TZ(NamedTuple): tz: tzinfo diff --git a/src/icalendar/timezone/tzid.py b/src/icalendar/timezone/tzid.py index 304291ffd..dfa7178ea 100644 --- a/src/icalendar/timezone/tzid.py +++ b/src/icalendar/timezone/tzid.py @@ -38,13 +38,16 @@ def tzids_from_tzinfo(tzinfo: tzinfo | None) -> tuple[str]: >>> import zoneinfo >>> from icalendar.timezone.tzid import tzids_from_tzinfo - >>> tzids_from_tzinfo(zoneinfo.ZoneInfo("Arctic/Longyearbyen")) - ('Arctic/Longyearbyen', 'Atlantic/Jan_Mayen', 'Europe/Berlin', 'Europe/Budapest', 'Europe/Copenhagen', 'Europe/Oslo', 'Europe/Stockholm', 'Europe/Vienna') + >>> tzids = tzids_from_tzinfo(zoneinfo.ZoneInfo("Arctic/Longyearbyen")) + >>> "Arctic/Longyearbyen" in tzids + True + >>> "Europe/Berlin" in tzids + True >>> from dateutil.tz import gettz - >>> tzids_from_tzinfo(gettz("Europe/Berlin")) - ('Europe/Berlin', 'Arctic/Longyearbyen', 'Atlantic/Jan_Mayen', 'Europe/Budapest', 'Europe/Copenhagen', 'Europe/Oslo', 'Europe/Stockholm', 'Europe/Vienna') + >>> "Europe/Berlin" in tzids_from_tzinfo(gettz("Europe/Berlin")) + True - """ # The example might need to change if you recreate the lookup tree # noqa: E501 + """ # The example might need to change if you recreate the lookup tree if tzinfo is None: return () if isinstance(tzinfo, timezone): @@ -63,14 +66,15 @@ def tzids_from_tzinfo(tzinfo: tzinfo | None) -> tuple[str]: if olson is not None: return _get_equivalent_tzids(olson) return _get_equivalent_tzids(tzinfo._name) # noqa: SLF001 - if hasattr(tzinfo, "_filename"): # dateutil.tz.tzfile # noqa: SIM102 - if DATEUTIL_ZONEINFO_PATH is not None: - # tzfile('/usr/share/zoneinfo/Europe/Berlin') - path = tzinfo._filename # noqa: SLF001 - if path.startswith(str(DATEUTIL_ZONEINFO_PATH)): - tzid = str(Path(path).relative_to(DATEUTIL_ZONEINFO_PATH)) - return _get_equivalent_tzids(tzid) - return _get_equivalent_tzids(path) + if hasattr(tzinfo, "_filename"): # dateutil.tz.tzfile + # tzfile('/usr/share/zoneinfo/Europe/Berlin'), or a bare timezone id + # when dateutil uses its bundled zoneinfo. + path = tzinfo._filename # noqa: SLF001 + if DATEUTIL_ZONEINFO_PATH is not None and path.startswith( + str(DATEUTIL_ZONEINFO_PATH) + ): + path = str(Path(path).relative_to(DATEUTIL_ZONEINFO_PATH)) + return _get_equivalent_tzids(path) if isinstance(tzinfo, tz.tzutc): return _get_equivalent_tzids("UTC") return () From 7009a35270e36343348b05ea2c8de8c77c4ab23c Mon Sep 17 00:00:00 2001 From: Dane Parin Date: Thu, 12 Nov 2026 21:00:21 +0700 Subject: [PATCH 2/7] Correct volume mount in tests.yml for Docker --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 9c232dae9..d3acf911a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -109,7 +109,7 @@ jobs: - name: Run tests in Alpine run: | docker run --rm \ - --volume "$WORKSPACE:/icalendar:ro" \ + --volume "$WORKSPACE:/icalendar" \ --workdir /icalendar \ alpine:edge \ sh -c 'apk add --no-cache python3 py3-pytest py3-hypothesis py3-tz py3-dateutil py3-tzdata && PYTHONPATH=src python3 -m pytest -q -p no:cacheprovider' From a1768ebd0cf8014f1ce8463f340d6eaaf45a6638 Mon Sep 17 00:00:00 2001 From: Dane Parin Date: Fri, 13 Nov 2026 23:04:18 +0700 Subject: [PATCH 3/7] Run Alpine tests with system packages and fix dateutil path detection --- .github/workflows/tests.yml | 11 ++--------- Makefile | 4 ++++ scripts/docker/compose.yaml | 26 ++++++++++++++++++++++++++ src/icalendar/timezone/tzid.py | 8 ++++---- tox.ini | 11 +++++++++++ 5 files changed, 47 insertions(+), 13 deletions(-) create mode 100644 scripts/docker/compose.yaml diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e5e636d4e..3365bb4ab 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -96,23 +96,16 @@ jobs: fail-on-error: false test-alpine: - name: Test on Alpine Linux without system tzdata + name: Test on Alpine Linux permissions: contents: read runs-on: ubuntu-latest - env: - WORKSPACE: ${{ github.workspace }} steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 with: persist-credentials: false - name: Run tests in Alpine - run: | - docker run --rm \ - --volume "$WORKSPACE:/icalendar" \ - --workdir /icalendar \ - alpine:edge \ - sh -c 'apk add --no-cache python3 py3-pytest py3-hypothesis py3-tz py3-dateutil py3-tzdata && PYTHONPATH=src python3 -m pytest -q -p no:cacheprovider' + run: make test-alpine test-distribution: name: Check built packages diff --git a/Makefile b/Makefile index 818f8abbb..f4d1e4d66 100644 --- a/Makefile +++ b/Makefile @@ -149,6 +149,10 @@ docs-all: .venv clean vale doctest docstring html linkcheckbroken ## Clean docs test: .venv ## Run code tests and coverage @uv run tox +.PHONY: test-alpine +test-alpine: ## Run the tests on Alpine Linux with system packages + docker compose -f scripts/docker/compose.yaml run --rm alpine + .PHONY: test-dist test-dist: ## Build and test the distribution files @src/icalendar/tests/test_create_release.sh diff --git a/scripts/docker/compose.yaml b/scripts/docker/compose.yaml new file mode 100644 index 000000000..906ffe26f --- /dev/null +++ b/scripts/docker/compose.yaml @@ -0,0 +1,26 @@ +services: + alpine: + image: alpine:3.24.4 + working_dir: /tmp + volumes: + - ../..:/src:ro + command: + - sh + - -eu + - -c + - | + apk add --no-cache \ + py3-coverage \ + py3-dateutil \ + py3-hypothesis \ + py3-pytest \ + py3-tox \ + py3-tz \ + py3-tzdata + + mkdir -p /tmp/icalendar + tar -C /src --exclude=.git --exclude=.venv --exclude=.tox -cf - . \ + | tar -C /tmp/icalendar -xf - + + cd /tmp/icalendar + tox -e alpine diff --git a/src/icalendar/timezone/tzid.py b/src/icalendar/timezone/tzid.py index dfa7178ea..17622212f 100644 --- a/src/icalendar/timezone/tzid.py +++ b/src/icalendar/timezone/tzid.py @@ -70,10 +70,10 @@ def tzids_from_tzinfo(tzinfo: tzinfo | None) -> tuple[str]: # tzfile('/usr/share/zoneinfo/Europe/Berlin'), or a bare timezone id # when dateutil uses its bundled zoneinfo. path = tzinfo._filename # noqa: SLF001 - if DATEUTIL_ZONEINFO_PATH is not None and path.startswith( - str(DATEUTIL_ZONEINFO_PATH) - ): - path = str(Path(path).relative_to(DATEUTIL_ZONEINFO_PATH)) + if DATEUTIL_ZONEINFO_PATH is not None: + path_obj = Path(path) + if path_obj.is_relative_to(DATEUTIL_ZONEINFO_PATH): + path = path_obj.relative_to(DATEUTIL_ZONEINFO_PATH).as_posix() return _get_equivalent_tzids(path) if isinstance(tzinfo, tz.tzutc): return _get_equivalent_tzids("UTC") diff --git a/tox.ini b/tox.ini index 4f066b308..ffd63472e 100644 --- a/tox.ini +++ b/tox.ini @@ -15,6 +15,17 @@ commands = coverage html coverage xml +[testenv:alpine] +description = test environment with Alpine Linux packages +package = skip +basepython = python3 +runner = virtualenv +system_site_packages = true +deps = +dependency_groups = +set_env = + PYTHONPATH = src + [testenv:nopytz] # install with dependencies usedevelop = False From 8eb3064e72e86587fc17fc8d2c5a11fb5dc6ea4e Mon Sep 17 00:00:00 2001 From: Dane Parin Date: Sat, 14 Nov 2026 22:42:59 +0700 Subject: [PATCH 4/7] Override the Tox runner for Alpine tests --- scripts/docker/compose.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/docker/compose.yaml b/scripts/docker/compose.yaml index 906ffe26f..2f31732e4 100644 --- a/scripts/docker/compose.yaml +++ b/scripts/docker/compose.yaml @@ -23,4 +23,4 @@ services: | tar -C /tmp/icalendar -xf - cd /tmp/icalendar - tox -e alpine + tox -e alpine --override testenv.runner=virtualenv From 305f9d1956708ba60546d5826002824d9a7a7527 Mon Sep 17 00:00:00 2001 From: Dane Parin Date: Sat, 14 Nov 2026 22:46:24 +0700 Subject: [PATCH 5/7] Allow coverage in Alpine tox environment --- tox.ini | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tox.ini b/tox.ini index ffd63472e..7f7bffe6b 100644 --- a/tox.ini +++ b/tox.ini @@ -23,6 +23,8 @@ runner = virtualenv system_site_packages = true deps = dependency_groups = +allowlist_externals = + coverage set_env = PYTHONPATH = src From 52deedda89e42fcc00ea2b8337e4042360b092ea Mon Sep 17 00:00:00 2001 From: Dane Parin Date: Fri, 20 Nov 2026 21:15:37 +0700 Subject: [PATCH 6/7] Update changelog --- news/812.bugfix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/news/812.bugfix b/news/812.bugfix index eea96a3d8..4e7dc0d43 100644 --- a/news/812.bugfix +++ b/news/812.bugfix @@ -1 +1 @@ -Fixed ``dateutil`` timezone detection when it falls back to its bundled zoneinfo. The timezone tests no longer depend on the installed tzdata version, and CI now runs the test suite on Alpine Linux. Reviewed by GPT-6 Luna. @SemTiOne +Fixed ``dateutil`` timezone detection when it falls back to its bundled zoneinfo. The timezone tests no longer depend on the installed tzdata version, and CI now runs the test suite on Alpine Linux. Reviewed by GPT-6 Luna. :user:SemTiOne From 4ebe6a42aa2a5fe005a5796e4770f559819491a6 Mon Sep 17 00:00:00 2001 From: Dane Parin Date: Fri, 20 Nov 2026 21:18:37 +0700 Subject: [PATCH 7/7] Fix attribution in changelog --- news/812.bugfix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/news/812.bugfix b/news/812.bugfix index 4e7dc0d43..694a5a920 100644 --- a/news/812.bugfix +++ b/news/812.bugfix @@ -1 +1 @@ -Fixed ``dateutil`` timezone detection when it falls back to its bundled zoneinfo. The timezone tests no longer depend on the installed tzdata version, and CI now runs the test suite on Alpine Linux. Reviewed by GPT-6 Luna. :user:SemTiOne +Fixed ``dateutil`` timezone detection when it falls back to its bundled zoneinfo. The timezone tests no longer depend on the installed tzdata version, and CI now runs the test suite on Alpine Linux. Reviewed by GPT-6 Luna. :user:`SemTiOne`