diff --git a/cpython/patches/0007-Warn-on-zoneinfo-without-tzdata.patch b/cpython/patches/0007-Warn-on-zoneinfo-without-tzdata.patch new file mode 100644 index 000000000..6440c3c23 --- /dev/null +++ b/cpython/patches/0007-Warn-on-zoneinfo-without-tzdata.patch @@ -0,0 +1,17 @@ +diff --git a/Lib/zoneinfo/_common.pyold b/Lib/zoneinfo/_common.py +index 98cdfe37..75f8fd2b 100644 +--- a/Lib/zoneinfo/_common.py ++++ b/Lib/zoneinfo/_common.py +@@ -11,6 +11,12 @@ def load_tzdata(key): + try: + return resources.files(package_name).joinpath(resource_name).open("rb") + except (ImportError, FileNotFoundError, UnicodeEncodeError): ++ import sys ++ if "tzdata" not in sys.modules: ++ raise ZoneInfoNotFoundError( ++ f"No time zone found with key {key}. \n" ++ " On Pyodide you must do pyodide.loadPackage('tzdata')" ++ " package before you use zoneinfo.") + # There are three types of exception that can be raised that all amount + # to "we cannot find this key": + # diff --git a/docs/usage/wasm-constraints.md b/docs/usage/wasm-constraints.md index 781e16ca1..931d6d568 100644 --- a/docs/usage/wasm-constraints.md +++ b/docs/usage/wasm-constraints.md @@ -46,6 +46,9 @@ Instead, it is better to load individual modules as needed using Pyodide includes some method stubs based on browser APIs: `webbrowser.open()`, `webbrowser.open_new()`, `webbrowser.open_new_tab()`. +- zoneinfo: The zoneinfo package will only work if you install the timezone data using + the tzdata package (i.e. by calling `pyodide.loadPackage("tzdata")`) + ### Synchronous HTTP requests support Packages for `urllib3` and `requests` are included in pyodide. In browser, these diff --git a/packages/tzdata/meta.yaml b/packages/tzdata/meta.yaml new file mode 100644 index 000000000..c19b31607 --- /dev/null +++ b/packages/tzdata/meta.yaml @@ -0,0 +1,13 @@ +package: + name: tzdata + version: "2024.1" + top-level: + - tzdata +source: + url: https://files.pythonhosted.org/packages/65/58/f9c9e6be752e9fcb8b6a0ee9fb87e6e7a1f6bcab2cdc73f02bb7ba91ada0/tzdata-2024.1-py2.py3-none-any.whl + sha256: 9068bc196136463f5245e51efda838afa15aaeca9903f49050dfa2679db4d252 +about: + home: https://github.com/python/tzdata + PyPI: https://pypi.org/project/tzdata + summary: Provider of IANA time zone data + license: Apache-2.0