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] unexpected DeprecationWarning of pkg_resources from script (dev).tmpl #3981

Closed
kenhkl opened this issue Jul 10, 2023 · 12 comments
Closed
Labels
bug Needs Triage Issues that need to be evaluated for severity and status.

Comments

@kenhkl
Copy link

kenhkl commented Jul 10, 2023

setuptools version

setuptools===68.0.0

Python version

Python 3.8

OS

Linux

Additional environment information

No response

Description

Since setuptools group has offically claimed that 'pkg_resources' package was deprecated at here, the use of pkg_resources by the users are reasonable to report a DeprecationWarning, however the use by setuptools itself should not report such warning as I think.

When I install by pip install -e with -e option, the installed script is generated by setuptools/script (dev).tmpl where the following statement exists:

__import__('pkg_resources').require(%(spec)r)

Therefore, I get an unexpected warning when I run the installed script:

...: DeprecationWarning: pkg_resources is deprecated as an API. See ...

A possible solution is to remove

__import__('pkg_resources').require(%(spec)r)

in setuptools/script (dev).tmpl (and probably setuptools/script.tmpl).

Expected behavior

When running a script installed by pip install -e, I expect no DeprecationWarning triggered by __import__('pkg_resources').require from setuptools/script (dev).tmpl.

How to Reproduce

  1. Create a project named test_pkg_resources, with two files:
test_pkg_resources
  |- setup.py
  |- testrun

where, setup.py is:

import setuptools
from os.path import abspath, dirname, join
repo = dirname(abspath(__file__))
setuptools.setup(
    name = "test-proj",
    scripts=[join(repo, "testrun")],
    python_requires=">=3.7",
)

and testrun is:

#!/usr/bin/env python3
if __name__ == "__main__":
    print("Hello!")
  1. run command to install with option -e:
python3 -m pip install -e test_pkg_resources/ --user
  1. run installed script:
testrun
  1. then the unexpected warning appears.

Output

.../bin/testrun:4: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
  __import__('pkg_resources').require('test-proj==0.0.0')
Hello!
@kenhkl kenhkl added bug Needs Triage Issues that need to be evaluated for severity and status. labels Jul 10, 2023
@abravalheri
Copy link
Contributor

Hi @kenhkl, I believe that with a sufficiently updated version of pip will should not be seeing that message.

This is likely to be happening because pip is triggering a deprecated code path.
Since the implementation of PEP 660, editable installs are expected to trigger the editable_wheel command instead of develop.

You can also force pip to use the latest (and not deprecated) behaviour with --use-pep517 flag for pip install.

@kenhkl
Copy link
Author

kenhkl commented Jul 20, 2023

Thanks @abravalheri, really looking forward to a new version of pip.
By the way, a confussion: since my occasion is to use pip to do editable installs, so your suggestion to use --use-pep517 seems not helpful to avoid the pkg_resources DeprecationWarning mentioned above.

You can also force pip to use the latest (and not deprecated) behaviour with --use-pep517 flag for pip install.

@abravalheri
Copy link
Contributor

Have you tried to use pip install --use-pep517 -e .? What is the output that pip provides if you run pip -v install --use-pep517 -e .?

@kenhkl
Copy link
Author

kenhkl commented Jul 25, 2023

@abravalheri Sorry, I did not present my point clearly.
Yes, the warning is missing when I run python3 -m pip install --use-pep517 -e test_pkg_resources/ --user. And the modification on other modules called by testrun can be performed on-the-fly. However, this way differs from using python3 -m pip install -e test_pkg_resources/ --user that the modification on testrun cannot be performed dynamically.

So, if one wants such testrun to be editable installed, then a new version of pip is needed.

Have you tried to use pip install --use-pep517 -e .? What is the output that pip provides if you run pip -v install --use-pep517 -e .?

@abravalheri
Copy link
Contributor

abravalheri commented Jul 25, 2023

Hi @kenhkl, unfortunately I don't know how the testrun script works, but I would like to avoid touching the template that is used by easy-install, because it is hard to fully understand how that would unfold in the ecosystem (there might be old packages out there that depends on this behaviour).

There are other ways to convince pip to use the new APIs for build isolation (which will imply that the new editable_wheel command runs instead of the deprecated develop), would you consider trying one of the following?

Otherwise, I would recommend silencing the warning (e.g. via the PYTHONWARNINGS environment variable or pytest config).

@kenhkl
Copy link
Author

kenhkl commented Jul 28, 2023

Thanks @abravalheri, I now have enough knowledge to deal with the unexpected warnings so far.

@kenhkl kenhkl closed this as completed Jul 28, 2023
@jiasli
Copy link

jiasli commented Jul 31, 2023

I believe that with a sufficiently updated version of pip will should not be seeing that message.

I am using the latest pip

$ pip -V
pip 23.2.1 from /home/user2/py310/lib/python3.10/site-packages/pip (python 3.10)

but our script az installed by pip install -e src/azure-cli still shows this warning:

$ az -v
/home/user2/py310/bin/az:4: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
  __import__('pkg_resources').require('azure-cli==2.51.0')

pip generates /home/user2/py310/bin/az as

$ cat /home/user2/py310/bin/az
#!/home/user2/py310/bin/python
# EASY-INSTALL-DEV-SCRIPT: 'azure-cli==2.51.0','az'
__requires__ = 'azure-cli==2.51.0'
__import__('pkg_resources').require('azure-cli==2.51.0')
__file__ = '/home/user2/azure-cli/src/azure-cli/az'
with open(__file__) as f:
    exec(compile(f.read(), __file__, 'exec'))

@abravalheri
Copy link
Contributor

abravalheri commented Jul 31, 2023

Hi @jiasli , I believe that pip 23.1 was supposed to use isolated builds by default (the new APIs that setuptools already implements), but they decided to postpone a little bit (understandably).

Please have a look on my previous comment for alternatives.

@jiasli
Copy link

jiasli commented Jul 31, 2023

Thanks a lot @abravalheri for sharing this information. We will then wait for the new version of pip. Making changes to such a heavy project is very time-consuming and risky. 🙂

@myz540
Copy link

myz540 commented Jan 14, 2024

Have you tried to use pip install --use-pep517 -e .? What is the output that pip provides if you run pip -v install --use-pep517 -e .?

This actually worked for me, thanks!

@krivadna
Copy link

Have you tried to use pip install --use-pep517 -e .? What is the output that pip provides if you run pip -v install --use-pep517 -e .?

This actually worked for me, thanks!

Pls help

~/dirsearch $ pip -v install --use-pep517 -e

Usage:
pip install [options] [package-index-options] ...
pip install [options] -r [package-index-options] ...
pip install [options] [-e] ...
pip install [options] [-e] ...
pip install [options] <archive url/path> ...

-e option requires 1 argument

@myz540
Copy link

myz540 commented Aug 26, 2024

Have you tried to use pip install --use-pep517 -e .? What is the output that pip provides if you run pip -v install --use-pep517 -e .?

This actually worked for me, thanks!

Pls help

~/dirsearch $ pip -v install --use-pep517 -e

Usage: pip install [options] [package-index-options] ... pip install [options] -r [package-index-options] ... pip install [options] [-e] ... pip install [options] [-e] ... pip install [options] <archive url/path> ...

-e option requires 1 argument

you're missing a ., -e shouldn't require any args but pip install definitely does

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Needs Triage Issues that need to be evaluated for severity and status.
Projects
None yet
Development

No branches or pull requests

5 participants