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

Reference to pkg_resources #684

Closed
nielsuit227 opened this issue Mar 8, 2023 · 2 comments · Fixed by #754
Closed

Reference to pkg_resources #684

nielsuit227 opened this issue Mar 8, 2023 · 2 comments · Fixed by #754

Comments

@nielsuit227
Copy link

nielsuit227 commented Mar 8, 2023

Setuptools has deprecated pkg_resources, and recommends to importlib instead.
This results in a deprecation warnings for setuptools >= 67.3.0.
https://setuptools.pypa.io/en/latest/pkg_resources.html

Also the python packaging docs say the same, and recommend the following snippet.

import sys

if sys.version_info >= (3, 8):
    from importlib import metadata
else:
    import importlib_metadata as metadata

__version__ =  metadata.version("djangorestframework_simplejwt")

Note that this does include an additional depenceny for Python 3.7, importlib-metadata. With that, all seems to work fine for your supported python versions (3.7-3.10)

@Andrew-Chen-Wang
Copy link
Member

This might be a Jazzband-wide problem. CC @jezdez seeing if anyone else has a different method of doing the same.

But lgtm! Feel free to open a PR

Caellion added a commit to Caellion/djangorestframework-simplejwt that referenced this issue Apr 25, 2023
Co-Authored-By: nielsuit227
Caellion added a commit to Caellion/djangorestframework-simplejwt that referenced this issue Apr 25, 2023
Co-Authored-By: nielsuit227
@grizmio
Copy link

grizmio commented Jul 28, 2023

what do you think about something like this ugly example:

import sys


if sys.version_info >= (3, 8):
    from importlib import metadata
    try:
        __version__ = metadata.version("djangorestframework_simplejwt")
    except metadata.PackageNotFoundError:
        # package is not installed
        __version__ = None
else:
    from pkg_resources import DistributionNotFound, get_distribution

    try:
        __version__ = get_distribution("djangorestframework_simplejwt").version
    except DistributionNotFound:
        # package is not installed
        __version__ = None

#702 (comment)

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