-
-
Notifications
You must be signed in to change notification settings - Fork 32.6k
Description
Bug report
During migrating our package from pkg_resources
to using importlib.metadata
I encountered some weirdness when it comes to using importlib.metadata.Distribution
objects. Specifically, it seems to lack a custom __eq__
operator, simply inheriting object.__eq__
. In consequence checking distributions for equality seems to just always fail..
from importlib.metadata import distribution
distribution('pip') == distribution('pip') # False
.. which in turn makes it impossible to use dist
kwarg in entry point selection and users have to fall back to manually comparing distribution plain text name
attribute (or something similar / more sophisticated):
from importlib.metadata import entry_points, EntryPoints
entry_points(group='console_scripts', dist='pip') # empty EntryPoints list
entry_points(group='console_scripts', dist=distribution('pip')) # empty EntryPoints list
EntryPoints(ep for ep in entry_points(group='console_scripts') if ep.dist == distribution('pip')) # empty EntryPoints list
EntryPoints(ep for ep in entry_points(group='console_scripts') if ep.dist.name == 'pip') # expected list of entry points
I think comparing distributions for equality should be fixed, maybe even allowing comparison with a plain string containing the distribution's name (e.g. "pip"
) might make sense (although I'm not aware of potential drawbacks / conflicts that might happen in case there might be multiple distributions with same "name" which intuitively seems odd to me).
I believe this is the right place for this report, I'm very sorry if it isn't.
Your environment
- CPython versions tested on: 3.11.4
- Operating system and architecture: Debian Linux 11, linux-64
conda env:
# packages in environment:
#
# Name Version Build Channel
_libgcc_mutex 0.1 conda_forge conda-forge
_openmp_mutex 4.5 2_gnu conda-forge
bzip2 1.0.8 h7f98852_4 conda-forge
ca-certificates 2023.7.22 hbcca054_0 conda-forge
ld_impl_linux-64 2.40 h41732ed_0 conda-forge
libexpat 2.5.0 hcb278e6_1 conda-forge
libffi 3.4.2 h7f98852_5 conda-forge
libgcc-ng 13.1.0 he5830b7_0 conda-forge
libgomp 13.1.0 he5830b7_0 conda-forge
libnsl 2.0.0 h7f98852_0 conda-forge
libsqlite 3.42.0 h2797004_0 conda-forge
libuuid 2.38.1 h0b41bf4_0 conda-forge
libzlib 1.2.13 hd590300_5 conda-forge
ncurses 6.4 hcb278e6_0 conda-forge
openssl 3.1.1 hd590300_1 conda-forge
pip 23.2.1 pyhd8ed1ab_0 conda-forge
python 3.11.4 hab00c5b_0_cpython conda-forge
readline 8.2 h8228510_1 conda-forge
setuptools 68.0.0 pyhd8ed1ab_0 conda-forge
tk 8.6.12 h27826a3_0 conda-forge
tzdata 2023c h71feb2d_0 conda-forge
wheel 0.41.0 pyhd8ed1ab_0 conda-forge
xz 5.2.6 h166bdaf_0 conda-forge
miniconda base env:
shell level : 4
conda version : 23.3.1
python version : 3.9.15.final.0
virtual packages : __archspec=1=x86_64
__glibc=2.31=0
__linux=5.10.0=0
__unix=0=0
channel URLs : https://conda.anaconda.org/conda-forge/linux-64
https://conda.anaconda.org/conda-forge/noarch
platform : linux-64
user-agent : conda/23.3.1 requests/2.29.0 CPython/3.9.15 Linux/5.10.0-21-amd64 debian/11 glibc/2.31 solver/libmamba conda-libmamba-solver/22.8.1 libmambapy/1.1.0