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

[BUG] import pkg_resources emits DeprecationWarning #2885

Closed
1 task done
kmaehashi opened this issue Nov 15, 2021 · 3 comments · Fixed by #2889
Closed
1 task done

[BUG] import pkg_resources emits DeprecationWarning #2885

kmaehashi opened this issue Nov 15, 2021 · 3 comments · Fixed by #2889
Labels

Comments

@kmaehashi
Copy link

setuptools version

setuptools==59.1.0

Python version

3.9.5

OS

Ubuntu

Additional environment information

No response

Description

DeprecationWarning is emitted just by importing pkg_resources.
This seems like a regression in 59.1.0; this issue did not reproduce with 59.0.1.

Expected behavior

No warnings were emitted by import.

How to Reproduce

python -Werror -c 'import pkg_resources'

Output

Traceback (most recent call last):
  File "/home/maehashi/.pyenv/versions/local-3.9.5/lib/python3.9/site-packages/pkg_resources/_vendor/packaging/version.py", line 49, in parse
    return Version(version)
  File "/home/maehashi/.pyenv/versions/local-3.9.5/lib/python3.9/site-packages/pkg_resources/_vendor/packaging/version.py", line 266, in __init__
    raise InvalidVersion(f"Invalid version: '{version}'")
pkg_resources.extern.packaging.version.InvalidVersion: Invalid version: '/home/maehashi/.pyenv/versions/3.9.5/envs/local'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/maehashi/.pyenv/versions/local-3.9.5/lib/python3.9/site-packages/pkg_resources/__init__.py", line 3257, in <module>
    def _initialize_master_working_set():
  File "/home/maehashi/.pyenv/versions/local-3.9.5/lib/python3.9/site-packages/pkg_resources/__init__.py", line 3231, in _call_aside
    f(*args, **kwargs)
  File "/home/maehashi/.pyenv/versions/local-3.9.5/lib/python3.9/site-packages/pkg_resources/__init__.py", line 3269, in _initialize_master_working_set
    working_set = WorkingSet._build_master()
  File "/home/maehashi/.pyenv/versions/local-3.9.5/lib/python3.9/site-packages/pkg_resources/__init__.py", line 564, in _build_master
    ws = cls()
  File "/home/maehashi/.pyenv/versions/local-3.9.5/lib/python3.9/site-packages/pkg_resources/__init__.py", line 557, in __init__
    self.add_entry(entry)
  File "/home/maehashi/.pyenv/versions/local-3.9.5/lib/python3.9/site-packages/pkg_resources/__init__.py", line 613, in add_entry
    for dist in find_distributions(entry, True):
  File "/home/maehashi/.pyenv/versions/local-3.9.5/lib/python3.9/site-packages/pkg_resources/__init__.py", line 2064, in find_on_path
    path_item_entries = _by_version_descending(filtered)
  File "/home/maehashi/.pyenv/versions/local-3.9.5/lib/python3.9/site-packages/pkg_resources/__init__.py", line 2034, in _by_version_descending
    return sorted(names, key=_by_version, reverse=True)
  File "/home/maehashi/.pyenv/versions/local-3.9.5/lib/python3.9/site-packages/pkg_resources/__init__.py", line 2032, in _by_version
    return [packaging.version.parse(part) for part in parts]
  File "/home/maehashi/.pyenv/versions/local-3.9.5/lib/python3.9/site-packages/pkg_resources/__init__.py", line 2032, in <listcomp>
    return [packaging.version.parse(part) for part in parts]
  File "/home/maehashi/.pyenv/versions/local-3.9.5/lib/python3.9/site-packages/pkg_resources/_vendor/packaging/version.py", line 51, in parse
    return LegacyVersion(version)
  File "/home/maehashi/.pyenv/versions/local-3.9.5/lib/python3.9/site-packages/pkg_resources/_vendor/packaging/version.py", line 111, in __init__
    warnings.warn(
DeprecationWarning: Creating a LegacyVersion has been deprecated and will be removed in the next major release

Code of Conduct

  • I agree to follow the PSF Code of Conduct
@jaraco
Copy link
Member

jaraco commented Nov 15, 2021

The warning is intentionally emitted by packaging, which was updated in this version. The use of unsupported versions was previously deprecated, so I’m slightly surprised the error wasn’t triggered at the earlier warning in parse_version.

Oh. I see that parse is being called directly, not through parse_version. I did not realize that Version.parse had its own fallback.

In that case, I’m glad this caught the deprecation warning. Now we just have to figure out why a path is being passed as a version.

@jaraco
Copy link
Member

jaraco commented Nov 15, 2021

It's unclear to me what factor is triggering the error. Do you know what I could do to replicate the environment where this issue occurs? I do see that _by_version_descending is being called with a name that includes a path, possibly one with a dash in it.

Oh, my! I was able to replicate the issue easily just by invoking Python in Setuptools' own test environment:

$ ./.tox/python/bin/python -We -c "import pkg_resources"
Traceback (most recent call last):
  File "/Users/jaraco/code/public/pypa/setuptools/pkg_resources/_vendor/packaging/version.py", line 49, in parse
    return Version(version)
  File "/Users/jaraco/code/public/pypa/setuptools/pkg_resources/_vendor/packaging/version.py", line 266, in __init__
    raise InvalidVersion(f"Invalid version: '{version}'")
pkg_resources.extern.packaging.version.InvalidVersion: Invalid version: '/Users/jaraco/code/public/pypa/setuptools/setuptools'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/jaraco/code/public/pypa/setuptools/pkg_resources/__init__.py", line 3257, in <module>
    def _initialize_master_working_set():
  File "/Users/jaraco/code/public/pypa/setuptools/pkg_resources/__init__.py", line 3231, in _call_aside
    f(*args, **kwargs)
  File "/Users/jaraco/code/public/pypa/setuptools/pkg_resources/__init__.py", line 3269, in _initialize_master_working_set
    working_set = WorkingSet._build_master()
  File "/Users/jaraco/code/public/pypa/setuptools/pkg_resources/__init__.py", line 564, in _build_master
    ws = cls()
  File "/Users/jaraco/code/public/pypa/setuptools/pkg_resources/__init__.py", line 557, in __init__
    self.add_entry(entry)
  File "/Users/jaraco/code/public/pypa/setuptools/pkg_resources/__init__.py", line 613, in add_entry
    for dist in find_distributions(entry, True):
  File "/Users/jaraco/code/public/pypa/setuptools/pkg_resources/__init__.py", line 2064, in find_on_path
    path_item_entries = _by_version_descending(filtered)
  File "/Users/jaraco/code/public/pypa/setuptools/pkg_resources/__init__.py", line 2034, in _by_version_descending
    return sorted(names, key=_by_version, reverse=True)
  File "/Users/jaraco/code/public/pypa/setuptools/pkg_resources/__init__.py", line 2032, in _by_version
    return [packaging.version.parse(part) for part in parts]
  File "/Users/jaraco/code/public/pypa/setuptools/pkg_resources/__init__.py", line 2032, in <listcomp>
    return [packaging.version.parse(part) for part in parts]
  File "/Users/jaraco/code/public/pypa/setuptools/pkg_resources/_vendor/packaging/version.py", line 51, in parse
    return LegacyVersion(version)
  File "/Users/jaraco/code/public/pypa/setuptools/pkg_resources/_vendor/packaging/version.py", line 111, in __init__
    warnings.warn(
DeprecationWarning: Creating a LegacyVersion has been deprecated and will be removed in the next major release

I'm going to yank this version for now to limit disruption while I work out a solution later this week.

@jaraco
Copy link
Member

jaraco commented Nov 15, 2021

Screen Shot 2021-11-15 at 09 08 51

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants