Skip to content

Commit

Permalink
avoid the use of pkg_resources when importlib.metadata is available (#…
Browse files Browse the repository at this point in the history
…799)

* feat: avoid the use of pkg_resources when importlib.metadata, since pkg_resources is removed from Python 3.12

* feat: avoid the use of pkg_resources when importlib.metadata, since pkg_resources is removed from Python 3.12

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix: remove flake8 errors

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
d9pouces and pre-commit-ci[bot] committed Dec 13, 2023
1 parent 0dd41a3 commit c286019
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
#
# All configuration values have a default; values that are commented out
# serve to show the default.
from pkg_resources import get_distribution

# 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
# documentation root, use os.path.abspath to make it absolute, like shown here.
# sys.path.insert(0, os.path.abspath('.'))
from pipeline import __version__ as pipeline_version

# -- General configuration -----------------------------------------------------

Expand Down Expand Up @@ -45,7 +45,7 @@
# built documents.
#
# The full version, including alpha/beta/rc tags.
release = get_distribution("django-pipeline").version
release = pipeline_version
# The short X.Y version.
version = ".".join(release.split(".")[:2])

Expand Down
33 changes: 27 additions & 6 deletions pipeline/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
from pkg_resources import DistributionNotFound, get_distribution

PackageNotFoundError = None
DistributionNotFound = None
try:
__version__ = get_distribution("django-pipeline").version
except DistributionNotFound:
# package is not installed
__version__ = None
from importlib.metadata import PackageNotFoundError
from importlib.metadata import version as get_version
except ImportError:
get_version = None
PackageNotFoundError = None
if get_version is None:
try:
from pkg_resources import DistributionNotFound, get_distribution

def get_version(x):
return get_distribution(x).version

except ImportError:
get_version = None
DistributionNotFound = None
get_distribution = None

__version__ = None
if get_version is not None:
try:
__version__ = get_version("django-pipeline")
except PackageNotFoundError:
pass
except DistributionNotFound:
pass

0 comments on commit c286019

Please sign in to comment.