Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-475: switch from nox to tox #476

Closed
wants to merge 17 commits into from
12 changes: 6 additions & 6 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
25 changes: 14 additions & 11 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ dist
coverage*
*.html
.ipynb_checkpoints
.tox
28 changes: 14 additions & 14 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
37 changes: 37 additions & 0 deletions examples/run.py
Original file line number Diff line number Diff line change
@@ -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()
102 changes: 0 additions & 102 deletions noxfile.py

This file was deleted.

59 changes: 55 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -89,7 +89,6 @@ build.targets.sdist.exclude = [
".*",
"docs/*",
"examples/*",
"noxfile.py",
"tests/*",
]
version.source = "vcs"
Expand Down Expand Up @@ -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
Expand All @@ -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
"""
Loading
Loading