From 5697a21eaf8f86cdb2c7f0f34ef9f0595fd84fbe Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Tue, 6 Dec 2022 18:34:08 +0000 Subject: [PATCH] Migrate to native package namespaces Signed-off-by: Stephen Finucane --- setup.py | 2 +- sphinxcontrib/__init__.py | 2 +- sphinxcontrib/openapi/__init__.py | 10 +++++++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index 077dacd..d9b49c0 100755 --- a/setup.py +++ b/setup.py @@ -33,6 +33,7 @@ "sphinx-mdinclude >= 0.5.2", "picobox >= 2.2", "deepmerge >= 0.1", + "importlib-metadata; python_version < '3.8'", ], project_urls={ "Documentation": "https://sphinxcontrib-openapi.readthedocs.io/", @@ -54,6 +55,5 @@ "Framework :: Sphinx", "Framework :: Sphinx :: Extension", ], - namespace_packages=["sphinxcontrib"], python_requires=">=3.7", ) diff --git a/sphinxcontrib/__init__.py b/sphinxcontrib/__init__.py index 418cc3a..6ff9e2b 100644 --- a/sphinxcontrib/__init__.py +++ b/sphinxcontrib/__init__.py @@ -9,4 +9,4 @@ :license: BSD, see LICENSE for details. """ -__import__("pkg_resources").declare_namespace(__name__) +__path__ = __import__("pkgutil").extend_path(__path__, __name__) diff --git a/sphinxcontrib/openapi/__init__.py b/sphinxcontrib/openapi/__init__.py index 9ccdcc9..33908c0 100644 --- a/sphinxcontrib/openapi/__init__.py +++ b/sphinxcontrib/openapi/__init__.py @@ -9,12 +9,16 @@ :license: BSD, see LICENSE for details. """ -from pkg_resources import get_distribution, DistributionNotFound +try: + from importlib.metadata import distribution, PackageNotFoundError +except ImportError: # python < 3.8 + from importlib_metadata import distribution, PackageNotFoundError + from sphinxcontrib.openapi import renderers, directive try: - __version__ = get_distribution(__name__).version -except DistributionNotFound: + __version__ = distribution(__name__).version +except PackageNotFoundError: # package is not installed __version__ = None