Skip to content

Commit

Permalink
feat: Use hatch envs instead of nox (#40)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
kratsg committed Nov 30, 2022
1 parent febfb3d commit 1359037
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 160 deletions.
1 change: 0 additions & 1 deletion .flake8
Expand Up @@ -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
41 changes: 21 additions & 20 deletions .github/CONTRIBUTING.md
Expand Up @@ -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
Expand Down Expand Up @@ -60,31 +61,31 @@ 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

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
Expand Down
16 changes: 5 additions & 11 deletions .github/workflows/ci.yml
Expand Up @@ -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 }}
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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:
Expand Down
13 changes: 5 additions & 8 deletions .github/workflows/docs.yml
Expand Up @@ -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
Expand All @@ -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'
Expand All @@ -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
82 changes: 0 additions & 82 deletions noxfile.py

This file was deleted.

109 changes: 71 additions & 38 deletions pyproject.toml
Expand Up @@ -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/"
Expand All @@ -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
Expand All @@ -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"
Expand Down

0 comments on commit 1359037

Please sign in to comment.