commit:     17864cf886299bb86752cf231abdfc9bc5b0d552
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Sat Mar 25 16:20:09 2023 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Sat Mar 25 16:21:09 2023 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=17864cf8

dev-python/pytz: Use system timezone-data (again)

Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>

 .../pytz/files/pytz-2023.2-system-tzinfo.patch     | 49 +++++++++++++++++++++
 dev-python/pytz/pytz-2023.2-r1.ebuild              | 51 ++++++++++++++++++++++
 2 files changed, 100 insertions(+)

diff --git a/dev-python/pytz/files/pytz-2023.2-system-tzinfo.patch 
b/dev-python/pytz/files/pytz-2023.2-system-tzinfo.patch
new file mode 100644
index 000000000000..4ce04416dc83
--- /dev/null
+++ b/dev-python/pytz/files/pytz-2023.2-system-tzinfo.patch
@@ -0,0 +1,49 @@
+Inspired by the Fedora patch:
+https://src.fedoraproject.org/rpms/pytz/blob/rawhide/f/pytz-zoneinfo.patch
+
+diff --git a/pytz/__init__.py b/pytz/__init__.py
+index f89d0eb..d00f3bb 100644
+--- a/pytz/__init__.py
++++ b/pytz/__init__.py
+@@ -75,6 +75,20 @@ else:  # Python 2.x
+         return s.encode('ASCII')
+ 
+ 
++def allzones():
++    for dirpath, dirnames, filenames in os.walk(_PYTZ_TZDATADIR):
++        for f in filenames:
++            p = os.path.join(dirpath, f)
++            if open(p, 'rb').read(4) == b'TZif':
++                yield os.path.relpath(p, _PYTZ_TZDATADIR)
++
++
++_PYTZ_TZDATADIR = os.environ.get('PYTZ_TZDATADIR', '/usr/share/zoneinfo')
++_all_timezones_unchecked = LazyList(x for x in allzones())
++all_timezones = _all_timezones_unchecked
++all_timezones_set = LazySet(all_timezones)
++
++
+ def open_resource(name):
+     """Open a resource from the zoneinfo subdir for reading.
+ 
+@@ -88,7 +102,7 @@ def open_resource(name):
+     for part in name_parts:
+         if part == os.path.pardir or os.sep in part:
+             raise ValueError('Bad path segment: %r' % part)
+-    zoneinfo_dir = os.environ.get('PYTZ_TZDATADIR', None)
++    zoneinfo_dir = _PYTZ_TZDATADIR
+     if zoneinfo_dir is not None:
+         filename = os.path.join(zoneinfo_dir, *name_parts)
+     else:
+diff --git a/setup.py b/setup.py
+index 24f7f37..b03592c 100644
+--- a/setup.py
++++ b/setup.py
+@@ -21,7 +21,6 @@ for dirpath, dirnames, filenames in 
os.walk(os.path.join('pytz', 'zoneinfo')):
+     resources.extend([os.path.join(basepath, filename) for filename in 
filenames])
+ package_data = {'pytz': resources}
+ 
+-assert len(resources) > 10, 'zoneinfo files not found!'
+ 
+ setup(
+     name='pytz',

diff --git a/dev-python/pytz/pytz-2023.2-r1.ebuild 
b/dev-python/pytz/pytz-2023.2-r1.ebuild
new file mode 100644
index 000000000000..eea96064ba6e
--- /dev/null
+++ b/dev-python/pytz/pytz-2023.2-r1.ebuild
@@ -0,0 +1,51 @@
+# Copyright 1999-2023 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=8
+
+DISTUTILS_USE_PEP517=setuptools
+PYTHON_COMPAT=( python3_{9..11} pypy3 )
+PYTHON_REQ_USE="threads(+)"
+
+inherit distutils-r1 pypi
+
+DESCRIPTION="World timezone definitions for Python"
+HOMEPAGE="
+       https://pythonhosted.org/pytz/
+       https://github.com/stub42/pytz/
+       https://pypi.org/project/pytz/
+"
+
+LICENSE="MIT"
+SLOT="0"
+KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~loong ~m68k ~mips ~ppc ~ppc64 
~riscv ~s390 ~sparc ~x86 ~amd64-linux ~x86-linux ~ppc-macos ~x64-macos 
~x64-solaris"
+IUSE="test"
+RESTRICT="!test? ( test )"
+
+RDEPEND="
+       || (
+               >=sys-libs/timezone-data-2023b
+               sys-libs/glibc[vanilla]
+       )
+"
+BDEPEND="
+       test? (
+               ${RDEPEND}
+       )
+"
+
+src_prepare() {
+       distutils-r1_src_prepare
+
+       # unbundle timezone-data
+       rm -r pytz/zoneinfo || die
+       # remove hardcoded list of all timezones but leave subjective set
+       # of "common timezones"
+       sed -i -e '/^_all_timezones_unchecked/,/^all_timezones_set/d' 
pytz/__init__.py || die
+       eapply "${FILESDIR}"/pytz-2023.2-system-tzinfo.patch
+}
+
+python_test() {
+       "${EPYTHON}" pytz/tests/test_tzinfo.py -v ||
+               die "Tests fail with ${EPYTHON}"
+}

Reply via email to