From ca4d14b52fa94150df595508b9b82d093210688c Mon Sep 17 00:00:00 2001 From: "Christopher J. Markiewicz" Date: Sat, 17 May 2025 09:51:57 -0400 Subject: [PATCH 1/6] Switch to src layout, move tests to root --- pyproject.toml | 2 +- {lazy_loader => src/lazy_loader}/__init__.py | 0 {lazy_loader/tests => tests}/__init__.py | 0 {lazy_loader/tests => tests}/fake_pkg/__init__.py | 0 {lazy_loader/tests => tests}/fake_pkg/__init__.pyi | 0 {lazy_loader/tests => tests}/fake_pkg/some_func.py | 0 {lazy_loader/tests => tests}/import_np_parallel.py | 0 {lazy_loader/tests => tests}/test_lazy_loader.py | 6 +++--- 8 files changed, 4 insertions(+), 4 deletions(-) rename {lazy_loader => src/lazy_loader}/__init__.py (100%) rename {lazy_loader/tests => tests}/__init__.py (100%) rename {lazy_loader/tests => tests}/fake_pkg/__init__.py (100%) rename {lazy_loader/tests => tests}/fake_pkg/__init__.pyi (100%) rename {lazy_loader/tests => tests}/fake_pkg/some_func.py (100%) rename {lazy_loader/tests => tests}/import_np_parallel.py (100%) rename {lazy_loader/tests => tests}/test_lazy_loader.py (97%) diff --git a/pyproject.toml b/pyproject.toml index 36bd7a5..37ea55d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -48,7 +48,7 @@ log_cli_level = "info" [tool.ruff] exclude = [ - "lazy_loader/tests/fake_pkg/__init__.pyi", + "tests/fake_pkg/__init__.pyi", ] [tool.ruff.lint] diff --git a/lazy_loader/__init__.py b/src/lazy_loader/__init__.py similarity index 100% rename from lazy_loader/__init__.py rename to src/lazy_loader/__init__.py diff --git a/lazy_loader/tests/__init__.py b/tests/__init__.py similarity index 100% rename from lazy_loader/tests/__init__.py rename to tests/__init__.py diff --git a/lazy_loader/tests/fake_pkg/__init__.py b/tests/fake_pkg/__init__.py similarity index 100% rename from lazy_loader/tests/fake_pkg/__init__.py rename to tests/fake_pkg/__init__.py diff --git a/lazy_loader/tests/fake_pkg/__init__.pyi b/tests/fake_pkg/__init__.pyi similarity index 100% rename from lazy_loader/tests/fake_pkg/__init__.pyi rename to tests/fake_pkg/__init__.pyi diff --git a/lazy_loader/tests/fake_pkg/some_func.py b/tests/fake_pkg/some_func.py similarity index 100% rename from lazy_loader/tests/fake_pkg/some_func.py rename to tests/fake_pkg/some_func.py diff --git a/lazy_loader/tests/import_np_parallel.py b/tests/import_np_parallel.py similarity index 100% rename from lazy_loader/tests/import_np_parallel.py rename to tests/import_np_parallel.py diff --git a/lazy_loader/tests/test_lazy_loader.py b/tests/test_lazy_loader.py similarity index 97% rename from lazy_loader/tests/test_lazy_loader.py rename to tests/test_lazy_loader.py index 9fcc783..e0d0221 100644 --- a/lazy_loader/tests/test_lazy_loader.py +++ b/tests/test_lazy_loader.py @@ -128,7 +128,7 @@ def test_lazy_attach_returns_copies(): def test_attach_same_module_and_attr_name(): - from lazy_loader.tests import fake_pkg + from tests import fake_pkg # Grab attribute twice, to ensure that importing it does not # override function by module @@ -136,7 +136,7 @@ def test_attach_same_module_and_attr_name(): assert isinstance(fake_pkg.some_func, types.FunctionType) # Ensure imports from submodule still work - from lazy_loader.tests.fake_pkg.some_func import some_func + from tests.fake_pkg.some_func import some_func assert isinstance(some_func, types.FunctionType) @@ -157,7 +157,7 @@ def test_stub_loading(tmp_path): def test_stub_loading_parity(): - from lazy_loader.tests import fake_pkg + from tests import fake_pkg from_stub = lazy.attach_stub(fake_pkg.__name__, fake_pkg.__file__) stub_getter, stub_dir, stub_all = from_stub From b8baa9ff6d8881c0c9c43e845ce994c75aa78c57 Mon Sep 17 00:00:00 2001 From: "Christopher J. Markiewicz" Date: Sat, 17 May 2025 09:56:41 -0400 Subject: [PATCH 2/6] Add tests to MANIFEST.in --- MANIFEST.in | 1 + 1 file changed, 1 insertion(+) diff --git a/MANIFEST.in b/MANIFEST.in index fc49293..51e2849 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1 +1,2 @@ include CHANGELOG.md +recursive-include tests * From 1adea58239893995bf03ce24ac24c6bc5bf31dfc Mon Sep 17 00:00:00 2001 From: "Christopher J. Markiewicz" Date: Sat, 17 May 2025 10:20:41 -0400 Subject: [PATCH 3/6] chore: Configure coverage --- .github/workflows/coverage.yml | 2 +- pyproject.toml | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 2898e39..1fd4f23 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -29,7 +29,7 @@ jobs: - name: Measure test coverage run: | - python -m pytest --cov=lazy_loader --durations=10 + python -m pytest --cov --durations=10 # Tests fail if using `--doctest-modules`. I.e., # python -m pytest --cov=lazy_loader --doctest-modules --durations=20 diff --git a/pyproject.toml b/pyproject.toml index 37ea55d..ba778f2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,7 +25,7 @@ dependencies = [ ] [project.optional-dependencies] -test = ["pytest >= 8.0", "pytest-cov >= 5.0"] +test = ["pytest >= 8.0", "pytest-cov >= 5.0", "coverage[toml] >= 7.2"] lint = ["pre-commit == 4.2.0"] dev = ["changelist == 0.5"] @@ -92,3 +92,13 @@ ignore = [ [tool.ruff.format] docstring-code-format = true + +[tool.coverage.run] +branch = true +source = ["lazy_loader", "tests"] + +[tool.coverage.paths] +source = [ + "src/lazy_loader", + "*/site-packages/lazy_loader", +] From fcc08619687ccb54d0603309b0cb2c2a348cdcb2 Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Sat, 17 May 2025 09:39:44 -0700 Subject: [PATCH 4/6] Only track coverage for lazy-loader, not tests --- .github/workflows/coverage.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 1fd4f23..942a102 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -29,9 +29,9 @@ jobs: - name: Measure test coverage run: | - python -m pytest --cov --durations=10 + python -m pytest --cov=src --durations=10 # Tests fail if using `--doctest-modules`. I.e., - # python -m pytest --cov=lazy_loader --doctest-modules --durations=20 + # python -m pytest --cov=src --durations=10 --doctest-modules - name: Upload coverage to Codecov uses: codecov/codecov-action@v5 From 3c94712149abea51918be413151ee51014c73be2 Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Sat, 17 May 2025 10:15:01 -0700 Subject: [PATCH 5/6] Review MANIFEST.in --- MANIFEST.in | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/MANIFEST.in b/MANIFEST.in index 51e2849..ce1d4c7 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,2 +1,9 @@ include CHANGELOG.md +include .spin/cmds.py recursive-include tests * + +global-exclude *~ +global-exclude *.pyc + +prune */.pytest_cache +prune */__pycache__ From 79aa9d05fcf5c3ef95a0b3f55316e7bd804a80e1 Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Sat, 17 May 2025 10:19:13 -0700 Subject: [PATCH 6/6] Try setting coverage to package name --- .github/workflows/coverage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 942a102..da3a31e 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -29,7 +29,7 @@ jobs: - name: Measure test coverage run: | - python -m pytest --cov=src --durations=10 + python -m pytest --cov=lazy_loader --durations=10 # Tests fail if using `--doctest-modules`. I.e., # python -m pytest --cov=src --durations=10 --doctest-modules