diff --git a/docs/conf.py b/docs/conf.py index 6612bef2..7101aab5 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -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 ----------------------------------------------------- @@ -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]) diff --git a/pipeline/__init__.py b/pipeline/__init__.py index 9bedee87..9ee79765 100644 --- a/pipeline/__init__.py +++ b/pipeline/__init__.py @@ -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