On Mon, 26 Jun 2023 at 19:10, Miro Hrončok <mhron...@redhat.com> wrote:
>
> Hello Patsy,
>
> On 26. 06. 23 17:54, Aoife Moloney wrote:
> > https://fedoraproject.org/wiki/Changes/AllowRemovalOfTzdata
> >
> > == Summary ==
> > Allow the removal of tzdata especially on containers in order to minimize 
> > size.
> > ...
> >
> > In order for this to work, we need packages that use tzdata at run
> > time to switch from Require'ing tzdata to Recommend'ing tzdata.  These
> > packages should also gracefully handle instances where tzdata has been
> > removed.  For example, this would require recognizing that tzdata is
> > not present and providing an appropriate error, such as recommending
> > that the user install tzdata.
> > ...
> > * python3.XX (3.9, 3.10, 3.11, 3.12)
>
> Who is expected to work on this? Python maintainers or this Change proposal 
> owners?
>
> *PEP 615 – Support for the IANA Time Zone Database in the Standard Library* 
> says:
>
>
> """
> Python distributors are encouraged to ensure that time zone data is installed
> alongside Python whenever possible (e.g. by declaring tzdata as a dependency
> for the python package).
> """
>
> from https://peps.python.org/pep-0615/#system-time-zone-information
>
>
> By changing the Requires to Recommends, we would diverge from upstream
> recommendation.
>
> ---
>
> The current problem with Python without tzdata is:
>
> =======================================================================
>  >>> from zoneinfo import ZoneInfo
>  >>> ZoneInfo("Europe/Prague")
> Traceback (most recent call last):
>    File "/usr/lib64/python3.11/zoneinfo/_common.py", line 12, in load_tzdata
>      return resources.files(package_name).joinpath(resource_name).open("rb")
>             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>    File "/usr/lib64/python3.11/importlib/resources/_common.py", line 22, in 
> files
>      return from_package(get_package(package))
>                          ^^^^^^^^^^^^^^^^^^^^
>    File "/usr/lib64/python3.11/importlib/resources/_common.py", line 53, in
> get_package
>      resolved = resolve(package)
>                 ^^^^^^^^^^^^^^^^
>    File "/usr/lib64/python3.11/importlib/resources/_common.py", line 44, in 
> resolve
>      return cand if isinstance(cand, types.ModuleType) else
> importlib.import_module(cand)
>
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>    File "/usr/lib64/python3.11/importlib/__init__.py", line 126, in 
> import_module
>      return _bootstrap._gcd_import(name[level:], package, level)
>             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>    File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
>    File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
>    File "<frozen importlib._bootstrap>", line 1126, in _find_and_load_unlocked
>    File "<frozen importlib._bootstrap>", line 241, in 
> _call_with_frames_removed
>    File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
>    File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
>    File "<frozen importlib._bootstrap>", line 1126, in _find_and_load_unlocked
>    File "<frozen importlib._bootstrap>", line 241, in 
> _call_with_frames_removed
>    File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
>    File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
>    File "<frozen importlib._bootstrap>", line 1140, in _find_and_load_unlocked
> ModuleNotFoundError: No module named 'tzdata'
>
> During handling of the above exception, another exception occurred:
>
> Traceback (most recent call last):
>    File "<stdin>", line 1, in <module>
>    File "/usr/lib64/python3.11/zoneinfo/_common.py", line 24, in load_tzdata
>      raise ZoneInfoNotFoundError(f"No time zone found with key {key}")
> zoneinfo._common.ZoneInfoNotFoundError: 'No time zone found with key 
> Europe/Prague'

This error looks very similar to the one for a non-existent timezone,
e.g. if I have tzdata installed and create ZoneInfo("Fake/McFakeface")
then I get exactly the same error except for the string
"Europe/Prague" in the last line. So it seems like it's actually
working fine. With no tzdata installed, all time zones are treated as
unknown, with the same result as requesting a completely bogus time
zone.



> =======================================================================
>
> Not that ZoneInfo("UTC") also fails:
>
> =======================================================================
>  >>> ZoneInfo("UTC")
> Traceback (most recent call last):
> ...
> zoneinfo._common.ZoneInfoNotFoundError: 'No time zone found with key UTC'
> =======================================================================
>
> So we would need to patch Python to detect missing tzdata and report something
> like:
>
>   ZoneInfoNotInstalledError: 'No time zone information installed on the 
> system,
> you can only use UTC'

I'm not sure that's really needed. You can just treat missing tzdata
as the extreme case of an unknown time zone, where they're all
unknown.

>
> We would also need to ensure UTC work even without tzdata installed.

Yes, that would be useful.

Although IMHO even that seems like a nice-to-have not an absolute
showstopper. Most containerized workloads that don't need time zone
info probably aren't using ZoneInfo("UTC") to convert from UTC to UTC,
they're probably not using ZoneInfo at all.

>
> I would be reluctant to carry this as a downstream-only patch. And the 
> upstream
> window for changes like this has already closed for Python 3.12.
>
_______________________________________________
devel mailing list -- devel@lists.fedoraproject.org
To unsubscribe send an email to devel-le...@lists.fedoraproject.org
Fedora Code of Conduct: 
https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: 
https://lists.fedoraproject.org/archives/list/devel@lists.fedoraproject.org
Do not reply to spam, report it: 
https://pagure.io/fedora-infrastructure/new_issue

Reply via email to