From 4823f880783453a072b9baa2bd480a608042e4f7 Mon Sep 17 00:00:00 2001 From: Jarrod Millman Date: Fri, 5 Apr 2024 06:11:57 -0700 Subject: [PATCH 1/3] Drop Python 3.7 support --- .github/workflows/test.yml | 11 +---------- lazy_loader/__init__.py | 9 ++------- pyproject.toml | 6 ++---- 3 files changed, 5 insertions(+), 21 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index af6fc19..d42ebdf 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,16 +9,7 @@ jobs: matrix: os: [ubuntu, macos, windows] python-version: - [ - "3.7", - "3.8", - "3.9", - "3.10", - "3.11", - "3.12-dev", - "pypy-3.8", - "pypy-3.9", - ] + ["3.8", "3.9", "3.10", "3.11", "3.12", "pypy-3.8", "pypy-3.9"] steps: - uses: actions/checkout@v4 diff --git a/lazy_loader/__init__.py b/lazy_loader/__init__.py index b7843ed..02ee509 100644 --- a/lazy_loader/__init__.py +++ b/lazy_loader/__init__.py @@ -43,8 +43,6 @@ def attach(package_name, submodules=None, submod_attrs=None): {'foo': ['someattr']} ) - This functionality requires Python 3.7 or higher. - Parameters ---------- package_name : str @@ -269,12 +267,9 @@ def _check_requirement(require: str) -> bool: True if the installed version of the dependency matches the specified version, False otherwise. """ - import packaging.requirements + import importlib.metadata as importlib_metadata - try: - import importlib.metadata as importlib_metadata - except ImportError: # PY37 - import importlib_metadata + import packaging.requirements req = packaging.requirements.Requirement(require) return req.specifier.contains( diff --git a/pyproject.toml b/pyproject.toml index c81bd40..054066d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "lazy_loader" -requires-python = ">=3.7" +requires-python = ">=3.8" authors = [{name = "Scientific Python Developers"}] readme = "README.md" license = {file = "LICENSE.md"} @@ -13,7 +13,6 @@ classifiers = [ "Development Status :: 4 - Beta", "License :: OSI Approved :: BSD License", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", @@ -23,7 +22,6 @@ classifiers = [ description = "Makes it easy to load subpackages and functions on demand." dependencies = [ "packaging", - "importlib_metadata; python_version < '3.8'", ] [project.optional-dependencies] @@ -44,7 +42,7 @@ attr = 'lazy_loader.__version__' [tool.ruff] line-length = 88 -target-version = "py37" +target-version = "py38" select = [ "C", "E", From df287c2a020bf9a7eb04dade4974e000f2614602 Mon Sep 17 00:00:00 2001 From: Jarrod Millman Date: Fri, 5 Apr 2024 08:23:59 -0700 Subject: [PATCH 2/3] Update pyproject.toml Co-authored-by: Chris Markiewicz --- pyproject.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 054066d..e8f133b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -42,7 +42,6 @@ attr = 'lazy_loader.__version__' [tool.ruff] line-length = 88 -target-version = "py38" select = [ "C", "E", From 799f07e35c018ad7ad8251e2315dd418e355550d Mon Sep 17 00:00:00 2001 From: Jarrod Millman Date: Fri, 5 Apr 2024 08:34:18 -0700 Subject: [PATCH 3/3] Update importlib.metadata import --- lazy_loader/__init__.py | 4 ++-- lazy_loader/tests/test_lazy_loader.py | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/lazy_loader/__init__.py b/lazy_loader/__init__.py index 02ee509..c61ea99 100644 --- a/lazy_loader/__init__.py +++ b/lazy_loader/__init__.py @@ -267,13 +267,13 @@ def _check_requirement(require: str) -> bool: True if the installed version of the dependency matches the specified version, False otherwise. """ - import importlib.metadata as importlib_metadata + import importlib.metadata import packaging.requirements req = packaging.requirements.Requirement(require) return req.specifier.contains( - importlib_metadata.version(req.name), + importlib.metadata.version(req.name), prereleases=True, ) diff --git a/lazy_loader/tests/test_lazy_loader.py b/lazy_loader/tests/test_lazy_loader.py index 19187ba..c811a03 100644 --- a/lazy_loader/tests/test_lazy_loader.py +++ b/lazy_loader/tests/test_lazy_loader.py @@ -160,10 +160,8 @@ def test_stub_loading_errors(tmp_path): def test_require_kwarg(): - have_importlib_metadata = importlib.util.find_spec("importlib.metadata") is not None - dot = "." if have_importlib_metadata else "_" # Test with a module that definitely exists, behavior hinges on requirement - with mock.patch(f"importlib{dot}metadata.version") as version: + with mock.patch("importlib.metadata.version") as version: version.return_value = "1.0.0" math = lazy.load("math", require="somepkg >= 2.0") assert isinstance(math, lazy.DelayedImportErrorModule)