diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml index f4521b32..70f40b5f 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -32,11 +32,11 @@ jobs: with: fetch-depth: 0 - - name: Cache nox + - name: Cache tox uses: actions/cache@v4 with: key: test-${{ hashFiles('pyproject.toml') }} - path: .nox + path: .tox - name: Set up Python uses: actions/setup-python@v5 @@ -45,16 +45,16 @@ jobs: cache: pip python-version: 3.x - - name: Install nox - run: python -m pip install nox + - name: Install tox + run: python -m pip install tox - name: Run examples - run: nox -s examples + run: tox -e examples env: FORCE_COLOR: 1 - name: Generate HTML - run: nox -s examples -- html + run: tox -e examples -- html env: FORCE_COLOR: 1 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f6aef75d..bbc3a576 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -35,11 +35,11 @@ jobs: with: fetch-depth: 0 - - name: Cache nox + - name: Cache tox uses: actions/cache@v4 with: key: test-${{ hashFiles('pyproject.toml') }} - path: .nox + path: .tox - name: Set up Python uses: actions/setup-python@v5 @@ -48,16 +48,19 @@ jobs: cache: pip python-version: ${{ matrix.python-version }} - - name: Install nox and coverage.py - run: python -m pip install coverage[toml] nox + - name: Install tox and coverage.py + run: python -m pip install coverage[toml] tox + + - name: Install ubuntu dependencies for fitsio + run: sudo apt-get install -y libbz2-dev - name: Run doctests - run: nox -s doctests-${{ matrix.python-version }} --verbose + run: tox -e doctests-${{ matrix.python-version }} --verbose env: FORCE_COLOR: 1 - name: Run tests and generate coverage report - run: nox -s coverage-${{ matrix.python-version }} --verbose + run: tox -e coverage-${{ matrix.python-version }} --verbose env: FORCE_COLOR: 1 @@ -98,11 +101,11 @@ jobs: cache: pip python-version: 3.x - - name: Install nox - run: python -m pip install nox + - name: Install tox + run: python -m pip install tox - name: Build SDist and wheel - run: nox -s build --verbose + run: tox -e build --verbose env: FORCE_COLOR: 1 @@ -126,9 +129,9 @@ jobs: run: |- sudo apt-get update sudo apt-get install -y pandoc - python -m pip install nox + python -m pip install tox - name: Build docs - run: nox -s docs --verbose + run: tox -e docs --verbose env: FORCE_COLOR: 1 diff --git a/.gitignore b/.gitignore index 81a7f767..8e8f4322 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ dist coverage* *.html .ipynb_checkpoints +.tox diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index efd3b302..27053f21 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -136,51 +136,51 @@ The current version number is automatically inferred from the last release The target is to have a new _GLASS_ release once there are significant changes to the code's functionality. -## Nox +## Tox `GLASS` supports running various critical commands using -[nox](https://github.com/wntrblm/nox) to make them less intimidating for new -developers. All of these commands (or sessions in the language of `nox`) - +[tox](https://github.com/tox-dev/tox) to make them less intimidating for new +developers. All of these commands (or sessions in the language of `tox`) - `lint`, `tests`, `coverage`, `doctests`, `docs`, and `build` - are defined in -[noxfile.py](https://github.com/glass-dev/glass/main/noxfile.py). +[pyproject.toml](https://github.com/glass-dev/glass/blob/main/pyproject.toml). -`nox` can be installed via `pip` using - +`tox` can be installed via `pip` using - ```bash -pip install nox +pip install tox ``` The default sessions (`lint` and `tests`) can be executed using - ```bash -nox +tox ``` -A particular session (for example `tests`) can be run with `nox` on all +A particular session (for example `tests`) can be run with `tox` on all supported Python versions using - ```bash -nox -s tests +tox -e tests ``` Only `tests`, `coverage`, and the `doctests` session run on all supported Python versions by default. -To specify a particular Python version (for example `3.11`), use the following +To specify a particular Python version (for example `3.13`), use the following syntax - ```bash -nox -s tests-3.11 +tox -e tests-3.13 ``` The following command can be used to deploy the docs on `localhost` - ```bash -nox -s docs -- serve +tox -e docs -- serve ``` -The `nox` environments created for each type of session on the first run is -saved under `.nox/` and reused by default. +The `tox` environments created for each type of session on the first run is +saved under `.tox/` and reused by default. ## Contributing workflow diff --git a/examples/run.py b/examples/run.py new file mode 100644 index 00000000..b2a5a298 --- /dev/null +++ b/examples/run.py @@ -0,0 +1,37 @@ +"""_summary_.""" + +import pathlib +import subprocess +import sys + + +def main() -> None: + """_summary_.""" + if len(sys.argv) > 1 and "html" in sys.argv[1:]: + print("Generating HTML for the example notebooks") + subprocess.run( # noqa: S603 + [ # noqa: S607 + "jupyter", + "nbconvert", + "--to", + "html", + "--embed-images", + "examples/**/*.ipynb", + ], + check=False, + ) + else: + notebooks = [str(p) for p in pathlib.Path().glob("examples/**/*.ipynb")] + subprocess.run( # noqa: S603 + [ # noqa: S607 + "jupyter", + "execute", + "--inplace", + *notebooks, + ], + check=False, + ) + + +if __name__ == "__main__": + main() diff --git a/noxfile.py b/noxfile.py deleted file mode 100644 index 6a45d5c7..00000000 --- a/noxfile.py +++ /dev/null @@ -1,102 +0,0 @@ -"""Nox config.""" - -from __future__ import annotations - -from pathlib import Path - -import nox - -# Options to modify nox behaviour -nox.options.reuse_existing_virtualenvs = True -nox.options.sessions = ["lint", "tests"] - -ALL_PYTHON = [ - "3.10", - "3.11", - "3.12", - "3.13", -] - - -@nox.session -def lint(session: nox.Session) -> None: - """Run the linter.""" - session.install("pre-commit") - session.run("pre-commit", "run", "--all-files", *session.posargs) - - -@nox.session(python=ALL_PYTHON) -def tests(session: nox.Session) -> None: - """Run the unit tests.""" - session.install("-c", ".github/test-constraints.txt", "-e", ".[test]") - session.run( - "pytest", - *session.posargs, - ) - - -@nox.session(python=ALL_PYTHON) -def coverage(session: nox.Session) -> None: - """Run tests and compute coverage.""" - session.posargs.append("--cov") - tests(session) - - -@nox.session(python=ALL_PYTHON) -def doctests(session: nox.Session) -> None: - """Run the doctests.""" - session.posargs.append("--doctest-plus") - session.posargs.append("glass") - tests(session) - - -@nox.session -def examples(session: nox.Session) -> None: - """Run the example notebooks. Pass "html" to build html.""" - session.install("-e", ".[examples]") - - if session.posargs: - if "html" in session.posargs: - print("Generating HTML for the example notebooks") - session.run( - "jupyter", - "nbconvert", - "--to", - "html", - "--embed-images", - "examples/**/*.ipynb", - ) - else: - print("Unsupported argument to examples") - else: - session.run( - "jupyter", - "execute", - "--inplace", - *Path().glob("examples/**/*.ipynb"), - *session.posargs, - ) - - -@nox.session -def docs(session: nox.Session) -> None: - """Build the docs. Pass "serve" to serve.""" - session.install("-e", ".[docs]") - session.chdir("docs") - session.run("sphinx-build", "-M", "html", ".", "_build") - - port = 8001 - - if session.posargs: - if "serve" in session.posargs: - print(f"Launching docs at http://localhost:{port}/ - use Ctrl-C to quit") - session.run("python", "-m", "http.server", f"{port}", "-d", "_build/html") - else: - print("Unsupported argument to docs") - - -@nox.session -def build(session: nox.Session) -> None: - """Build an SDist and wheel.""" - session.install("build") - session.run("python", "-m", "build") diff --git a/pyproject.toml b/pyproject.toml index 3c292882..bb3a3da7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -80,7 +80,7 @@ run = {branch = true, parallel = true, source = [ ]} paths.source = [ "src", - ".nox*/*/lib/python*/site-packages", + ".tox*/*/lib/python*/site-packages", ] [tool.hatch] @@ -89,7 +89,6 @@ build.targets.sdist.exclude = [ ".*", "docs/*", "examples/*", - "noxfile.py", "tests/*", ] version.source = "vcs" @@ -161,12 +160,11 @@ lint.per-file-ignores = {"__init__.py" = [ "D100", # undocumented-public-module "INP001", # implicit-namespace-package, ], "examples*" = [ + "INP001", # implicit-namespace-package "PLR2004", # magic-value-comparison "T201", # print ], "glass*" = [ "PLR2004", # TODO: magic-value-comparison -], "noxfile.py" = [ - "T201", # print ], "tests*" = [ "D100", # undocumented-public-module "D103", # TODO: undocumented-public-function @@ -189,3 +187,56 @@ trailing_comma_inline_array = true overrides."project.classifiers".inline_arrays = false overrides."tool.coverage.paths.source".inline_arrays = false overrides."tool.ruff.lint.isort.section-order".inline_arrays = false + +[tool.tox] +legacy_tox_ini = """ + [tox] + envlist = + lint + {tests,coverage,doctests}-3.{10,11,12,13} + examples + docs + build + requires = + pip>=20.0 + isolated_build = True + + [testenv] + extras = test + constrain_package_deps = + test: .github/test-constraints.txt + + [testenv:lint] + skip_install = True + deps = pre-commit + commands = pre-commit run --all-files {posargs} + + [testenv:tests-3.{10,11,12,13}] + extras = test + commands = pytest {posargs} + + [testenv:coverage-3.{10,11,12,13}] + extras = test + commands = pytest --cov {posargs} + + [testenv:doctests-3.{10,11,12,13}] + extras = test + commands = pytest --doctest-plus glass {posargs} + + [testenv:examples] + extras = examples + commands = python examples/run.py {posargs} + description = Run the example notebooks. Pass "html" to build html. + + [testenv:docs] + extras = docs + change_dir = docs + commands = + sphinx-build -M html . _build + serve: python -m http.server 8001 -d _build/html + + [testenv:build] + skip_install = True + deps = build + commands = python -m build +""" diff --git a/tests/test_points.py b/tests/test_points.py index cd7dced2..fb75f4a3 100644 --- a/tests/test_points.py +++ b/tests/test_points.py @@ -53,12 +53,12 @@ def test_effective_bias(mocker: pytest_mock.MockerFixture) -> None: z = np.linspace(0, 1, 10) bz = np.zeros((10,)) - np.testing.assert_allclose(effective_bias(z, bz, w), np.zeros((10,))) + np.testing.assert_allclose(effective_bias(z, bz, w), np.zeros((1,))) z = np.zeros((10,)) bz = np.full_like(z, 0.5) - np.testing.assert_allclose(effective_bias(z, bz, w), np.zeros((10,))) + np.testing.assert_allclose(effective_bias(z, bz, w), np.zeros((1,))) z = np.linspace(0, 1, 10) bz = np.full_like(z, 0.5)