From 92557ed664d50efad9b06db276d89cf7af125bb1 Mon Sep 17 00:00:00 2001 From: Ashlynn Antrobus Date: Thu, 6 Jun 2024 16:23:50 -0600 Subject: [PATCH 1/4] Replaced depreciated pkg_resources with importlib.resources in precalculated_text_measurer.py --- pybadges/precalculated_text_measurer.py | 30 ++++++++++++++----------- 1 file changed, 17 insertions(+), 13 deletions(-) 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') From 5a5c9c032cf318160975109ffd9af670e224d925 Mon Sep 17 00:00:00 2001 From: Ashlynn Antrobus Date: Thu, 6 Jun 2024 16:26:38 -0600 Subject: [PATCH 2/4] Updated Pillow and requests to oldest versions that support Python 3.12 in noxfile.py --- noxfile.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/noxfile.py b/noxfile.py index cd1a556..b86dcee 100644 --- a/noxfile.py +++ b/noxfile.py @@ -45,8 +45,8 @@ 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', + 'Pillow==10.1', # Oldest version that supports Python 3.12. + 'requests==2.32.3', # Oldest version that supports Python 3.12 'xmldiff==2.4' ]) def compatibility(session, install): From 98c09403ae1935103180fc6f58ae1e896911b02a Mon Sep 17 00:00:00 2001 From: Ashlynn Antrobus Date: Thu, 6 Jun 2024 16:29:06 -0600 Subject: [PATCH 3/4] Updated Pillow and requests to oldest versions that support Python 3.12 but these versions don't support Python 3.7 so updated minimum Python version to 3.8 in setup.py --- setup.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 88559b2..1cf04b7 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,10 +66,10 @@ 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. 'fonttools>=3.26', From 27b9b1ede6ddb48868f963ba7a5fb5d5622adc33 Mon Sep 17 00:00:00 2001 From: Ashlynn Antrobus Date: Thu, 6 Jun 2024 16:48:26 -0600 Subject: [PATCH 4/4] updated xmldiff to version 2.6 for Py3.12 support in noxfile.py and setup.py --- noxfile.py | 2 +- setup.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/noxfile.py b/noxfile.py index b86dcee..55574d3 100644 --- a/noxfile.py +++ b/noxfile.py @@ -47,7 +47,7 @@ def unit(session): 'Jinja2==3.0.0', 'Pillow==10.1', # Oldest version that supports Python 3.12. 'requests==2.32.3', # Oldest version that supports Python 3.12 - 'xmldiff==2.4' + '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/setup.py b/setup.py index 1cf04b7..c6b9ca5 100644 --- a/setup.py +++ b/setup.py @@ -71,12 +71,12 @@ def replace_relative_with_absolute(match): extras_require={ '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',