From 135903723bc0bd44b1e1344fe2c74f0b49a4f63a Mon Sep 17 00:00:00 2001 From: Giordon Stark Date: Wed, 30 Nov 2022 06:11:25 +0100 Subject: [PATCH] feat: Use hatch envs instead of nox (#40) * migrate docs environment from nox to hatch * migrate lint from nox to hatch * use pipx run since hatch isn't there * drop post-install, since that's for post-install project, not env * typo * drop dev * remove strictness for now * drop allow-direct-references * drop noxfile entirely * use pre-commit github action * drop pre-commit from pyproject * minor changes * add twine dep --- .flake8 | 1 - .github/CONTRIBUTING.md | 41 +++++++------- .github/workflows/ci.yml | 16 ++---- .github/workflows/docs.yml | 13 ++--- noxfile.py | 82 ---------------------------- pyproject.toml | 109 ++++++++++++++++++++++++------------- 6 files changed, 102 insertions(+), 160 deletions(-) delete mode 100644 noxfile.py diff --git a/.flake8 b/.flake8 index bc8020ea..8e8325fd 100644 --- a/.flake8 +++ b/.flake8 @@ -3,6 +3,5 @@ extend-ignore = E203, E501, E722, B950, W503 select = C,E,F,W,T,B,B9,I per-file-ignores = tests/*: T - noxfile.py: T scripts/*: T20 src/mapyde/cli/*: B008 diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 03ac123e..b4c0a694 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -5,25 +5,26 @@ description of best practices for developing Scikit-HEP packages. # Quick development -The fastest way to start with development is to use nox. If you don't have nox, -you can use `pipx run nox` to run it without installing, or `pipx install nox`. -If you don't have pipx (pip for applications), then you can install with with -`pip install pipx` (the only case were installing an application with regular -pip is reasonable). If you use macOS, then pipx and nox are both in brew, use -`brew install pipx nox`. - -To use, run `nox`. This will lint and test using every installed version of -Python on your system, skipping ones that are not installed. You can also run +The fastest way to start with development is to use pipx and hatch. If you don't +have pipx, you can use `pipx run hatch` to run it without installing, or +`pipx install hatch`. If you don't have pipx (pip for applications), then you +can install with with `pip install pipx` (the only case were installing an +application with regular pip is reasonable). If you use macOS, then pipx and +hatch are both in brew, use `brew install pipx hatch`. + +To use, run `hatch run dev:test`. This will test using every installed version +of Python on your system, skipping ones that are not installed. You can also run specific jobs: ```console -$ nox -s lint # Lint only -$ nox -s tests-3.9 # Python 3.9 tests only -$ nox -s docs -- serve # Build and serve the docs -$ nox -s build # Make an SDist and wheel +$ hatch run lint # Lint only +$ hatch run +py=3.9 dev:test # Python 3.9 tests only +$ hatch run dev:py3.9:test # Python 3.9 tests only +$ hatch run docs:serve # Build and serve the docs +$ hatch run build # Make an SDist and wheel ``` -Nox handles everything for you, including setting up an temporary virtual +hatch handles everything for you, including setting up an temporary virtual environment for each run. # Setting up a development environment manually @@ -60,10 +61,10 @@ You can also/alternatively run `pre-commit run` (changes only) or # Testing -Use pytest to run the unit checks: +Use pytest to run the unit checks (via `hatch`): ```bash -pytest +hatch run dev:test ``` # Building docs @@ -71,20 +72,20 @@ pytest You can build the docs using: ```bash -nox -s docs +hatch run docs:build ``` You can see a preview with: ```bash -nox -s docs -- serve +hatch run docs:serve ``` # Pre-commit This project uses pre-commit for all style checking. While you can run it with -nox, this is such an important tool that it deserves to be installed on its own. -Install pre-commit and run: +hatch, this is such an important tool that it deserves to be installed on its +own. Install pre-commit and run: ```bash pre-commit run -a diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f69fe589..37502a0c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,7 +33,7 @@ jobs: - name: Run PyLint run: | echo "::add-matcher::$GITHUB_WORKSPACE/.github/matchers/pylint.json" - pipx run nox -s pylint + pipx run hatch run lint checks: name: Check Python ${{ matrix.python-version }} on ${{ matrix.runs-on }} @@ -46,7 +46,7 @@ jobs: runs-on: [ubuntu-latest, macos-latest, windows-latest] include: - - python-version: pypy-3.8 + - python-version: pypy3.8 runs-on: ubuntu-latest steps: @@ -58,11 +58,8 @@ jobs: with: python-version: ${{ matrix.python-version }} - - name: Install package - run: python -m pip install .[test] - - name: Test package - run: python -m pytest -ra + run: pipx run hatch run +py=${{ matrix.python-version}} dev:test dist: name: Distribution build @@ -74,16 +71,13 @@ jobs: with: fetch-depth: 0 - - name: Build sdist and wheel - run: pipx run build + - name: Build sdist and wheel; and check products + run: pipx run hatch run build-check - uses: actions/upload-artifact@v3 with: path: dist - - name: Check products - run: pipx run twine check dist/* - - uses: pypa/gh-action-pypi-publish@v1.5.1 if: github.event_name == 'release' && github.event.action == 'published' with: diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 7e7283e2..8d801652 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -26,11 +26,8 @@ jobs: with: python-version: "3.x" - - name: Build Docs - run: pipx run nox -s docs - - name: Check documentation - run: pipx run linkchecker --config .linkcheckerrc site + run: pipx run hatch run docs:build-check publish: runs-on: ubuntu-latest @@ -52,8 +49,7 @@ jobs: if: github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository == 'scipp-atlas/mario-mapyde' - run: | - pipx run nox -s mike -- --push dev + run: pipx run hatch run docs:deploy dev - name: Get MAJOR.MINOR version if: github.event_name == 'release' && github.event.action == 'published' @@ -65,5 +61,6 @@ jobs: - name: Deploy documentation (${{ steps.label.outputs.version }}) with mike 🚀 if: github.event_name == 'release' && github.event.action == 'published' - run: | - pipx run nox -s mike -- --push --update-aliases ${{ steps.label.outputs.version }} latest + run: + pipx run hatch run docs:deploy ${{ steps.label.outputs.version }} + latest diff --git a/noxfile.py b/noxfile.py deleted file mode 100644 index 9a9c1f54..00000000 --- a/noxfile.py +++ /dev/null @@ -1,82 +0,0 @@ -from __future__ import annotations - -import shutil -from pathlib import Path - -import nox - -DIR = Path(__file__).parent.resolve() - -nox.options.sessions = ["lint", "pylint", "tests"] - - -@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 -def pylint(session: nox.Session) -> None: - """ - Run PyLint. - """ - # This needs to be installed into the package environment, and is slower - # than a pre-commit check - session.install(".", "pylint") - session.run("pylint", "src", *session.posargs) - - -@nox.session -def tests(session: nox.Session) -> None: - """ - Run the unit and regular tests. - """ - session.install(".[test]") - session.run("pytest", *session.posargs) - - -@nox.session -def docs(session: nox.Session) -> None: - """ - Build the docs. Pass "serve" to serve. - """ - - session.install(".[docs]") - session.run("mkdocs", "build") - - if session.posargs: - if "serve" in session.posargs: - print("Launching docs at http://localhost:8000/ - use Ctrl-C to quit") - session.run("python", "-m", "http.server", "8000", "-d", "site") - else: - session.warn("Unsupported argument to docs") - - -@nox.session -def mike(session: nox.Session) -> None: - """ - Build and deploy docs using mike. - """ - - session.install(".[docs]") - - args = session.posargs or ["dev"] - session.run("mike", "deploy", "--branch", "gh-pages", *args) - - -@nox.session -def build(session: nox.Session) -> None: - """ - Build an SDist and wheel. - """ - - build_p = DIR.joinpath("build") - if build_p.exists(): - shutil.rmtree(build_p) - - session.install("build") - session.run("python", "-m", "build") diff --git a/pyproject.toml b/pyproject.toml index f4d288f3..3382340f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,39 +43,6 @@ dependencies = [ "importlib_resources>=1.3.0; python_version<'3.9'", # for resources in schema ] -[project.optional-dependencies] -test = [ - "pytest >=6", -] -dev = [ - "pytest >=6", - "tbump>=6.7.0" -] -docs = [ - "mkdocs>=1.4.0", - "mkdocs-material>=8.5.6", - # Plugins - "mkdocs-minify-plugin>=0.5.0", - "mkdocs-git-revision-date-localized-plugin>=1.1.0", - "mkdocstrings[python]>=0.18", - "mkdocs-redirects>=1.1.0", - "mkdocs-glightbox>=0.3.0", - # https://github.com/jimporter/mike/issues/82#issuecomment-1172913929 - "mike @ https://github.com/jimporter/mike/archive/392d57b8bb9d14bcedf2451a0dc302709f8055eb.zip", - # Extensions - "mkdocs-click>=0.8.0", - "pymdown-extensions>=9.7.0", - # Necessary for syntax highlighting in code blocks - "pygments>=2.13.0", - # Validation - # https://github.com/linkchecker/linkchecker/pull/669#issuecomment-1267236287 - "linkchecker @ git+https://github.com/linkchecker/linkchecker.git@d9265bb71c2054bf57b8c5734a4825d62505c779", - # auto-generation of docs - "mkdocs-gen-files>=0.4", - "mkdocs-literate-nav>=0.5.0", - "mkdocs-section-index>=0.3.4", -] - # see https://github.com/pypi/warehouse/blob/main/warehouse/templates/packaging/detail.html [project.urls] Homepage = "https://scipp-atlas.github.io/mario-mapyde/latest/" @@ -95,16 +62,12 @@ local_scheme = "no-local-version" [tool.hatch.build.hooks.vcs] version-file = "src/mapyde/_version.py" -[tool.hatch.metadata] -allow-direct-references = true - [tool.hatch.build] exclude = [ "/ci", "/Dockerfiles", "/stats/", "/test/", - "/noxfile.py", "/.*", "/*.sh", "/*.toml", # note: does not remove pyproject.toml @@ -120,9 +83,79 @@ exclude = [ [tool.hatch.envs.default] dependencies = [ - "pytest", + "tbump>=6.7.0", + "pylint", + "build", + "twine", +] + +[tool.hatch.envs.default.scripts] +tag = "tbump {args}" +lint = "pylint src" +build = "python -m build" +validate = "twine check dist/*" +# https://github.com/linkchecker/linkchecker/issues/678 +build-check = [ + "build", + "validate", +] + +[tool.hatch.envs.dev] +template = "dev" +# pylint and pytest needs to be installed into package environment +detached = false +dependencies = [ + "pytest >=6", ] +[tool.hatch.envs.dev.scripts] +test = "pytest -ra" + +[[tool.hatch.envs.dev.matrix]] +python = ["3.7", "3.8", "3.9", "3.10", "3.11", "pypy3.8"] + +[tool.hatch.envs.docs] +template = "docs" +dependencies = [ + "mkdocs>=1.4.0", + "mkdocs-material>=8.5.6", + # Plugins + "mkdocs-minify-plugin>=0.5.0", + "mkdocs-git-revision-date-localized-plugin>=1.1.0", + "mkdocstrings[python]>=0.18", + "mkdocs-redirects>=1.1.0", + "mkdocs-glightbox>=0.3.0", + # https://github.com/jimporter/mike/issues/82#issuecomment-1172913929 + "mike @ https://github.com/jimporter/mike/archive/392d57b8bb9d14bcedf2451a0dc302709f8055eb.zip", + # Extensions + "mkdocs-click>=0.8.0", + "pymdown-extensions>=9.7.0", + # Necessary for syntax highlighting in code blocks + "pygments>=2.13.0", + # Validation + # https://github.com/linkchecker/linkchecker/pull/669#issuecomment-1267236287 + "linkchecker @ git+https://github.com/linkchecker/linkchecker.git@d9265bb71c2054bf57b8c5734a4825d62505c779", + # auto-generation of docs + "mkdocs-gen-files>=0.4", + "mkdocs-literate-nav>=0.5.0", + "mkdocs-section-index>=0.3.4", +] +[tool.hatch.envs.docs.env-vars] +MKDOCS_CONFIG = "mkdocs.yml" +MKDOCS_BRANCH = "gh-pages" +[tool.hatch.envs.docs.scripts] +# --strict disabled for now, see https://github.com/timvink/mkdocs-git-revision-date-localized-plugin/issues/101 +build = "mkdocs build --config-file {env:MKDOCS_CONFIG} --clean {args}" +#build = "mkdocs build --config-file {env:MKDOCS_CONFIG} --clean --strict {args}" +serve = "mkdocs serve --config-file {env:MKDOCS_CONFIG} --dev-addr localhost:8000 {args}" +ci-build = "mike deploy --config-file {env:MKDOCS_CONFIG} --branch {env:MKDOCS_BRANCH} --update-aliases {args}" +deploy = "ci-build --push" +validate = "linkchecker --config .linkcheckerrc site" +# https://github.com/linkchecker/linkchecker/issues/678 +build-check = [ + "build --no-directory-urls", + "validate", +] [tool.pytest.ini_options] minversion = "6.0"