From 30751f8f5b24fa81d1db558ef5c2b3bd7d807b55 Mon Sep 17 00:00:00 2001 From: Cimbali Date: Thu, 30 Mar 2023 23:41:29 +0100 Subject: [PATCH] =?UTF-8?q?Always=20use=20python=203.9=E2=80=99s=20importl?= =?UTF-8?q?ib.resources?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use backport otherwise, i.e. in 3.8 and before. --- pympress/util.py | 16 ++++++---------- setup.cfg | 2 +- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/pympress/util.py b/pympress/util.py index fe0bec84..6a1b62f5 100644 --- a/pympress/util.py +++ b/pympress/util.py @@ -34,10 +34,10 @@ import sys import pathlib -try: - # Introduced in 3.7 +if sys.version_info >= (3, 9): + # Using parts introduced in 3.9 import importlib.resources as importlib_resources -except ImportError: +else: # Backport dependency import importlib_resources @@ -103,13 +103,9 @@ def __get_resource_path(*path_parts): Returns: :class:`~pathlib.Path`: The path to the resource """ - try: - # Introduced in 3.9 - resource = importlib_resources.asfile(importlib_resources.files('pympress').joinpath(*path_parts)) - except AttributeError: - # Deprecated in 3.11 - resource = importlib_resources.path('.'.join(('pympress', *path_parts[:-1])), path_parts[-1]) - return _opened_resources.enter_context(resource) + # Introduced in 3.9 + resource = importlib_resources.files('pympress').joinpath(*path_parts) + return _opened_resources.enter_context(importlib_resources.as_file(resource)) def close_opened_resources(): diff --git a/setup.cfg b/setup.cfg index 28b8e616..58e7c873 100644 --- a/setup.cfg +++ b/setup.cfg @@ -44,7 +44,7 @@ packages = python_requires = >=3.4 install_requires = watchdog - importlib_resources;python_version<"3.7" + importlib_resources >= 1.3;python_version<"3.9" build_requires = setuptools babel