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

remove: package_resources to use importlib metadata instead #66

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions cid/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import pkg_resources
import sys

if sys.version_info >= (3, 8):
from importlib.metadata import version, PackageNotFoundError
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather import the module because the name of the __version__ variable (which is what users want) is very close to the imported version symbol (which is a function, and not what users want).

Suggested change
from importlib.metadata import version, PackageNotFoundError
import importlib.metadata

... and then, below:

try:
    __version__ = importlib.metadata.version('django-cid')
except importlib.metadata.PackageNotFoundError:
    raise importlib.metadata.PackageNotFoundError("The package `django-cid` is not properly installed.")

(I am not sure whether we should "raise ... from ..." instead, the traceback looks equally hard to read to me... Your version is fine by me.)

else:
from importlib_metadata import version, PackageNotFoundError
Comment on lines +5 to +6
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi. I have juste merged changes that require Python 3.8. Thus, it's not necessary to import from the importlib_metadata (external) package.


__version__ = pkg_resources.get_distribution('django-cid').version
try:
__version__ = version('django-cid')
except PackageNotFoundError:
raise PackageNotFoundError("The package `django-cid` is not properly installed.")