Skip to content

doc: use importlib.metadata in favor of pkg_resources in conf.py #1617

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lemoer
Copy link
Contributor

@lemoer lemoer commented Feb 20, 2025

As can be found here [1], pkg_resources is deprecated and is removed by default from python 3.12 according to [2]. The used alternative importlib.metadata is available from python 3.8 on according to [3].

[1] https://setuptools.pypa.io/en/latest/pkg_resources.html
[2] https://docs.python.org/3/whatsnew/3.12.html
[3] https://docs.python.org/3.12/library/importlib.metadata.html

@Emantor
Copy link
Member

Emantor commented Feb 20, 2025

Hi, you commits are missing a DCO.

@lemoer lemoer force-pushed the pr_doc_use_importlib branch from 3ae876a to ed4b6c8 Compare February 20, 2025 13:59
As can be found here [1], pkg_resources is deprecated and is removed by
default from python 3.12 according to [2]. The used alternative
importlib.metadata is available from python 3.8 on according to [3].

[1] https://setuptools.pypa.io/en/latest/pkg_resources.html
[2] https://docs.python.org/3/whatsnew/3.12.html
[3] https://docs.python.org/3.12/library/importlib.metadata.html

Signed-off-by: Leonardo Mörlein <git@irrelefant.net>
@lemoer lemoer force-pushed the pr_doc_use_importlib branch from ed4b6c8 to 261e95c Compare February 20, 2025 14:06
@lemoer
Copy link
Contributor Author

lemoer commented Feb 20, 2025

Hi, you commits are missing a DCO.

Hi, thanks for the hint. Fixed.

@Bastian-Krause
Copy link
Member

Thanks for taking the time to create this PR!

As can be found here [1], pkg_resources is deprecated and is removed by default from python 3.12 according to [2].

This sounds confusing. The only thing that changed is that setuptools is no longer pre-installed in venvs created with venv. But this has nothing to do with the pkg_resources deprecation and labgrid will still rely on setuptools anyway (see pyproject.toml). Could you please make that more clear?

The used alternative importlib.metadata is available from python 3.8 on according to [3].

[1] https://setuptools.pypa.io/en/latest/pkg_resources.html
[2] https://docs.python.org/3/whatsnew/3.12.html
[3] https://docs.python.org/3.12/library/importlib.metadata.html

The fix itself looks fine.

@lemoer
Copy link
Contributor Author

lemoer commented Feb 25, 2025

Yes, you are right. If I install, setuptools manually, this also solves the problem.

However, using pip install .[docs] in my venv, does not seem to install setuptools inside the venv:

lemoer@luna ~/d/f/g/labgrid ((71fe8956))> python -m venv venv
(venv) lemoer@luna ~/d/f/g/labgrid ((71fe8956))> pip show setuptools
WARNING: Package(s) not found: setuptools
(venv) lemoer@luna ~/d/f/g/labgrid ((71fe8956)) [0|1]> pip install .[doc]
Processing /home/lemoer/documents/ff/git/labgrid
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Collecting ansicolors>=1.1.8 (from labgrid==24.1.dev198)
  Using cached ansicolors-1.1.8-py2.py3-none-any.whl.metadata (9.0 kB)
Collecting attrs>=21.4.0 (from labgrid==24.1.dev198)
  Using cached attrs-25.1.0-py3-none-any.whl.metadata (10 kB)
Collecting grpcio<2.0.0,>=1.64.1 (from labgrid==24.1.dev198)
  Using cached grpcio-1.70.0-cp312-cp312-manylinux_2_17_aarch64.whl.metadata (3.9 kB)
Collecting grpcio-reflection<2.0.0,>=1.64.1 (from labgrid==24.1.dev198)
  Using cached grpcio_reflection-1.70.0-py3-none-any.whl.metadata (1.1 kB)
Collecting protobuf>=5.27.0 (from labgrid==24.1.dev198)
  Using cached protobuf-5.29.3-cp38-abi3-manylinux2014_aarch64.whl.metadata (592 bytes)
Collecting jinja2>=3.0.2 (from labgrid==24.1.dev198)
  Using cached jinja2-3.1.5-py3-none-any.whl.metadata (2.6 kB)
Collecting pexpect>=4.8.0 (from labgrid==24.1.dev198)
  Using cached pexpect-4.9.0-py2.py3-none-any.whl.metadata (2.5 kB)
Collecting pyserial-labgrid>=3.4.0.1 (from labgrid==24.1.dev198)
  Using cached pyserial_labgrid-3.5.0.2-py2.py3-none-any.whl.metadata (2.9 kB)
Collecting pytest>=7.0.0 (from labgrid==24.1.dev198)
  Using cached pytest-8.3.4-py3-none-any.whl.metadata (7.5 kB)
Collecting pyudev>=0.22.0 (from labgrid==24.1.dev198)
  Using cached pyudev-0.24.3-py3-none-any.whl.metadata (4.6 kB)
Collecting pyusb>=1.2.1 (from labgrid==24.1.dev198)
  Using cached pyusb-1.3.1-py3-none-any.whl.metadata (2.5 kB)
Collecting PyYAML>=6.0.1 (from labgrid==24.1.dev198)
  Using cached PyYAML-6.0.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.metadata (2.1 kB)
Collecting requests>=2.26.0 (from labgrid==24.1.dev198)
  Using cached requests-2.32.3-py3-none-any.whl.metadata (4.6 kB)
Collecting xmodem>=0.4.6 (from labgrid==24.1.dev198)
  Using cached xmodem-0.4.7-py3-none-any.whl.metadata (4.3 kB)
Collecting sphinx_rtd_theme>=1.0.0 (from labgrid==24.1.dev198)
  Using cached sphinx_rtd_theme-3.0.2-py2.py3-none-any.whl.metadata (4.4 kB)
Collecting Sphinx>=2.0.0 (from labgrid==24.1.dev198)
  Using cached sphinx-8.2.1-py3-none-any.whl.metadata (7.0 kB)
Collecting MarkupSafe>=2.0 (from jinja2>=3.0.2->labgrid==24.1.dev198)
  Using cached MarkupSafe-3.0.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.metadata (4.0 kB)
Collecting ptyprocess>=0.5 (from pexpect>=4.8.0->labgrid==24.1.dev198)
  Using cached ptyprocess-0.7.0-py2.py3-none-any.whl.metadata (1.3 kB)
Collecting iniconfig (from pytest>=7.0.0->labgrid==24.1.dev198)
  Using cached iniconfig-2.0.0-py3-none-any.whl.metadata (2.6 kB)
Collecting packaging (from pytest>=7.0.0->labgrid==24.1.dev198)
  Using cached packaging-24.2-py3-none-any.whl.metadata (3.2 kB)
Collecting pluggy<2,>=1.5 (from pytest>=7.0.0->labgrid==24.1.dev198)
  Using cached pluggy-1.5.0-py3-none-any.whl.metadata (4.8 kB)
Collecting charset-normalizer<4,>=2 (from requests>=2.26.0->labgrid==24.1.dev198)
  Using cached charset_normalizer-3.4.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.metadata (35 kB)
Collecting idna<4,>=2.5 (from requests>=2.26.0->labgrid==24.1.dev198)
  Using cached idna-3.10-py3-none-any.whl.metadata (10 kB)
Collecting urllib3<3,>=1.21.1 (from requests>=2.26.0->labgrid==24.1.dev198)
  Using cached urllib3-2.3.0-py3-none-any.whl.metadata (6.5 kB)
Collecting certifi>=2017.4.17 (from requests>=2.26.0->labgrid==24.1.dev198)
  Using cached certifi-2025.1.31-py3-none-any.whl.metadata (2.5 kB)
Collecting sphinxcontrib-applehelp>=1.0.7 (from Sphinx>=2.0.0->labgrid==24.1.dev198)
  Using cached sphinxcontrib_applehelp-2.0.0-py3-none-any.whl.metadata (2.3 kB)
Collecting sphinxcontrib-devhelp>=1.0.6 (from Sphinx>=2.0.0->labgrid==24.1.dev198)
  Using cached sphinxcontrib_devhelp-2.0.0-py3-none-any.whl.metadata (2.3 kB)
Collecting sphinxcontrib-htmlhelp>=2.0.6 (from Sphinx>=2.0.0->labgrid==24.1.dev198)
  Using cached sphinxcontrib_htmlhelp-2.1.0-py3-none-any.whl.metadata (2.3 kB)
Collecting sphinxcontrib-jsmath>=1.0.1 (from Sphinx>=2.0.0->labgrid==24.1.dev198)
  Using cached sphinxcontrib_jsmath-1.0.1-py2.py3-none-any.whl.metadata (1.4 kB)
Collecting sphinxcontrib-qthelp>=1.0.6 (from Sphinx>=2.0.0->labgrid==24.1.dev198)
  Using cached sphinxcontrib_qthelp-2.0.0-py3-none-any.whl.metadata (2.3 kB)
Collecting sphinxcontrib-serializinghtml>=1.1.9 (from Sphinx>=2.0.0->labgrid==24.1.dev198)
  Using cached sphinxcontrib_serializinghtml-2.0.0-py3-none-any.whl.metadata (2.4 kB)
Collecting Pygments>=2.17 (from Sphinx>=2.0.0->labgrid==24.1.dev198)
  Using cached pygments-2.19.1-py3-none-any.whl.metadata (2.5 kB)
Collecting docutils<0.22,>=0.20 (from Sphinx>=2.0.0->labgrid==24.1.dev198)
  Using cached docutils-0.21.2-py3-none-any.whl.metadata (2.8 kB)
Collecting snowballstemmer>=2.2 (from Sphinx>=2.0.0->labgrid==24.1.dev198)
  Using cached snowballstemmer-2.2.0-py2.py3-none-any.whl.metadata (6.5 kB)
Collecting babel>=2.13 (from Sphinx>=2.0.0->labgrid==24.1.dev198)
  Using cached babel-2.17.0-py3-none-any.whl.metadata (2.0 kB)
Collecting alabaster>=0.7.14 (from Sphinx>=2.0.0->labgrid==24.1.dev198)
  Using cached alabaster-1.0.0-py3-none-any.whl.metadata (2.8 kB)
Collecting imagesize>=1.3 (from Sphinx>=2.0.0->labgrid==24.1.dev198)
  Using cached imagesize-1.4.1-py2.py3-none-any.whl.metadata (1.5 kB)
Collecting roman-numerals-py>=1.0.0 (from Sphinx>=2.0.0->labgrid==24.1.dev198)
  Using cached roman_numerals_py-3.1.0-py3-none-any.whl.metadata (3.6 kB)
Collecting sphinxcontrib-jquery<5,>=4 (from sphinx_rtd_theme>=1.0.0->labgrid==24.1.dev198)
  Using cached sphinxcontrib_jquery-4.1-py2.py3-none-any.whl.metadata (2.6 kB)
Using cached ansicolors-1.1.8-py2.py3-none-any.whl (13 kB)
Using cached attrs-25.1.0-py3-none-any.whl (63 kB)
Using cached grpcio-1.70.0-cp312-cp312-manylinux_2_17_aarch64.whl (5.7 MB)
Using cached grpcio_reflection-1.70.0-py3-none-any.whl (22 kB)
Using cached jinja2-3.1.5-py3-none-any.whl (134 kB)
Using cached pexpect-4.9.0-py2.py3-none-any.whl (63 kB)
Using cached protobuf-5.29.3-cp38-abi3-manylinux2014_aarch64.whl (319 kB)
Using cached pyserial_labgrid-3.5.0.2-py2.py3-none-any.whl (91 kB)
Using cached pytest-8.3.4-py3-none-any.whl (343 kB)
Using cached pyudev-0.24.3-py3-none-any.whl (62 kB)
Using cached pyusb-1.3.1-py3-none-any.whl (58 kB)
Using cached PyYAML-6.0.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (739 kB)
Using cached requests-2.32.3-py3-none-any.whl (64 kB)
Using cached sphinx-8.2.1-py3-none-any.whl (3.6 MB)
Using cached sphinx_rtd_theme-3.0.2-py2.py3-none-any.whl (7.7 MB)
Using cached xmodem-0.4.7-py3-none-any.whl (35 kB)
Using cached alabaster-1.0.0-py3-none-any.whl (13 kB)
Using cached babel-2.17.0-py3-none-any.whl (10.2 MB)
Using cached certifi-2025.1.31-py3-none-any.whl (166 kB)
Using cached charset_normalizer-3.4.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (140 kB)
Using cached docutils-0.21.2-py3-none-any.whl (587 kB)
Using cached idna-3.10-py3-none-any.whl (70 kB)
Using cached imagesize-1.4.1-py2.py3-none-any.whl (8.8 kB)
Using cached MarkupSafe-3.0.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (24 kB)
Using cached packaging-24.2-py3-none-any.whl (65 kB)
Using cached pluggy-1.5.0-py3-none-any.whl (20 kB)
Using cached ptyprocess-0.7.0-py2.py3-none-any.whl (13 kB)
Using cached pygments-2.19.1-py3-none-any.whl (1.2 MB)
Using cached roman_numerals_py-3.1.0-py3-none-any.whl (7.7 kB)
Using cached snowballstemmer-2.2.0-py2.py3-none-any.whl (93 kB)
Using cached sphinxcontrib_applehelp-2.0.0-py3-none-any.whl (119 kB)
Using cached sphinxcontrib_devhelp-2.0.0-py3-none-any.whl (82 kB)
Using cached sphinxcontrib_htmlhelp-2.1.0-py3-none-any.whl (98 kB)
Using cached sphinxcontrib_jquery-4.1-py2.py3-none-any.whl (121 kB)
Using cached sphinxcontrib_jsmath-1.0.1-py2.py3-none-any.whl (5.1 kB)
Using cached sphinxcontrib_qthelp-2.0.0-py3-none-any.whl (88 kB)
Using cached sphinxcontrib_serializinghtml-2.0.0-py3-none-any.whl (92 kB)
Using cached urllib3-2.3.0-py3-none-any.whl (128 kB)
Using cached iniconfig-2.0.0-py3-none-any.whl (5.9 kB)
Building wheels for collected packages: labgrid
  Building wheel for labgrid (pyproject.toml) ... done
  Created wheel for labgrid: filename=labgrid-24.1.dev198-py3-none-any.whl size=256577 sha256=64edbdc106b8ee08fd355dd4bd108d13b414d703ea885cac0311cd94ff292f17
  Stored in directory: /tmp/pip-ephem-wheel-cache-vhdo44pb/wheels/80/0a/f8/88f447d4ba3cf9dc39c45cf702d8e896db9dd5d989c97a3e1e
Successfully built labgrid
Installing collected packages: xmodem, snowballstemmer, pyserial-labgrid, ptyprocess, ansicolors, urllib3, sphinxcontrib-serializinghtml, sphinxcontrib-qthelp, sphinxcontrib-jsmath, sphinxcontrib-htmlhelp, sphinxcontrib-devhelp, sphinxcontrib-applehelp, roman-numerals-py, PyYAML, pyusb, pyudev, Pygments, protobuf, pluggy, pexpect, packaging, MarkupSafe, iniconfig, imagesize, idna, grpcio, docutils, charset-normalizer, certifi, babel, attrs, alabaster, requests, pytest, jinja2, grpcio-reflection, Sphinx, labgrid, sphinxcontrib-jquery, sphinx_rtd_theme
Successfully installed MarkupSafe-3.0.2 PyYAML-6.0.2 Pygments-2.19.1 Sphinx-8.2.1 alabaster-1.0.0 ansicolors-1.1.8 attrs-25.1.0 babel-2.17.0 certifi-2025.1.31 charset-normalizer-3.4.1 docutils-0.21.2 grpcio-1.70.0 grpcio-reflection-1.70.0 idna-3.10 imagesize-1.4.1 iniconfig-2.0.0 jinja2-3.1.5 labgrid-24.1.dev198 packaging-24.2 pexpect-4.9.0 pluggy-1.5.0 protobuf-5.29.3 ptyprocess-0.7.0 pyserial-labgrid-3.5.0.2 pytest-8.3.4 pyudev-0.24.3 pyusb-1.3.1 requests-2.32.3 roman-numerals-py-3.1.0 snowballstemmer-2.2.0 sphinx_rtd_theme-3.0.2 sphinxcontrib-applehelp-2.0.0 sphinxcontrib-devhelp-2.0.0 sphinxcontrib-htmlhelp-2.1.0 sphinxcontrib-jquery-4.1 sphinxcontrib-jsmath-1.0.1 sphinxcontrib-qthelp-2.0.0 sphinxcontrib-serializinghtml-2.0.0 urllib3-2.3.0 xmodem-0.4.7
(venv) lemoer@luna ~/d/f/g/labgrid ((71fe8956))> pip show setuptools
WARNING: Package(s) not found: setuptools

Manually installing works:

(venv) lemoer@luna ~/d/f/g/labgrid ((71fe8956))> pip install setuptools
Collecting setuptools
  Using cached setuptools-75.8.0-py3-none-any.whl.metadata (6.7 kB)
Using cached setuptools-75.8.0-py3-none-any.whl (1.2 MB)
Installing collected packages: setuptools
Successfully installed setuptools-75.8.0
(venv) lemoer@luna ~/d/f/g/labgrid ((71fe8956))> pip show setuptools
Name: setuptools
Version: 75.8.0
Summary: Easily download, build, install, upgrade, and uninstall Python packages
Home-page:
Author:
Author-email: Python Packaging Authority <distutils-sig@python.org>
License:
Location: /home/lemoer/documents/ff/git/labgrid/venv/lib/python3.12/site-packages
Requires:
Required-by:

I am not sure why this happens. Maybe relevant, maybe not, but outside of the venv, the package is also existing:

(venv) lemoer@luna ~/d/f/g/labgrid ((71fe8956))> deactivate
lemoer@luna ~/d/f/g/labgrid ((71fe8956))> pip show setuptools
DEPRECATION: Loading egg at /usr/local/lib/python3.12/dist-packages/esp_flasher-3.0.3-py3.12.egg is deprecated. pip 24.3 will enforce this behaviour change. A possible replacement is to use pip for package installation. Discussion can be found at https://github.com/pypa/pip/issues/12330
Name: setuptools
Version: 74.1.2
Summary: Easily download, build, install, upgrade, and uninstall Python packages
Home-page:
Author:
Author-email: Python Packaging Authority <distutils-sig@python.org>
License:
Location: /usr/lib/python3/dist-packages
Requires:
Required-by:

I am using ubuntu 24.04 and python 3.12.7.

@Bastian-Krause
Copy link
Member

Bastian-Krause commented Feb 25, 2025

setuptools is only defined as a build-time dependency (see build-system.requires key in our pyproject.toml). Build-time dependencies are managed in an isolated build environment and are not installed into the final virtual environment where labgrid is installed. This step happens in "Installing build dependencies ... done".

The "doc" extra should have included "setuptools" as a dependency to make the "pkg_resources" module available during runtime. Now that you're making setuptools during runtime obsolete, the pyproject.toml is correct as is.

@Bastian-Krause Bastian-Krause self-assigned this Feb 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants