Skip to content

Commit

Permalink
Add hooks for zoneinfo and backports.zoneinfo
Browse files Browse the repository at this point in the history
On Windows, these packages use timezone data from the tzdata
package. Due to lack of direct import (the data is loaded using
importlib.resources), we need to add a hiddenimport. On other OSes,
system-wide timezone data is used by default.
  • Loading branch information
rokm committed Oct 26, 2021
1 parent 55a5a7a commit 3c41727
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions news/339.new.1.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add hooks for ``zoneinfo`` and ``backports.zoneinfo``.
1 change: 1 addition & 0 deletions requirements-test-libraries.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ importlib_resources==5.3.0; python_version < '3.9'
av==8.0.3
adbutils==0.11.0; sys_platform == 'darwin' or sys_platform == 'win32'
APScheduler==3.8.0
backports.zoneinfo==0.2.1; python_version < '3.9'
boto==2.49.0
boto3==1.18.63
botocore==1.21.63
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# ------------------------------------------------------------------
# Copyright (c) 2021 PyInstaller Development Team.
#
# This file is distributed under the terms of the GNU General Public
# License (version 2.0 or later).
#
# The full license is available in LICENSE.GPL.txt, distributed with
# this software.
#
# SPDX-License-Identifier: GPL-2.0-or-later
# ------------------------------------------------------------------

from PyInstaller.compat import is_win

# On Windows, timezone data is provided by the tzdata package that is
# not directly loaded.
if is_win:
hiddenimports = ['tzdata']
18 changes: 18 additions & 0 deletions src/_pyinstaller_hooks_contrib/hooks/stdhooks/hook-zoneinfo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# ------------------------------------------------------------------
# Copyright (c) 2021 PyInstaller Development Team.
#
# This file is distributed under the terms of the GNU General Public
# License (version 2.0 or later).
#
# The full license is available in LICENSE.GPL.txt, distributed with
# this software.
#
# SPDX-License-Identifier: GPL-2.0-or-later
# ------------------------------------------------------------------

from PyInstaller.compat import is_win

# On Windows, timezone data is provided by the tzdata package that is
# not directly loaded.
if is_win:
hiddenimports = ['tzdata']
22 changes: 22 additions & 0 deletions src/_pyinstaller_hooks_contrib/tests/test_libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -913,3 +913,25 @@ def test_tzdata(pyi_builder):
print(data)
""")


@importorskip("backports.zoneinfo")
@pytest.mark.skipif(is_win and not can_import_module('tzdata'),
reason='On Windows, backports.zoneinfo requires tzdata.')
def test_backports_zoneinfo(pyi_builder):
pyi_builder.test_source("""
from backports import zoneinfo
tz = zoneinfo.ZoneInfo("Europe/Ljubljana")
print(tz)
""")


@importorskip("zoneinfo")
@pytest.mark.skipif(is_win and not can_import_module('tzdata'),
reason='On Windows, zoneinfo requires tzdata.')
def test_zoneinfo(pyi_builder):
pyi_builder.test_source("""
import zoneinfo
tz = zoneinfo.ZoneInfo("Europe/Ljubljana")
print(tz)
""")

0 comments on commit 3c41727

Please sign in to comment.