-
Notifications
You must be signed in to change notification settings - Fork 58
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
Replace pkg_resources with importlib.metadata #110
Comments
It looks as straightforward as: try:
from importlib import metadata
except ImportError:
import importlib_metadata as metadata
__version__ = metadata.version("pymediainfo") |
diff --git a/pymediainfo/__init__.py b/pymediainfo/__init__.py
index f05a5a5..efe1974 100644
--- a/pymediainfo/__init__.py
+++ b/pymediainfo/__init__.py
@@ -12,11 +12,14 @@ import warnings
import xml.etree.ElementTree as ET
from typing import Any, Dict, List, Optional, Tuple, Union
-from pkg_resources import DistributionNotFound, get_distribution
+try:
+ from importlib import metadata
+except ImportError:
+ import importlib_metadata as metadata # type: ignore
try:
- __version__ = get_distribution("pymediainfo").version
-except DistributionNotFound:
+ __version__ = metadata.version("pymediainfo")
+except metadata.PackageNotFoundError:
pass
That seems to work, now I just need to set the dependencies right in |
sbraz
added a commit
that referenced
this issue
Apr 9, 2021
This allows us to drop the requirement for setuptools.
sbraz
added a commit
that referenced
this issue
Apr 9, 2021
sbraz
added a commit
that referenced
this issue
Apr 10, 2021
@miigotu I'll push this latest commit with a version bump tomorrow. It's slightly late here and I want to take one last look when I'm properly awake. Thanks for the useful advice. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@miigotu As discussed in #50 (comment), do you have any good example of packages using
importlib.metadata
to expose a__version__
attribute?I guess we'll have to use the backport for older Pythons too.
The text was updated successfully, but these errors were encountered: