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

Upgrade to setuptools 67.6.1 causes DeprecationWarning about pkg_resources #11975

Closed
1 task done
robsdedude opened this issue Apr 17, 2023 · 12 comments
Closed
1 task done
Labels
S: needs triage Issues/PRs that need to be triaged type: bug A confirmed bug or unintended behavior

Comments

@robsdedude
Copy link

robsdedude commented Apr 17, 2023

Description

d7e0248 bumped setuptools introducing a deprecation warning "pkg_resources is deprecated as an API".

I don't see a way of making pip not run into it. With env variable _PIP_USE_IMPORTLIB_METADATA set, trying to install something with pip, I get

Traceback (most recent call last):
  File "/.pyenv/versions/3.10.10/lib/python3.10/site-packages/pip/_internal/cli/base_command.py", line 169, in exc_logging_wrapper
    status = run_func(*args)
  File "/.pyenv/versions/3.10.10/lib/python3.10/site-packages/pip/_internal/cli/req_command.py", line 248, in wrapper
    return func(self, options, args)
  File "/.pyenv/versions/3.10.10/lib/python3.10/site-packages/pip/_internal/commands/install.py", line 324, in run
    session = self.get_default_session(options)
  File "/.pyenv/versions/3.10.10/lib/python3.10/site-packages/pip/_internal/cli/req_command.py", line 98, in get_default_session
    self._session = self.enter_context(self._build_session(options))
  File "/.pyenv/versions/3.10.10/lib/python3.10/site-packages/pip/_internal/cli/req_command.py", line 125, in _build_session
    session = PipSession(
  File "/.pyenv/versions/3.10.10/lib/python3.10/site-packages/pip/_internal/network/session.py", line 342, in __init__
    self.headers["User-Agent"] = user_agent()
  File "/.pyenv/versions/3.10.10/lib/python3.10/site-packages/pip/_internal/network/session.py", line 175, in user_agent
    setuptools_dist = get_default_environment().get_distribution("setuptools")
  File "/.pyenv/versions/3.10.10/lib/python3.10/site-packages/pip/_internal/metadata/importlib/_envs.py", line 188, in get_distribution
    return next(matches, None)
  File "/.pyenv/versions/3.10.10/lib/python3.10/site-packages/pip/_internal/metadata/importlib/_envs.py", line 183, in <genexpr>
    matches = (
  File "/.pyenv/versions/3.10.10/lib/python3.10/site-packages/pip/_internal/metadata/base.py", line 612, in iter_all_distributions
    for dist in self._iter_distributions():
  File "/.pyenv/versions/3.10.10/lib/python3.10/site-packages/pip/_internal/metadata/importlib/_envs.py", line 176, in _iter_distributions
    for dist in finder.find_eggs(location):
  File "/.pyenv/versions/3.10.10/lib/python3.10/site-packages/pip/_internal/metadata/importlib/_envs.py", line 144, in find_eggs
    yield from self._find_eggs_in_dir(location)
  File "/.pyenv/versions/3.10.10/lib/python3.10/site-packages/pip/_internal/metadata/importlib/_envs.py", line 111, in _find_eggs_in_dir
    from pip._vendor.pkg_resources import find_distributions
  File "/.pyenv/versions/3.10.10/lib/python3.10/site-packages/pip/_vendor/pkg_resources/__init__.py", line 121, in <module>
    warnings.warn("pkg_resources is deprecated as an API", DeprecationWarning)
DeprecationWarning: pkg_resources is deprecated as an API

without, I get

Traceback (most recent call last):
  File "/.pyenv/versions/3.10.10/lib/python3.10/site-packages/pip/_internal/cli/base_command.py", line 169, in exc_logging_wrapper
    status = run_func(*args)
  File "/.pyenv/versions/3.10.10/lib/python3.10/site-packages/pip/_internal/cli/req_command.py", line 248, in wrapper
    return func(self, options, args)
  File "/.pyenv/versions/3.10.10/lib/python3.10/site-packages/pip/_internal/commands/install.py", line 324, in run
    session = self.get_default_session(options)
  File "/.pyenv/versions/3.10.10/lib/python3.10/site-packages/pip/_internal/cli/req_command.py", line 98, in get_default_session
    self._session = self.enter_context(self._build_session(options))
  File "/.pyenv/versions/3.10.10/lib/python3.10/site-packages/pip/_internal/cli/req_command.py", line 125, in _build_session
    session = PipSession(
  File "/.pyenv/versions/3.10.10/lib/python3.10/site-packages/pip/_internal/network/session.py", line 342, in __init__
    self.headers["User-Agent"] = user_agent()
  File "/.pyenv/versions/3.10.10/lib/python3.10/site-packages/pip/_internal/network/session.py", line 175, in user_agent
    setuptools_dist = get_default_environment().get_distribution("setuptools")
  File "/.pyenv/versions/3.10.10/lib/python3.10/site-packages/pip/_internal/metadata/__init__.py", line 75, in get_default_environment
    return select_backend().Environment.default()
  File "/.pyenv/versions/3.10.10/lib/python3.10/site-packages/pip/_internal/metadata/__init__.py", line 63, in select_backend
    from . import pkg_resources
  File "/.pyenv/versions/3.10.10/lib/python3.10/site-packages/pip/_internal/metadata/pkg_resources.py", line 8, in <module>
    from pip._vendor import pkg_resources
  File "/.pyenv/versions/3.10.10/lib/python3.10/site-packages/pip/_vendor/pkg_resources/__init__.py", line 121, in <module>
    warnings.warn("pkg_resources is deprecated as an API", DeprecationWarning)
DeprecationWarning: pkg_resources is deprecated as an API

Expected behavior

I'd like there to be a way to invoke pip such that it does not emit any warnings (unless of course some package relies on legacy setup methods or other valid warning cases).

That way, I can run pip with warnings as errors in my CI and actually notice when I run into deprecations.

pip version

23.1

Python version

3.10.10

OS

Linux

How to Reproduce

  1. Install pip 23.1
    python -m install pip==23.1
  2. Run it with warnings as error
    python -W error -m pip freeze
  3. 💥

Output

No response

Code of Conduct

@robsdedude robsdedude added S: needs triage Issues/PRs that need to be triaged type: bug A confirmed bug or unintended behavior labels Apr 17, 2023
@pfmoore
Copy link
Member

pfmoore commented Apr 17, 2023

_PIP_USE_IMPORTLIB_METADATA avoids most use of pkg_resources, but it looks like we still use it to find .egg distributions, even in the importlib.metadata code path.

Maybe we should just stop supporting eggs? IMO, it's about time.

In the meantime, I don't know what the best course of action is - we could patch out the warning from our vendored copy of setuptools, or disable the warning using the warnings machinery. Or we could just revert the setuptools upgrade, as being more trouble than it's worth... @pypa/pip-committers any thoughts?

I should point out, this might block the backport of 23.1 to ensurepip in CPython 3.10 and earlier1, as I believe the CPython test suite runs with warnings as errors.

Footnotes

  1. I've created the PR for CPython, but not merged it yet as I wanted to wait in case we needed a 23.1.1...

@pradyunsg
Copy link
Member

Or we could just revert the setuptools upgrade, as being more trouble than it's worth... @pypa/pip-committers any thoughts?

Let's do that, for now.

@pfmoore
Copy link
Member

pfmoore commented Apr 17, 2023

Let's do that, for now.

#11976

I won't merge just yet, I'll wait in case any other committers have different views.

I don't think this means that we should remove the setuptools upgrade from the ensurepip PR for CPython, as it's only used to pre-install in venv.

@sbidoul
Copy link
Member

sbidoul commented Apr 17, 2023

Should we enable the egg deprecation at the same time?

for dist in finder.find_eggs(location):
# _emit_egg_deprecation(dist.location) # TODO: Enable this.
yield dist

@pfmoore
Copy link
Member

pfmoore commented Apr 17, 2023

I'm -1 on doing that in a bugfix release. Maybe we should have done it in 23.1, but we didn't...

@pradyunsg pradyunsg changed the title Upgrade to setup_tools 67.6.1 causes DeprecationWarning no matter what Upgrade to setuptools 67.6.1 causes DeprecationWarning about pkg_resources Apr 17, 2023
@pradyunsg
Copy link
Member

I don't think this means that we should remove the setuptools upgrade from the ensurepip PR for CPython, as it's only used to pre-install in venv.

Oh, I think we should -- python/cpython#101039 ;)

@pfmoore
Copy link
Member

pfmoore commented Apr 17, 2023

If that goes in, then yes I'll drop setuptools from the upgrade PR. The current iteration of that PR is on the basis that the removal is stalled while the test suite issues get fixed (and so I'd rather we had the latest setuptools version in the meantime).

@pradyunsg
Copy link
Member

Oh, the test suite was fixed in a separate PR. :)

@pfmoore
Copy link
Member

pfmoore commented Apr 17, 2023

Cool, I'll update the PR when python/cpython#101039 gets merged (I'd have to anyway as my PR would get merge conflicts 🙂)

@uranusjr
Copy link
Member

So what should we move forward with this? It seems like a bad idea for us to suddenly deprecate eggs in a point release, so maybe it’d be better to roll back the pkg_resources update in 23.1, and do the upgrade + deprecate eggs in 23.2?

@pfmoore
Copy link
Member

pfmoore commented Apr 18, 2023

I will revert and issue a 23.1.1 bug fix release in a few days (in case there are any other bug fixes to include). For 23.2, we can have a separate discussion. The unconditional deprecation of pkg_resources still hits our users who are on 3.10 and earlier, so we may still prefer to pin to the old pkg_resources even if we do deprecate eggs (which I’m in favour of).

@robsdedude
Copy link
Author

robsdedude commented Apr 26, 2023

Seems like the downgrade of pkg_resources has been released in 23.1.1.

Thanks for the quick resolution 🙌

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
S: needs triage Issues/PRs that need to be triaged type: bug A confirmed bug or unintended behavior
Projects
None yet
Development

No branches or pull requests

5 participants