diff --git a/CHANGELOG b/CHANGELOG index 98b42bb..6ef6503 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,6 @@ +1.1.5 + - fix: compatibility with setuptools>=82 (no `pkg_resources`), + which is shipped with CKAN 2.11.6 1.1.4 - ref: replace "word-wrap" with "overflow-wrap" - tests: own the docker image diff --git a/ckanext/__init__.py b/ckanext/__init__.py index de40ea7..b9f5069 100644 --- a/ckanext/__init__.py +++ b/ckanext/__init__.py @@ -1 +1,11 @@ -__import__('pkg_resources').declare_namespace(__name__) +# encoding: utf-8 + +# this is a namespace package +# (same as in CKAN, compatible with setuptools<82 and setuptools>=82, +# which does not ship `pkg_resources` anymore) +try: + import pkg_resources + pkg_resources.declare_namespace(__name__) +except ImportError: + import pkgutil + __path__ = pkgutil.extend_path(__path__, __name__) diff --git a/ckanext/dcor_theme/cli/i18n_branding.py b/ckanext/dcor_theme/cli/i18n_branding.py index e39e39f..2034920 100644 --- a/ckanext/dcor_theme/cli/i18n_branding.py +++ b/ckanext/dcor_theme/cli/i18n_branding.py @@ -1,7 +1,7 @@ from collections import OrderedDict +from importlib import resources as importlib_resources import logging import pathlib -import pkg_resources import subprocess import babel.messages.pofile @@ -51,8 +51,8 @@ def replace_branding(msgid): @click.command() def dcor_theme_i18n_branding(): - src = pathlib.Path(pkg_resources.resource_filename("ckan.i18n", - "ckan.pot")) + src = pathlib.Path(str(importlib_resources.files("ckan.i18n") + / "ckan.pot")) # load file and replace known strings with src.open("r", encoding="utf-8") as fd: poin = babel.messages.pofile.read_po(fd) diff --git a/ckanext/dcor_theme/css/make_dcor_main_css.py b/ckanext/dcor_theme/css/make_dcor_main_css.py index bbfd05c..cfa95d5 100644 --- a/ckanext/dcor_theme/css/make_dcor_main_css.py +++ b/ckanext/dcor_theme/css/make_dcor_main_css.py @@ -1,10 +1,11 @@ """Map CKAN default colors to DCOR colors and generate dcor_theme_colors.css""" -import pkg_resources +from importlib import resources as importlib_resources import pathlib #: Path to CKAN's main.css -ckan_css_path = pathlib.Path( - pkg_resources.resource_filename("ckan", "public/base/css/main.css")) +ckan_css_path = pathlib.Path(str( + importlib_resources.files("ckan") / "public" / "base" / "css" + / "main.css")) #: Dictionary mapping default colors to DCOR colors color_map = { diff --git a/ckanext/dcor_theme/tests/test_setuptools.py b/ckanext/dcor_theme/tests/test_setuptools.py new file mode 100644 index 0000000..923d1a3 --- /dev/null +++ b/ckanext/dcor_theme/tests/test_setuptools.py @@ -0,0 +1,10 @@ +import subprocess +import sys + + +def test_import_without_pkg_resources(): + """setuptools>=82 does not ship `pkg_resources` (e.g. CKAN 2.11.6)""" + code = ("import sys; " + "sys.modules['pkg_resources'] = None; " # import raises an error + "import ckanext.dcor_theme.plugin") + subprocess.check_call([sys.executable, "-c", code])