Skip to content

Commit

Permalink
Use importlib.metadata on python3.8+ and importlib_metadata for every…
Browse files Browse the repository at this point in the history
…thing up to and including python3.7

Signed-off-by: miigotu <miigotu@gmail.com>
  • Loading branch information
miigotu committed Apr 9, 2021
1 parent 0ec662b commit 413dd27
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
7 changes: 5 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
import subprocess
import sys

import pkg_resources
try:
from importlib.metadata import version # noqa
except ImportError:
from importlib_metadata import version # noqa

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
Expand Down Expand Up @@ -66,7 +69,7 @@
# the repository hasn't been changed prior to installation).
# https://github.com/pypa/setuptools_scm#usage-from-sphinx
if os.environ.get("READTHEDOCS") == "True":
version = pkg_resources.get_distribution(project).version
version = version(project)
else:
# The project root is the parent directory
root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
Expand Down
11 changes: 7 additions & 4 deletions pymediainfo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@
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.metadata import version, PackageNotFoundError # noqa
except ImportError:
from importlib_metadata import version, PackageNotFoundError # noqa

try:
__version__ = get_distribution("pymediainfo").version
except DistributionNotFound:
pass
__version__ = version("pymediainfo")
except PackageNotFoundError:
__version__ = ''


class Track:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def get_tag(self):
use_scm_version=True,
python_requires=">=3.6",
setup_requires=["setuptools_scm"],
install_requires=["setuptools"],
install_requires=['importlib_metadata; python_version<"3.8"'],
package_data={'pymediainfo': bin_files},
cmdclass=cmdclass,
classifiers=[
Expand Down

0 comments on commit 413dd27

Please sign in to comment.