Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extraneous dependency on pytzdata still exists #657

Closed
2 tasks done
joaoe opened this issue Sep 27, 2022 · 5 comments
Closed
2 tasks done

Extraneous dependency on pytzdata still exists #657

joaoe opened this issue Sep 27, 2022 · 5 comments

Comments

@joaoe
Copy link

joaoe commented Sep 27, 2022

  • I am on the latest Pendulum version.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • OS version and name: any (I'm using Windows)
  • Pendulum version: 2.1.2

Issue

Hi.

This commit from mid summer removed the dependency on pytzdata and replaced it with tzdata. The former is a 3rd party python module. The latter is the official timezone database mentioned in the Python docs

However,

  1. The wheel files at pypi.org still list pytzdata as the dependency . For instance, download pendulum-2.1.2.tar.gz, open the PKG-INFO file inside, and see this
Requires-Dist: python-dateutil (>=2.6,<3.0)
Requires-Dist: pytzdata (>=2020.1)
Requires-Dist: typing (>=3.6,<4.0); python_version < "3.5"

That is incorrect.

  1. I tried to find references to pytzdata in the repo and there is a single mention of pytzdata in the [tools.isort] section
    "pytzdata",
    That should be removed.
@joaoe
Copy link
Author

joaoe commented Sep 27, 2022

Oh, I just noticed that the 2.1.2 version on pypi.org is two years old and not from July 2022 ! Is this being maintained ?

@grubberr
Copy link

Hello, we already started to experience some problem with it

docker run -ti --rm python:3.11-slim /bin/bash
pip3 install pendulum
TZ="Europe/Kyiv" python3 -c "import pendulum; pendulum.now()"

    ...
    raise InvalidTimezone(timezone)
pendulum.tz.zoneinfo.exceptions.InvalidTimezone: Invalid timezone "Europe/Kyiv"

@Secrus
Copy link
Collaborator

Secrus commented Oct 27, 2022

We are currently working on version 3.0, which takes some time, especially since both sdispater and I are also Poetry maintainers, so our time is stretched thin as it is.

@NickFabry
Copy link
Sponsor Collaborator

As a temporary fix, to force pendulum 2.1.2 to use either the system zoneinfo, or (on Windows), the zoneinfo from the first party module tzdata, put the following into your python import path as (for example) pendulum_212_fix.py, and after you import pendulum, add the line import pendulum_212_fix, and you should be good.

#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
This module has one purpose - to fix the behavior of pendulum release
2.1.2, which uses a hardcoded version of the IANA zoneinfo data, 2022.2.
Importing this module after importing pendulum should cause pendulum to
use either the OS provided zoneinfo data, or if that does not exist, to
use the zoneinfo from the first party module tzdata. Note this introduces
a dependence on tzdata, which must be separetely installed, typically via
pip install tzdata.

In theory, IMMEDIATELY AFTER IMPORTING pendulum, you should simply
import this module and pendulum will then use the local system
zoneinfo, if available, and if not, the zoneinfo from tzdata, when
creating aware datetimes.
"""



import pathlib
import sysconfig
import tzdata

LOCAL_TZPATH = sysconfig.get_config_var('TZPATH')
if LOCAL_TZPATH:
    # This could be a colon separated list of paths; we take the first only
    LOCAL_TZPATH = LOCAL_TZPATH.split(':')[0]
else:
    LOCAL_TZPATH = pathlib.Path(tzdata.__path__) / 'zoneinfo'

import pendulum
import pytzdata
pytzdata.set_directory(LOCAL_TZPATH)



if __name__ == '__main__':
    pass

@Secrus
Copy link
Collaborator

Secrus commented Dec 17, 2023

Fixed in Pendulum 3.0

@Secrus Secrus closed this as completed Dec 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants