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

3.0.1 switched to a deprecated importlib.metadata API that's removed in Python 3.12 #545

Open
mgorny opened this issue Nov 17, 2023 · 7 comments

Comments

@mgorny
Copy link

mgorny commented Nov 17, 2023

The 3.0.1 version switches from pkg_resources to importlib.metadata. However, it uses the deprecate pre-3.10 API that doesn't work with Python 3.12 anymore:

$ tox -e py312
.pkg: _optional_hooks> python /usr/lib/python3.12/site-packages/pyproject_api/_backend.py True setuptools.build_meta __legacy__
.pkg: get_requires_for_build_sdist> python /usr/lib/python3.12/site-packages/pyproject_api/_backend.py True setuptools.build_meta __legacy__
.pkg: get_requires_for_build_wheel> python /usr/lib/python3.12/site-packages/pyproject_api/_backend.py True setuptools.build_meta __legacy__
.pkg: prepare_metadata_for_build_wheel> python /usr/lib/python3.12/site-packages/pyproject_api/_backend.py True setuptools.build_meta __legacy__
.pkg: build_sdist> python /usr/lib/python3.12/site-packages/pyproject_api/_backend.py True setuptools.build_meta __legacy__
py312: install_package> python -I -m pip install --force-reinstall --no-deps /tmp/pygal/.tox/.tmp/package/5/pygal-3.0.1.tar.gz
py312: commands[0]> coverage run --source=pygal /tmp/pygal/.tox/py312/bin/py.test pygal/test --junitxml=junit-py312.xml --flake8
ImportError while loading conftest '/tmp/pygal/pygal/test/conftest.py'.
pygal/__init__.py:64: in <module>
    for entry in entry_points().get('pygal.maps', ()):
E   AttributeError: 'EntryPoints' object has no attribute 'get'
py312: exit 4 (0.93 seconds) /tmp/pygal> coverage run --source=pygal /tmp/pygal/.tox/py312/bin/py.test pygal/test --junitxml=junit-py312.xml --flake8 pid=149296
.pkg: _exit> python /usr/lib/python3.12/site-packages/pyproject_api/_backend.py True setuptools.build_meta __legacy__
  py312: FAIL code 4 (7.79=setup[6.86]+cmd[0.93] seconds)
  evaluation failed :( (7.91 seconds)

See "compatibility note" at the bottom of:
https://docs.python.org/3.11/library/importlib.metadata.html#entry-points

For compatibility, if no parameters are passed to entry_points, a SelectableGroups object is returned, implementing that dict interface. In the future, calling entry_points with no parameters will return an EntryPoints object. Users should rely on the selection interface to retrieve entry points by group.

This is what happens in 3.12, so .get() is no longer valid.

@mgorny
Copy link
Author

mgorny commented Nov 17, 2023

This is a regression in fd4f336. CC @gentooboontoo

@mgorny mgorny changed the title 3.0.1 switched to a deprecated importlb.metadata API that's removed in Python 3.12 3.0.1 switched to a deprecated importlib.metadata API that's removed in Python 3.12 Nov 17, 2023
@rhpvorderman
Copy link

I have the same issue. It is causing crashes on python 3.12 github actions CI just like 3.0.0 did. For projects that use pygal as a dependency, supporting 3.12 is therefore currently not possible. I hope a patch release comes available soon.

gentooboontoo added a commit that referenced this issue Nov 19, 2023
Make it backward compatible with every supported Python version.
Could be a fix to #545.
@gentooboontoo
Copy link
Member

I have just released version 3.0.3 which should fix the problem with Python 3.12 without breaking previous versions >= 3.8.

Please note that running tox run -e py312 now fails with the following unrelated error:

$ tox run -e py312
…
File "kozea/pygal/.tox/py312/lib/python3.12/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2164, in <module>
    register_finder(pkgutil.ImpImporter, find_on_path)
                    ^^^^^^^^^^^^^^^^^^^
AttributeError: module 'pkgutil' has no attribute 'ImpImporter'. Did you mean: 'zipimporter'?

It seems related to this problem.

BTW, if I manually upgrade pip to the latest version using ensurepip, it works. I still don't know how to properly fix it (or if it is only transient):

$ tox run -e py312
# … fails
$ .tox/py312/bin/pip --version
pip 23.0 from kozea/pygal/.tox/py312/lib/python3.12/site-packages/pip (python 3.12)
$ .tox/py312/bin/python -m ensurepip --upgrade
# …
$ .tox/py312/bin/pip3 --version
pip 23.2.1 from kozea/pygal/.tox/py312/lib/python3.12/site-packages/pip (python 3.12)
$ tox run -e py312
# … succeeds

Please tell me if the new release works for you and if this issue could be considered as resolved despite the tox / pip problem.

@pmrowla
Copy link

pmrowla commented Nov 21, 2023

importlib_metadata is not in the install requirements for 3.0.3 (it was only added to the tox dependencies and not setup.py in d1d02c6), so importing pygal will fail even on non-python 3.12 with

  File "/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/pygal/__init__.py", line 32, in <module>
    from importlib_metadata import entry_points
ModuleNotFoundError: No module named 'importlib_metadata'

@rhpvorderman
Copy link

rhpvorderman commented Nov 21, 2023

Please tell me if the new release works for you and if this issue could be considered as resolved despite the tox / pip problem.

All that tox does is install a package in isolation. If it does not work in tox, it means there are hidden dependencies that are not listed, and users will run into problems. Not working in tox means it is not ready for release.

EDIT: I added the importlib-metadata dependency to my own project's setup.py and that solved all problems I had.

@akx
Copy link
Contributor

akx commented Nov 21, 2023

For the time being, adding importlib-metadata as a direct dependency to your project will fix this.

#548 will add that as a dependency here, but ultimately #546 is the fix – the PyPI version of importlib_metadata is not required at all for any project targeting Python 3.8 and up. but when targeting Python 3.10+, it shouldn't be required anymore.

@gentooboontoo
Copy link
Member

Version 3.0.4 is now available. Thanks for feedbacks and submitted PRs. Please tell if any associated issues persist.

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

Successfully merging a pull request may close this issue.

5 participants