From 3c41727a744a736c9ac665853d0b15d60373182d Mon Sep 17 00:00:00 2001 From: Rok Mandeljc Date: Tue, 26 Oct 2021 23:37:11 +0200 Subject: [PATCH] Add hooks for zoneinfo and backports.zoneinfo 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. --- news/339.new.1.rst | 1 + requirements-test-libraries.txt | 1 + .../hooks/stdhooks/hook-backports.zoneinfo.py | 18 +++++++++++++++ .../hooks/stdhooks/hook-zoneinfo.py | 18 +++++++++++++++ .../tests/test_libraries.py | 22 +++++++++++++++++++ 5 files changed, 60 insertions(+) create mode 100644 news/339.new.1.rst create mode 100644 src/_pyinstaller_hooks_contrib/hooks/stdhooks/hook-backports.zoneinfo.py create mode 100644 src/_pyinstaller_hooks_contrib/hooks/stdhooks/hook-zoneinfo.py diff --git a/news/339.new.1.rst b/news/339.new.1.rst new file mode 100644 index 00000000..0c126ea3 --- /dev/null +++ b/news/339.new.1.rst @@ -0,0 +1 @@ +Add hooks for ``zoneinfo`` and ``backports.zoneinfo``. diff --git a/requirements-test-libraries.txt b/requirements-test-libraries.txt index 1b785171..5595b07b 100644 --- a/requirements-test-libraries.txt +++ b/requirements-test-libraries.txt @@ -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 diff --git a/src/_pyinstaller_hooks_contrib/hooks/stdhooks/hook-backports.zoneinfo.py b/src/_pyinstaller_hooks_contrib/hooks/stdhooks/hook-backports.zoneinfo.py new file mode 100644 index 00000000..93730f47 --- /dev/null +++ b/src/_pyinstaller_hooks_contrib/hooks/stdhooks/hook-backports.zoneinfo.py @@ -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'] diff --git a/src/_pyinstaller_hooks_contrib/hooks/stdhooks/hook-zoneinfo.py b/src/_pyinstaller_hooks_contrib/hooks/stdhooks/hook-zoneinfo.py new file mode 100644 index 00000000..93730f47 --- /dev/null +++ b/src/_pyinstaller_hooks_contrib/hooks/stdhooks/hook-zoneinfo.py @@ -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'] diff --git a/src/_pyinstaller_hooks_contrib/tests/test_libraries.py b/src/_pyinstaller_hooks_contrib/tests/test_libraries.py index 1ff8a617..2747b865 100644 --- a/src/_pyinstaller_hooks_contrib/tests/test_libraries.py +++ b/src/_pyinstaller_hooks_contrib/tests/test_libraries.py @@ -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) + """)