From f3847db91c17e6e95bc323d960f804494e7f60fa Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 27 Apr 2026 21:36:37 +0000 Subject: [PATCH 1/2] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - https://github.com/psf/black → https://github.com/psf/black-pre-commit-mirror - [github.com/psf/black-pre-commit-mirror: 23.12.1 → 26.3.1](https://github.com/psf/black-pre-commit-mirror/compare/23.12.1...26.3.1) - [github.com/pre-commit/pre-commit-hooks: v4.5.0 → v6.0.0](https://github.com/pre-commit/pre-commit-hooks/compare/v4.5.0...v6.0.0) - [github.com/pycqa/flake8: 6.1.0 → 7.3.0](https://github.com/pycqa/flake8/compare/6.1.0...7.3.0) - [github.com/asottile/reorder-python-imports: v3.12.0 → v3.16.0](https://github.com/asottile/reorder-python-imports/compare/v3.12.0...v3.16.0) - [github.com/asottile/pyupgrade: v3.15.0 → v3.21.2](https://github.com/asottile/pyupgrade/compare/v3.15.0...v3.21.2) - [github.com/tox-dev/pyproject-fmt: 1.5.3 → v2.21.1](https://github.com/tox-dev/pyproject-fmt/compare/1.5.3...v2.21.1) - [github.com/pre-commit/mirrors-mypy: v1.8.0 → v1.20.2](https://github.com/pre-commit/mirrors-mypy/compare/v1.8.0...v1.20.2) --- .pre-commit-config.yaml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b42096a..19faaef 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,11 +1,11 @@ repos: -- repo: https://github.com/psf/black - rev: 23.12.1 +- repo: https://github.com/psf/black-pre-commit-mirror + rev: 26.3.1 hooks: - id: black args: [--safe, --quiet] - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 + rev: v6.0.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer @@ -14,27 +14,27 @@ repos: - id: check-yaml - id: debug-statements - repo: https://github.com/pycqa/flake8 - rev: 6.1.0 + rev: 7.3.0 hooks: - id: flake8 additional_dependencies: - flake8-typing-imports==1.14.0 - repo: https://github.com/asottile/reorder-python-imports - rev: v3.12.0 + rev: v3.16.0 hooks: - id: reorder-python-imports args: ['--application-directories=.:src'] - repo: https://github.com/asottile/pyupgrade - rev: v3.15.0 + rev: v3.21.2 hooks: - id: pyupgrade args: [--py37-plus] - repo: https://github.com/tox-dev/pyproject-fmt - rev: "1.5.3" + rev: "v2.21.1" hooks: - id: pyproject-fmt - repo: https://github.com/pre-commit/mirrors-mypy - rev: 'v1.8.0' + rev: 'v1.20.2' hooks: - id: mypy From e1533c955a677fc171d5bc608e9ed267ee3b847d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 27 Apr 2026 21:37:11 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- pyproject.toml | 37 ++++----- test_apipkg.py | 217 ++++++++++++------------------------------------- 2 files changed, 68 insertions(+), 186 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 5b59b41..174e648 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,11 +10,9 @@ name = "apipkg" description = "apipkg: namespace control and lazy-import mechanism" readme = "README.rst" license = "MIT" -maintainers = [ - { name = "Ronny Pfannschmidt", email = "opensource+apipkg@ronnypfannschmidt.de"} -] +maintainers = [ { name = "Ronny Pfannschmidt", email = "opensource+apipkg@ronnypfannschmidt.de" } ] authors = [ - { name = "holger krekel" }, + { name = "holger krekel" }, ] requires-python = ">=3.7" classifiers = [ @@ -32,37 +30,30 @@ classifiers = [ "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", + "Programming Language :: Python :: 3.14", "Programming Language :: Python :: Implementation :: CPython", "Topic :: Software Development :: Libraries", ] dynamic = [ "version", ] -[project.urls] -Homepage = "https://github.com/pytest-dev/apipkg" - -[tool.hatch.version] -source = "vcs" +urls.Homepage = "https://github.com/pytest-dev/apipkg" -[tool.hatch.build.targets.sdist] -include = [ - "/src", +[tool.hatch] +build.hooks.vcs.version-file = "src/apipkg/_version.py" +build.targets.sdist.include = [ + "/src", ] -[tool.hatch.build.hooks.vcs] -version-file = "src/apipkg/_version.py" - -[tool.hatch.envs.test] -dependencies = [ +envs.test.dependencies = [ "coverage[toml]", "pytest", "pytest-cov", ] -[[tool.hatch.envs.test.matrix]] -python = ["3.7", "3.8", "3.9", "3.10", "3.11"] - -[tool.hatch.envs.test.scripts] -run-coverage = "pytest --cov-config=pyproject.toml --cov=pkg --cov=tests {args}" -run = "run-coverage --no-cov {args}" +envs.test.matrix = [ { python = [ "3.7", "3.8", "3.9", "3.10", "3.11" ] } ] +envs.test.scripts.run-coverage = "pytest --cov-config=pyproject.toml --cov=pkg --cov=tests {args}" +envs.test.scripts.run = "run-coverage --no-cov {args}" +version.source = "vcs" [mypy] python_version = "3.7" diff --git a/test_apipkg.py b/test_apipkg.py index 7fe64e8..f5739f9 100644 --- a/test_apipkg.py +++ b/test_apipkg.py @@ -24,9 +24,7 @@ def make_modules(cls, tmpdir_factory): pkgdir = cls.tmpdir.ensure("realtest", dir=1) tfile = pkgdir.join("__init__.py") - tfile.write( - textwrap.dedent( - """ + tfile.write(textwrap.dedent(""" import apipkg apipkg.initpkg(__name__, { 'x': { @@ -39,16 +37,12 @@ def make_modules(cls, tmpdir_factory): } } ) - """ - ) - ) + """)) ipkgdir = cls.tmpdir.ensure("_xyz", dir=1) tfile = ipkgdir.join("testmodule.py") ipkgdir.ensure("__init__.py") - tfile.write( - textwrap.dedent( - """ + tfile.write(textwrap.dedent(""" 'test module' from _xyz.othermodule import MyTest @@ -58,9 +52,7 @@ def mytest0(): pass def mytest1(): pass - """ - ) - ) + """)) ipkgdir.join("othermodule.py").write("class MyTest: pass") def setup_method(self, *args): @@ -111,9 +103,7 @@ def test_realmodule___doc__(self): class TestScenarios: def test_relative_import(self, monkeypatch, tmpdir): pkgdir = tmpdir.mkdir("mymodule") - pkgdir.join("__init__.py").write( - textwrap.dedent( - """ + pkgdir.join("__init__.py").write(textwrap.dedent(""" import apipkg apipkg.initpkg(__name__, exportdefs={ '__doc__': '.submod:maindoc', @@ -122,9 +112,7 @@ def test_relative_import(self, monkeypatch, tmpdir): 'z': '.submod:x' }, }) - """ - ) - ) + """)) pkgdir.join("submod.py").write("x=3\nmaindoc='hello'") monkeypatch.syspath_prepend(tmpdir) import mymodule @@ -136,25 +124,17 @@ def test_relative_import(self, monkeypatch, tmpdir): def test_recursive_import(self, monkeypatch, tmpdir): pkgdir = tmpdir.mkdir("recmodule") - pkgdir.join("__init__.py").write( - textwrap.dedent( - """ + pkgdir.join("__init__.py").write(textwrap.dedent(""" import apipkg apipkg.initpkg(__name__, exportdefs={ 'some': '.submod:someclass', }) - """ - ) - ) - pkgdir.join("submod.py").write( - textwrap.dedent( - """ + """)) + pkgdir.join("submod.py").write(textwrap.dedent(""" import recmodule class someclass: pass print(recmodule.__dict__) - """ - ) - ) + """)) monkeypatch.syspath_prepend(tmpdir) import recmodule @@ -163,16 +143,12 @@ class someclass: pass def test_module_alias_import(self, monkeypatch, tmpdir): pkgdir = tmpdir.mkdir("aliasimport") - pkgdir.join("__init__.py").write( - textwrap.dedent( - """ + pkgdir.join("__init__.py").write(textwrap.dedent(""" import apipkg apipkg.initpkg(__name__, exportdefs={ 'some': 'os.path', }) - """ - ) - ) + """)) monkeypatch.syspath_prepend(tmpdir) import aliasimport @@ -181,16 +157,12 @@ def test_module_alias_import(self, monkeypatch, tmpdir): def test_from_module_alias_import(self, monkeypatch, tmpdir): pkgdir = tmpdir.mkdir("fromaliasimport") - pkgdir.join("__init__.py").write( - textwrap.dedent( - """ + pkgdir.join("__init__.py").write(textwrap.dedent(""" import apipkg apipkg.initpkg(__name__, exportdefs={ 'some': 'os.path', }) - """ - ) - ) + """)) monkeypatch.syspath_prepend(tmpdir) from fromaliasimport.some import join @@ -365,18 +337,14 @@ def test_name_attribute(): def test_error_loading_one_element(monkeypatch, tmpdir): pkgdir = tmpdir.mkdir("errorloading1") - pkgdir.join("__init__.py").write( - textwrap.dedent( - """ + pkgdir.join("__init__.py").write(textwrap.dedent(""" import apipkg apipkg.initpkg(__name__, exportdefs={ 'x': '.notexists:x', 'y': '.submod:y' }, ) - """ - ) - ) + """)) pkgdir.join("submod.py").write("y=0") monkeypatch.syspath_prepend(tmpdir) import errorloading1 @@ -391,27 +359,19 @@ def test_error_loading_one_element(monkeypatch, tmpdir): def test_onfirstaccess(tmpdir, monkeypatch): pkgdir = tmpdir.mkdir("firstaccess") - pkgdir.join("__init__.py").write( - textwrap.dedent( - """ + pkgdir.join("__init__.py").write(textwrap.dedent(""" import apipkg apipkg.initpkg(__name__, exportdefs={ '__onfirstaccess__': '.submod:init', 'l': '.submod:l', }, ) - """ - ) - ) - pkgdir.join("submod.py").write( - textwrap.dedent( - """ + """)) + pkgdir.join("submod.py").write(textwrap.dedent(""" l = [] def init(): l.append(1) - """ - ) - ) + """)) monkeypatch.syspath_prepend(tmpdir) import firstaccess @@ -425,27 +385,18 @@ def init(): def test_onfirstaccess_setsnewattr(tmpdir, monkeypatch, mode): pkgname = "mode_" + mode pkgdir = tmpdir.mkdir(pkgname) - pkgdir.join("__init__.py").write( - textwrap.dedent( - """ + pkgdir.join("__init__.py").write(textwrap.dedent(""" import apipkg apipkg.initpkg(__name__, exportdefs={ '__onfirstaccess__': '.submod:init', }, ) - """ - ) - ) - pkgdir.join("submod.py").write( - textwrap.dedent( - """ + """)) + pkgdir.join("submod.py").write(textwrap.dedent(""" def init(): import %s as pkg pkg.newattr = 42 - """ - % pkgname - ) - ) + """ % pkgname)) monkeypatch.syspath_prepend(tmpdir) mod = __import__(pkgname) assert isinstance(mod, apipkg.ApiModule) @@ -463,29 +414,21 @@ def init(): @pytest.mark.skipif("threading" not in sys.modules, reason="requires thread support") def test_onfirstaccess_race(tmpdir, monkeypatch): pkgdir = tmpdir.mkdir("firstaccessrace") - pkgdir.join("__init__.py").write( - textwrap.dedent( - """ + pkgdir.join("__init__.py").write(textwrap.dedent(""" import apipkg apipkg.initpkg(__name__, exportdefs={ '__onfirstaccess__': '.submod:init', 'l': '.submod:l', }, ) - """ - ) - ) - pkgdir.join("submod.py").write( - textwrap.dedent( - """ + """)) + pkgdir.join("submod.py").write(textwrap.dedent(""" import time l = [] def init(): time.sleep(0.1) l.append(1) - """ - ) - ) + """)) monkeypatch.syspath_prepend(tmpdir) import firstaccessrace @@ -517,26 +460,18 @@ def run(self): @pytest.mark.skipif("threading" not in sys.modules, reason="requires thread support") def test_attribute_race(tmpdir, monkeypatch): pkgdir = tmpdir.mkdir("attributerace") - pkgdir.join("__init__.py").write( - textwrap.dedent( - """ + pkgdir.join("__init__.py").write(textwrap.dedent(""" import apipkg apipkg.initpkg(__name__, exportdefs={ 'attr': '.submod:attr', }, ) - """ - ) - ) - pkgdir.join("submod.py").write( - textwrap.dedent( - """ + """)) + pkgdir.join("submod.py").write(textwrap.dedent(""" import time time.sleep(0.1) attr = 42 - """ - ) - ) + """)) monkeypatch.syspath_prepend(tmpdir) import attributerace @@ -567,9 +502,7 @@ def run(self): @pytest.mark.skipif("threading" not in sys.modules, reason="requires thread support") def test_import_race(tmpdir, monkeypatch): pkgdir = tmpdir.mkdir("importrace") - pkgdir.join("__init__.py").write( - textwrap.dedent( - """ + pkgdir.join("__init__.py").write(textwrap.dedent(""" import time time.sleep(0.1) import apipkg @@ -577,16 +510,10 @@ def test_import_race(tmpdir, monkeypatch): 'attr': '.submod:attr', }, ) - """ - ) - ) - pkgdir.join("submod.py").write( - textwrap.dedent( - """ + """)) + pkgdir.join("submod.py").write(textwrap.dedent(""" attr = 43 - """ - ) - ) + """)) monkeypatch.syspath_prepend(tmpdir) class TestThread(threading.Thread): @@ -636,21 +563,15 @@ def test_chdir_with_relative_imports_support_lazy_loading(tmpdir, monkeypatch): monkeypatch.syspath_prepend(os.path.abspath("src")) pkg = tmpdir.mkdir("pkg") tmpdir.mkdir("messy") - pkg.join("__init__.py").write( - textwrap.dedent( - """ + pkg.join("__init__.py").write(textwrap.dedent(""" import apipkg apipkg.initpkg(__name__, { 'test': '.sub:test', }) - """ - ) - ) + """)) pkg.join("sub.py").write("def test(): pass") - tmpdir.join("main.py").write( - textwrap.dedent( - """ + tmpdir.join("main.py").write(textwrap.dedent(""" from __future__ import print_function import os import sys @@ -662,9 +583,7 @@ def test_chdir_with_relative_imports_support_lazy_loading(tmpdir, monkeypatch): os.chdir('messy') pkg.test() assert os.path.isabs(pkg.sub.__file__), pkg.sub.__file__ - """ - ) - ) + """)) res = subprocess.call( [sys.executable, "main.py"], cwd=str(tmpdir), @@ -674,14 +593,10 @@ def test_chdir_with_relative_imports_support_lazy_loading(tmpdir, monkeypatch): def test_dotted_name_lookup(tmpdir, monkeypatch): pkgdir = tmpdir.mkdir("dotted_name_lookup") - pkgdir.join("__init__.py").write( - textwrap.dedent( - """ + pkgdir.join("__init__.py").write(textwrap.dedent(""" import apipkg apipkg.initpkg(__name__, dict(abs='os:path.abspath')) - """ - ) - ) + """)) monkeypatch.syspath_prepend(tmpdir) import dotted_name_lookup @@ -690,14 +605,10 @@ def test_dotted_name_lookup(tmpdir, monkeypatch): def test_extra_attributes(tmpdir, monkeypatch): pkgdir = tmpdir.mkdir("extra_attributes") - pkgdir.join("__init__.py").write( - textwrap.dedent( - """ + pkgdir.join("__init__.py").write(textwrap.dedent(""" import apipkg apipkg.initpkg(__name__, dict(abs='os:path.abspath'), dict(foo='bar')) - """ - ) - ) + """)) monkeypatch.syspath_prepend(tmpdir) import extra_attributes @@ -748,26 +659,18 @@ def test_aliasmodule_repr(): def test_aliasmodule_proxy_methods(tmpdir, monkeypatch): pkgdir = tmpdir - pkgdir.join("aliasmodule_proxy.py").write( - textwrap.dedent( - """ + pkgdir.join("aliasmodule_proxy.py").write(textwrap.dedent(""" def doit(): return 42 - """ - ) - ) + """)) - pkgdir.join("my_aliasmodule_proxy.py").write( - textwrap.dedent( - """ + pkgdir.join("my_aliasmodule_proxy.py").write(textwrap.dedent(""" import apipkg apipkg.initpkg(__name__, dict(proxy='aliasmodule_proxy')) def doit(): return 42 - """ - ) - ) + """)) monkeypatch.syspath_prepend(tmpdir) import aliasmodule_proxy as orig # type: ignore @@ -789,27 +692,19 @@ def test_aliasmodule_nested_import_with_from(tmpdir, monkeypatch): import os pkgdir = tmpdir.mkdir("api1") - pkgdir.ensure("__init__.py").write( - textwrap.dedent( - """ + pkgdir.ensure("__init__.py").write(textwrap.dedent(""" import apipkg apipkg.initpkg(__name__, { 'os2': 'api2', 'os2.path': 'api2.path2', }) - """ - ) - ) - tmpdir.join("api2.py").write( - textwrap.dedent( - """ + """)) + tmpdir.join("api2.py").write(textwrap.dedent(""" import os, sys from os import path sys.modules['api2.path2'] = path x = 3 - """ - ) - ) + """)) monkeypatch.syspath_prepend(tmpdir) from api1 import os2 # type: ignore from api1.os2.path import abspath # type: ignore @@ -872,16 +767,12 @@ def test_importlib_find_spec_initpkg(find_spec, tmpdir, monkeypatch): modname = "apipkg_test_example_initpkg_findspec" pkgdir = tmpdir.mkdir("apipkg_test_example_initpkg_findspec") - pkgdir.ensure("__init__.py").write( - textwrap.dedent( - """ + pkgdir.ensure("__init__.py").write(textwrap.dedent(""" import apipkg apipkg.initpkg(__name__, { 'email': 'email', }) - """ - ) - ) + """)) monkeypatch.syspath_prepend(tmpdir) find_spec(modname)