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

Open
#545 7 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

  • #546 by @akx — closed without merging

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
48/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
python

Research direction

Start in pygal/init.py, where entry_points() is used while loading map plugins, and review the compatibility note for importlib.metadata. Run tox -e py312 and the tests under pygal/test first. Done means the Python 3.12 test run no longer raises the EntryPoints.get() error and the existing tests pass.

Written by the indexing model from the issue text.

Description

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.

Dominant language
Python
Stars
2.8k
Forks
419
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Kozea/pygal

All issues in Kozea/pygal

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.