Skip to content

Commit

Permalink
Fix pendulum.tz.timezones() to use system tzdata
Browse files Browse the repository at this point in the history
Fix the `pendulum.tz.available_timezones()` to use
`available_timezones()` function instead of iterating over the files
in `tzdata` package.  This is more in line with PEP 615, as the system
timezone functions will operate on system-provided tzdata when
available, and use the `tzdata` package only if it's not available.
Therefore, the previous code would yield a potentially different list
of timezones than the system actually provides.

Furthermore, Gentoo provides a dummy `tzdata` package that does not
provide any data, since Python always uses system tzdata.  This change
is necessary to make pendulum work again on Gentoo.

Fixes python-pendulum#769
  • Loading branch information
mgorny committed Feb 2, 2024
1 parent 3e3fec6 commit 0143f10
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions src/pendulum/tz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pendulum.tz.timezone import UTC
from pendulum.tz.timezone import FixedTimezone
from pendulum.tz.timezone import Timezone
from pendulum.utils._compat import resources
from pendulum.utils._zoneinfo import available_timezones


PRE_TRANSITION = "pre"
Expand All @@ -22,13 +22,7 @@


def timezones() -> tuple[str, ...]:
global _timezones

if _timezones is None:
with cast(Path, resources.files("tzdata").joinpath("zones")).open() as f:
_timezones = tuple(tz.strip() for tz in f.readlines())

return _timezones
return available_timezones()


def fixed_timezone(offset: int) -> FixedTimezone:
Expand Down

0 comments on commit 0143f10

Please sign in to comment.