Skip to content

Commit

Permalink
chore: update cruft
Browse files Browse the repository at this point in the history
  • Loading branch information
wpk-nist-gov committed Feb 7, 2025
1 parent 696d78f commit fbda4d9
Show file tree
Hide file tree
Showing 12 changed files with 408 additions and 323 deletions.
4 changes: 2 additions & 2 deletions .cruft.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"template": "https://github.com/usnistgov/cookiecutter-nist-python.git",
"commit": "8abac57f08c85e44e62cd1bd861c83964e347be4",
"commit": "c65c6beac23fb72be9771e0587961e940ae501ff",
"checkout": "develop",
"context": {
"cookiecutter": {
Expand All @@ -19,7 +19,7 @@
"__answers": "",
"_copy_without_render": [],
"_template": "https://github.com/usnistgov/cookiecutter-nist-python.git",
"_commit": "8abac57f08c85e44e62cd1bd861c83964e347be4"
"_commit": "c65c6beac23fb72be9771e0587961e940ae501ff"
}
},
"directory": null
Expand Down
52 changes: 40 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,19 @@ repos:
types: [toml]
exclude: ^tests/data

# * Pyproject validate
- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.23
hooks:
- id: validate-pyproject

# * Prettier
- repo: https://github.com/rbubley/mirrors-prettier
rev: v3.4.2
hooks:
- id: prettier
alias: markdownlint
stages: [pre-commit]
stages: [pre-commit, manual]

# * Markdown
- repo: https://github.com/DavidAnson/markdownlint-cli2
Expand All @@ -63,7 +69,7 @@ repos:
additional_dependencies:
- black==24.10.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.3
rev: v0.9.5
hooks:
- id: ruff
alias: ruff-all
Expand All @@ -75,7 +81,7 @@ repos:

# * Spelling
- repo: https://github.com/codespell-project/codespell
rev: v2.4.0
rev: v2.4.1
hooks:
- id: codespell
additional_dependencies: [tomli]
Expand All @@ -85,18 +91,18 @@ repos:

# * Commit message
- repo: https://github.com/commitizen-tools/commitizen
rev: v4.1.0
rev: v4.2.0
hooks:
- id: commitizen
stages: [commit-msg]

# * uv
- repo: https://github.com/astral-sh/uv-pre-commit
# uv version.
rev: 0.5.24
rev: 0.5.29
hooks:
- id: uv-lock
alias: lock
args: [--locked]

# * pyproject2conda
- repo: https://github.com/usnistgov/pyproject2conda
Expand All @@ -111,24 +117,46 @@ repos:
- id: requirements-lock
name: requirements-lock
alias: lock
entry: nox -s lock -- ++lock-force
entry: nox -s lock -- # ++lock-force
language: python
files: ^requirements/.*\.txt$
pass_filenames: false
additional_dependencies: ["nox==2024.10.9"]

# * Manual Linting ------------------------------------------------------------
- repo: https://github.com/asottile/pyupgrade
rev: v3.19.1
# - repo: https://github.com/asottile/pyupgrade
# rev: v3.19.1
# hooks:
# - id: pyupgrade
# stages: [manual]
# args: [--py38-plus]
# - repo: https://github.com/nbQA-dev/nbQA
# rev: 1.9.1
# hooks:
# - id: nbqa-pyupgrade
# additional_dependencies: [pyupgrade]
# stages: [manual]
# args: [--py38-plus]

# pyproject-validate (schema-store)
- repo: https://github.com/henryiii/validate-pyproject-schema-store
rev: 2025.02.06
hooks:
- id: validate-pyproject
alias: validate-pyproject-full
stages: [manual]

# * checkmake
- repo: https://github.com/mrtazz/checkmake.git
rev: 0.2.2
hooks:
- id: pyupgrade
- id: checkmake
stages: [manual]
args: [--py38-plus]

# ** typos
# Probably stick with codespell, but this might also be nice...
- repo: https://github.com/crate-ci/typos
rev: dictgen-v0.3.1
rev: typos-dict-v0.12.4
hooks:
- id: typos
stages: [manual]
Expand Down
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# * Utilities -----------------------------------------------------------------
.PHONY: clean clean-test clean-pyc clean-build help
.PHONY: all clean clean-test clean-pyc clean-build help
.DEFAULT_GOAL := help


Expand Down Expand Up @@ -36,6 +36,8 @@ BROWSER := $(UVRUN) --no-config python -c "$$BROWSER_PYSCRIPT"
help:
@$(UVRUN) python -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST)

all: help

clean: clean-build clean-pyc clean-test ## remove all build, test, coverage and Python artifacts

clean-build: ## remove build artifacts
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ and the environments to apply them to. For example, above we specify that the
base option is `False` for envs `test-extras` and `dist-pypi`, and that the
python version should be `3.10` and `3.11` for envs `test` and `test-extras`.
Note that each "overrides" table must specify the options to be overridden, and
the environments that these overrides apply to. Also, note that subsequenct
the environments that these overrides apply to. Also, note that subsequent
overrides override previous overrides/options (last option wins).

So in all, options are picked up, in order, from the overrides list, then the
Expand All @@ -902,7 +902,7 @@ name = "hello"
<!-- [[[end]]] -->
<!-- prettier-ignore-end -->

Note that the full path of this file is note that the path of the `user_conifg`
Note that the full path of this file is note that the path of the `user_config`
file is relative to them`pyproject.toml` file. So, if the `pyproject.toml` file
is at `a/path/pyproject.toml`, the path of user configuration files will be
`a/path/config/userconfig.toml`. We then can run the following:
Expand Down
8 changes: 6 additions & 2 deletions docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ALLSPHINXAUTOOPTS = $(ALLSPHINXOPTS) \



.PHONY: help Makefile clean-all build livehtml showlinks release command
.PHONY: help Makefile clean-all build livehtml showlinks release command all clean test
# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(ALLSPHINXOPTS) $(O)
Expand All @@ -29,14 +29,18 @@ help:
%: Makefile
$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(ALLSPHINXOPTS) $(O)

clean-all: clean
clean: clean
rm -rf $(BUILDDIR)/*
rm -rf generated/*
rm -rf reference/generated/*

# Alias to html
build: html

all: clean html

test: html

livehtml:
$(SPHINXAUTOBUILD) "$(SOURCEDIR)" "$(BUILDDIR)/html" $(ALLSPHINXAUTOOPTS) $(O)

Expand Down
50 changes: 33 additions & 17 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ class SessionParams(DataclassParser):

# test
test_no_pytest: bool = False
test_opts: OPT_TYPE = add_option(help="Options to pytest")
test_options: OPT_TYPE = add_option(
"--test-options", "-t", help="Options to pytest"
)
test_run: RUN_ANNO = None
no_cov: bool = False

Expand Down Expand Up @@ -197,6 +199,9 @@ class SessionParams(DataclassParser):
) = add_option("--docs", "-d", help="doc commands")
docs_run: RUN_ANNO = None

# lint
lint_options: OPT_TYPE = add_option(help="Options to pre-commit")

# typing
typing: list[
Literal[
Expand All @@ -220,8 +225,8 @@ class SessionParams(DataclassParser):
build: list[Literal["build", "version"]] | None = None
build_run: RUN_ANNO = None
build_isolation: bool = False
build_outdir: str = "./dist"
build_opts: OPT_ANNO = None
build_out_dir: str = "./dist"
build_options: OPT_ANNO = None
build_silent: bool = False

# publish
Expand Down Expand Up @@ -449,9 +454,10 @@ def requirements(
"pre-commit",
"run",
"pyproject2conda-project",
"--all-files", # "--show-diff-on-failure",
"--all-files",
specs=get_uvxrun_specs(),
session=session,
success_codes=[0, 1],
)

if not opts.requirements_no_notify:
Expand Down Expand Up @@ -518,7 +524,7 @@ def _test(
session: nox.Session,
run: RUN_TYPE,
test_no_pytest: bool,
test_opts: OPT_TYPE,
test_options: OPT_TYPE,
no_cov: bool,
) -> None:
import os
Expand All @@ -527,7 +533,7 @@ def _test(

session_run_commands(session, run)
if not test_no_pytest:
opts = combine_list_str(test_opts or [])
opts = combine_list_str(test_options or [])
if not no_cov:
session.env["COVERAGE_FILE"] = str(Path(session.create_tmp()) / ".coverage")

Expand Down Expand Up @@ -558,7 +564,7 @@ def test(
session=session,
run=opts.test_run,
test_no_pytest=opts.test_no_pytest,
test_opts=opts.test_opts,
test_options=opts.test_options,
no_cov=opts.no_cov,
)

Expand All @@ -583,19 +589,19 @@ def test_notebook(session: nox.Session, opts: SessionParams) -> None:
""",
)

test_opts = (
(opts.test_opts or [])
test_options = (
(opts.test_options or [])
+ test_nbval_opts
+ [str(p) for p in Path("examples/usage").glob("*.ipynb")]
)

session.log(f"{test_opts = }")
session.log(f"{test_options = }")

_test(
session=session,
run=opts.test_run,
test_no_pytest=opts.test_no_pytest,
test_opts=test_opts,
test_options=test_options,
no_cov=opts.no_cov,
)

Expand Down Expand Up @@ -660,7 +666,7 @@ def testdist(
session=session,
run=opts.testdist_run,
test_no_pytest=opts.test_no_pytest,
test_opts=opts.test_opts,
test_options=opts.test_options,
no_cov=opts.no_cov,
)

Expand All @@ -672,7 +678,7 @@ def testdist(
# # ** Docs
@nox.session(name="docs", **DEFAULT_KWS)
@add_opts
def docs( # noqa: C901
def docs( # noqa: C901, PLR0912
session: nox.Session,
opts: SessionParams,
) -> None:
Expand Down Expand Up @@ -730,6 +736,13 @@ def docs( # noqa: C901
)
),
)
elif c == "showlinks":
session.run(
"python",
"-m",
"sphinx.ext.intersphinx",
"docs/_build/html/objects.inv",
)
else:
session.run(
"sphinx-build", "-b", c, *common_opts, "docs", f"docs/_build/{c}"
Expand All @@ -753,8 +766,10 @@ def docs( # noqa: C901

# ** lint
@nox.session(python=False)
@add_opts
def lint(
session: nox.Session,
opts: SessionParams,
) -> None:
"""
Run linters with pre-commit.
Expand All @@ -767,6 +782,7 @@ def lint(
"pre-commit",
"run",
"--all-files", # "--show-diff-on-failure",
*(opts.lint_options or []),
specs=get_uvxrun_specs(),
session=session,
)
Expand Down Expand Up @@ -874,15 +890,15 @@ def build(session: nox.Session, opts: SessionParams) -> None: # noqa: C901
"uvx", "--with", "hatch-vcs", "hatchling", "version", external=True
)
elif cmd == "build":
outdir = opts.build_outdir
outdir = opts.build_out_dir
shutil.rmtree(outdir, ignore_errors=True)

args = f"uv build --out-dir={outdir}".split()
if USE_ENVIRONMENT_FOR_BUILD and not opts.build_isolation:
args.append("--no-build-isolation")

if opts.build_opts:
args.extend(opts.build_opts)
if opts.build_options:
args.extend(opts.build_options)

out = session.run(*args, silent=opts.build_silent)
if opts.build_silent:
Expand Down Expand Up @@ -912,7 +928,7 @@ def get_package_wheel(
if reuse and getattr(get_package_wheel, "_called", False):
session.log("Reuse isolated build")
else:
cmd = f"nox -s build -- ++build-outdir {dist_location} ++build-opts --wheel ++build-silent"
cmd = f"nox -s build -- ++build-out-dir {dist_location} ++build-options --wheel ++build-silent"
session.run_always(*shlex.split(cmd), external=True)

# save that this was called:
Expand Down
Loading

0 comments on commit fbda4d9

Please sign in to comment.