summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2023-03-25 17:20:09 +0100
committerMichał Górny <mgorny@gentoo.org>2023-03-25 17:21:09 +0100
commit17864cf886299bb86752cf231abdfc9bc5b0d552 (patch)
tree93dbbe020ce4af53f5e95118a5dd3e1e82e62cdb /dev-python/pytz
parentdev-ml/ppx_custom_printf: Stabilize 0.15.0-r1 arm, #901681 (diff)
downloadgentoo-17864cf886299bb86752cf231abdfc9bc5b0d552.tar.gz
gentoo-17864cf886299bb86752cf231abdfc9bc5b0d552.tar.bz2
gentoo-17864cf886299bb86752cf231abdfc9bc5b0d552.zip
dev-python/pytz: Use system timezone-data (again)
Signed-off-by: Michał Górny <mgorny@gentoo.org>
Diffstat (limited to 'dev-python/pytz')
-rw-r--r--dev-python/pytz/files/pytz-2023.2-system-tzinfo.patch49
-rw-r--r--dev-python/pytz/pytz-2023.2-r1.ebuild51
2 files changed, 100 insertions, 0 deletions
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}"
+}