From b60838b6dfac85c8d20226f6a18264dd4e171707 Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Sat, 17 May 2025 10:25:21 -0700 Subject: [PATCH 1/3] Add spin configuration --- .spin/cmds.py | 19 +++++++++++++++++++ pyproject.toml | 15 ++++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 .spin/cmds.py diff --git a/.spin/cmds.py b/.spin/cmds.py new file mode 100644 index 0000000..0745c02 --- /dev/null +++ b/.spin/cmds.py @@ -0,0 +1,19 @@ +import sys + +import click +from spin.cmds.util import run + + +@click.command() +@click.argument("pytest_args", nargs=-1) +@click.option( + "-c", + "--coverage", + is_flag=True, + help="Generate a coverage report of executed tests.", +) +def test(pytest_args, coverage=False): + """🔧 Run tests""" + if coverage: + pytest_args = ("--cov=lazy_loader", *pytest_args) + run([sys.executable, "-m", "pytest", *list(pytest_args)]) diff --git a/pyproject.toml b/pyproject.toml index 3040854..48a187e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,15 +3,14 @@ requires = ["setuptools>=61.2"] build-backend = "setuptools.build_meta" [project] -name = "lazy_loader" +name = "lazy-loader" requires-python = ">=3.9" authors = [{name = "Scientific Python Developers"}] readme = "README.md" -license = {file = "LICENSE.md"} +license = "BSD-3-Clause" dynamic = ['version'] classifiers = [ "Development Status :: 5 - Production/Stable", - "License :: OSI Approved :: BSD License", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", @@ -102,3 +101,13 @@ source = [ "src/lazy_loader", "*/site-packages/lazy_loader", ] + +[tool.spin] +package = 'lazy_loader' + +[tool.spin.commands] +Build = [ + 'spin.cmds.pip.install', + '.spin/cmds.py:test', + 'spin.cmds.build.sdist', +] From ecb2325d0e96e092d69f19cc7a2f4450c87ba04f Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Sat, 17 May 2025 10:36:32 -0700 Subject: [PATCH 2/3] Check for editable install before running tests --- .spin/cmds.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/.spin/cmds.py b/.spin/cmds.py index 0745c02..7db4b98 100644 --- a/.spin/cmds.py +++ b/.spin/cmds.py @@ -1,4 +1,6 @@ +import importlib import sys +import textwrap import click from spin.cmds.util import run @@ -14,6 +16,20 @@ ) def test(pytest_args, coverage=False): """🔧 Run tests""" + if not importlib.util.find_spec("lazy_loader"): + click.secho( + textwrap.dedent("""\ + ERROR: The package is not installed. + + Please do an editable install: + + pip install -e .[test] + + prior to running the tests."""), + fg="red", + ) + sys.exit(1) + if coverage: pytest_args = ("--cov=lazy_loader", *pytest_args) run([sys.executable, "-m", "pytest", *list(pytest_args)]) From 8a610fff55faaf8dd765e071284fae3be3706698 Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Sat, 17 May 2025 13:15:22 -0700 Subject: [PATCH 3/3] Use spin in CI pipelines --- .github/workflows/coverage.yml | 6 +++--- .github/workflows/release.yml | 4 ++-- .github/workflows/test.yml | 4 ++-- pyproject.toml | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index da3a31e..e095b5c 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -21,7 +21,7 @@ jobs: - name: Install packages run: | - python -m pip install --upgrade pip wheel setuptools + python -m pip install --upgrade pip wheel setuptools spin python -m pip install ".[test]" python -m pip install --upgrade numpy python -m pip uninstall --yes scipy @@ -29,9 +29,9 @@ jobs: - name: Measure test coverage run: | - python -m pytest --cov=lazy_loader --durations=10 + spin test -c -- --durations=10 # Tests fail if using `--doctest-modules`. I.e., - # python -m pytest --cov=src --durations=10 --doctest-modules + # spin test -- --doctest-modules - name: Upload coverage to Codecov uses: codecov/codecov-action@v5 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c454680..6cf247b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -26,8 +26,8 @@ jobs: - name: Build wheels run: | git clean -fxd - pip install -U build twine wheel - python -m build --sdist --wheel + pip install -U build twine wheel spin + spin sdist -- --wheel - name: Publish package distributions to PyPI uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0785ea8..a299fe7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -25,9 +25,9 @@ jobs: - name: Install dependencies run: | - python -m pip install --upgrade pip + python -m pip install --upgrade pip spin python -m pip install ".[test]" - name: Test run: | - python -m pytest + spin test diff --git a/pyproject.toml b/pyproject.toml index 48a187e..32c1dcf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,7 +26,7 @@ dependencies = [ [project.optional-dependencies] test = ["pytest >= 8.0", "pytest-cov >= 5.0", "coverage[toml] >= 7.2"] lint = ["pre-commit == 4.2.0"] -dev = ["changelist == 0.5"] +dev = ["changelist == 0.5", "spin == 0.14"] [project.urls] Home = "https://scientific-python.org/specs/spec-0001/"