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

DeprecationWarning from setuptools 67.5.0 and above #727

Closed
uri-rodberg opened this issue Mar 16, 2023 · 9 comments · Fixed by #739
Closed

DeprecationWarning from setuptools 67.5.0 and above #727

uri-rodberg opened this issue Mar 16, 2023 · 9 comments · Fixed by #739
Assignees

Comments

@uri-rodberg
Copy link
Contributor

uri-rodberg commented Mar 16, 2023

Hi,

If setuptools 67.5.0 and above is installed, I receive a DeprecationWarning when running the tests with errors and warnings enabled (tested with Python 3.10.10):

  File "lib\site-packages\sorl\__init__.py", line 1, in <module>
    from pkg_resources import get_distribution, DistributionNotFound
  File "lib\site-packages\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

With setuptools 67.4.0 and below, there is no DeprecationWarning.

@uri-rodberg
Copy link
Contributor Author

uri-rodberg commented Mar 16, 2023

@claudep
Copy link
Contributor

claudep commented Apr 5, 2023

If someone wants to work on this, the most straightforward replacement would be the point 5. of https://packaging.python.org/en/latest/guides/single-sourcing-package-version/ (importlib.metadata)

@uri-rodberg
Copy link
Contributor Author

If someone wants to work on this, the most straightforward replacement would be the point 5. of https://packaging.python.org/en/latest/guides/single-sourcing-package-version/ (importlib.metadata)

This code might work with Python >= 3.8

    from importlib.metadata import version

    __version__ = version("sorl-thumbnail")

It might be worth checking the Python version and/or running this code with try and then fail to what the code is doing right now:

from pkg_resources import get_distribution, DistributionNotFound

try:
    __version__ = get_distribution("sorl-thumbnail").version
except DistributionNotFound:
    pass

@uri-rodberg
Copy link
Contributor Author

Actually, I see they also changed it already. Look at this code:

https://github.com/FactoryBoy/factory_boy/blob/master/factory/__init__.py#L73-L79

@claudep
Copy link
Contributor

claudep commented Apr 5, 2023

I'm sure you are now ready to suggest a PR 😄

@uri-rodberg
Copy link
Contributor Author

I'm sure you are now ready to suggest a PR 😄

I'm not sure I can. Notice that importlib_metadata appears also in https://github.com/FactoryBoy/factory_boy/blob/master/setup.cfg as a required package. I would recommend adding it as a required package for python_version<"3.8" and then using this code:

try:
    # Python 3.8+
    import importlib.metadata as importlib_metadata
except ImportError:
    import importlib_metadata

__version__ = importlib_metadata.version("sorl-thumbnail")

While replacing completely the current code (and not leaving it if the code fails).

@claudep
Copy link
Contributor

claudep commented Apr 5, 2023

That sounds like a plan!

@uri-rodberg
Copy link
Contributor Author

uri-rodberg commented Apr 5, 2023

Yes but I don't know how to add a required package. If you add it then you can just copy my code and put it on https://github.com/jazzband/sorl-thumbnail/blob/master/sorl/__init__.py.

@claudep
Copy link
Contributor

claudep commented Apr 6, 2023

In https://packaging.python.org/en/latest/guides/single-sourcing-package-version/, you'll find the explanation on how to add the conditional dependency.

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