Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,23 @@ jobs:
format: cobertura
fail-on-error: false

test-alpine:
name: Test on Alpine Linux
permissions:
contents: read
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false
- name: Install uv and Python
uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
with:
enable-cache: false
version: "0.13.9"
- name: Run tests in Alpine
run: make test-alpine

test-distribution:
name: Check built packages
permissions:
Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ 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 against the source distribution on Alpine Linux
rm -rf dist
uv build --sdist --out-dir dist
docker compose -f scripts/docker/compose.yaml run --rm --build alpine

.PHONY: test-dist
test-dist: ## Build and test the distribution files
@src/icalendar/tests/test_create_release.sh
Expand Down
1 change: 1 addition & 0 deletions news/812.bugfix
Original file line number Diff line number Diff line change
@@ -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. :user:`SemTiOne`
27 changes: 27 additions & 0 deletions scripts/docker/alpine/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM python:3.14.10-alpine3.24

WORKDIR /tmp

# Apply Alpine and pip security updates; only upgrade setuptools if present.
RUN apk upgrade --no-cache \
&& python -m pip install --no-cache-dir --upgrade pip \
&& if python -m pip show setuptools >/dev/null 2>&1; then \
python -m pip install --no-cache-dir --upgrade 'setuptools>=78.1.1'; \
fi

# Install pinned test dependencies.
RUN python -m pip install --no-cache-dir \
pytest==9.2.0 \
hypothesis==6.170.17 \
pytz==2026.6

COPY dist/ /tmp/dist/

RUN python -m pip install --no-cache-dir /tmp/dist/icalendar-*.tar.gz \
&& mkdir -p /tmp/icalendar-src \
&& tar -xzf /tmp/dist/icalendar-*.tar.gz \
-C /tmp/icalendar-src --strip-components=1

WORKDIR /tmp/icalendar-src

CMD ["python", "-c", "import pathlib, sysconfig, icalendar, pytest; package = pathlib.Path(icalendar.__file__).resolve(); site_packages = pathlib.Path(sysconfig.get_paths()['purelib']).resolve(); assert package.is_relative_to(site_packages), package; print(package); raise SystemExit(pytest.main(['--import-mode=importlib', 'src/icalendar/tests']))"]
3 changes: 3 additions & 0 deletions scripts/docker/alpine/Dockerfile.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**
!dist/
!dist/*.tar.gz
5 changes: 5 additions & 0 deletions scripts/docker/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
services:
alpine:
build:
context: ../..
dockerfile: scripts/docker/alpine/Dockerfile
14 changes: 11 additions & 3 deletions src/icalendar/tests/test_issue_722_generate_vtimezone.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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)
4 changes: 2 additions & 2 deletions src/icalendar/timezone/equivalent_timezone_ids.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 16 additions & 12 deletions src/icalendar/timezone/tzid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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 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:
# 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)
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)
Comment thread
SemTiOne marked this conversation as resolved.
Resolved
if isinstance(tzinfo, tz.tzutc):
return _get_equivalent_tzids("UTC")
return ()
Expand Down