diff --git a/noxfile.py b/noxfile.py index cd1a556..55574d3 100644 --- a/noxfile.py +++ b/noxfile.py @@ -45,9 +45,9 @@ def unit(session): 'install', [ 'Jinja2==3.0.0', - 'Pillow==8.3.2', # Oldest version that supports Python 3.7 to 3.10. - 'requests==2.22.0', - 'xmldiff==2.4' + 'Pillow==10.1', # Oldest version that supports Python 3.12. + 'requests==2.32.3', # Oldest version that supports Python 3.12 + 'xmldiff==2.6' # Oldest version that supports Python 3.12 ]) def compatibility(session, install): """Run the unit test suite with each support library and Python version.""" diff --git a/pybadges/precalculated_text_measurer.py b/pybadges/precalculated_text_measurer.py index 6e769af..737b6c5 100644 --- a/pybadges/precalculated_text_measurer.py +++ b/pybadges/precalculated_text_measurer.py @@ -18,7 +18,7 @@ import io import json -import pkg_resources +import importlib.resources as resources from typing import cast, Mapping, TextIO, Type from pybadges import text_measurer @@ -74,19 +74,23 @@ def default(cls) -> 'PrecalculatedTextMeasurer': if cls._default_cache is not None: return cls._default_cache - if pkg_resources.resource_exists(__name__, 'default-widths.json.xz'): + resource_name_xz = 'default-widths.json.xz' + resource_name_json = 'default-widths.json' + + resource_package = resources.files(__name__) + resource_xz_path = resource_package / resource_name_xz + resource_json_path = resource_package / resource_name_json + + if resource_xz_path.exists(): import lzma - with pkg_resources.resource_stream(__name__, - 'default-widths.json.xz') as f: - with lzma.open(f, "rt") as g: - cls._default_cache = PrecalculatedTextMeasurer.from_json( - cast(TextIO, g)) + with resources.as_file(resource_xz_path) as path: + with lzma.open(path, "rt") as f: + cls._default_cache = PrecalculatedTextMeasurer.from_json(cast(TextIO, f)) + return cls._default_cache + elif resource_json_path.exists(): + with resources.as_file(resource_json_path) as path: + with open(path, 'r', encoding='utf-8') as f: + cls._default_cache = PrecalculatedTextMeasurer.from_json(f) return cls._default_cache - elif pkg_resources.resource_exists(__name__, 'default-widths.json'): - with pkg_resources.resource_stream(__name__, - 'default-widths.json') as f: - cls._default_cache = PrecalculatedTextMeasurer.from_json( - io.TextIOWrapper(f, encoding='utf-8')) - return cls._default_cache else: raise ValueError('could not load default-widths.json') diff --git a/setup.py b/setup.py index 88559b2..c6b9ca5 100644 --- a/setup.py +++ b/setup.py @@ -49,7 +49,6 @@ def replace_relative_with_absolute(match): 'License :: OSI Approved :: Apache Software License', 'Programming Language :: Python', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: 3.8', 'Programming Language :: Python :: 3.9', 'Programming Language :: Python :: 3.10', @@ -67,17 +66,17 @@ def replace_relative_with_absolute(match): }, long_description=get_long_description(), long_description_content_type='text/markdown', - python_requires='>=3.4', - install_requires=['Jinja2>=3,<4', 'requests>=2.22.0,<3'], + python_requires='>=3.8', + install_requires=['Jinja2>=3,<4', 'requests>=2.32.3,<3'], extras_require={ - 'pil-measurement': ['Pillow>=6,<10'], + 'pil-measurement': ['Pillow>=10.1'], 'dev': [ - 'Flask>=2.0', # For server tests. + 'Flask>=2.0', # For server tests. 'fonttools>=3.26', 'nox', 'Pillow>=5', 'pytest>=3.6', - 'xmldiff>=2.4' + 'xmldiff>=2.6' ], }, license='Apache-2.0',