-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Add nox for project automation. Closes #6
- Loading branch information
Showing
7 changed files
with
178 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
import os | ||
from pathlib import Path | ||
|
||
import nox | ||
|
||
nox.options.sessions = ["pre_commit", "tests", "docs"] | ||
nox.options.reuse_existing_virtualenvs = True | ||
nox.options.error_on_external_run = True | ||
|
||
ALL_PYTHON_VERSIONS = [ | ||
# [[[cog | ||
# import re | ||
# for line in open("pyproject.toml"): | ||
# if (match := re.search(r"Programming Language :: Python :: (?P<version>3\.\d+)", line)) is not None: | ||
# cog.outl(f'"{match.group("version")}",') | ||
# ]]] | ||
"3.8", | ||
"3.9", | ||
"3.10", | ||
"3.11", | ||
"3.12", | ||
# [[[end]]] | ||
] | ||
|
||
# [[[cog | ||
# import yaml | ||
# rtd = yaml.safe_load(open(".readthedocs.yaml")) | ||
# cog.outl(f'DOCS_PYTHON_VERSION = "{rtd["build"]["tools"]["python"]}"') | ||
# ]]] | ||
DOCS_PYTHON_VERSION = "3.11" | ||
# [[[end]]] | ||
|
||
VENV_DIR = Path(".venv").resolve() | ||
|
||
|
||
@nox.session | ||
def dev(session: nox.Session) -> None: | ||
"""Sets up a Python development environment for the project.""" | ||
# install `virtualenv` CLI tool into nox's "dev" virtual environment (venv) | ||
session.install("virtualenv") | ||
|
||
# initialize development environment (venv) | ||
session.run( | ||
"virtualenv", | ||
"--prompt", | ||
"{{cookiecutter.project_name}}", | ||
str(VENV_DIR), | ||
silent=True, | ||
) | ||
|
||
# determine venv executable | ||
if os.name == "posix": | ||
venv_executable = VENV_DIR / "bin" / "python" | ||
else: | ||
venv_executable = VENV_DIR / "Scripts" / "python.exe" | ||
|
||
# upgrade pip, setuptools and wheel | ||
session.run( | ||
str(venv_executable), | ||
"-m", | ||
"pip", | ||
"install", | ||
"--upgrade", | ||
"pip", | ||
"setuptools", | ||
"wheel", | ||
external=True, | ||
silent=True, | ||
) | ||
|
||
# install the current package in editable mode (along with its dependencies) | ||
session.run( | ||
str(venv_executable), | ||
"-m", | ||
"pip", | ||
"install", | ||
"--editable", | ||
".[dev]", | ||
external=True, | ||
silent=True, | ||
) | ||
|
||
|
||
@nox.session | ||
def cog(session: nox.Session) -> None: | ||
"""Run cog.""" | ||
session.install("cogapp", "PyYAML") | ||
session.run("cog", *session.posargs, "-r", "noxfile.py") | ||
|
||
|
||
@nox.session | ||
def pre_commit(session: nox.Session) -> None: | ||
"""Run pre-commit hooks.""" | ||
session.install("pre-commit") | ||
session.run("pre-commit", "run", "--all-files") | ||
|
||
|
||
@nox.session(python=ALL_PYTHON_VERSIONS, tags=["tests"]) | ||
def tests(session: nox.Session) -> None: | ||
"""Run tests.""" | ||
session.install(".[tests]") | ||
session.run("pytest", *session.posargs) | ||
|
||
|
||
@nox.session(python=DOCS_PYTHON_VERSION) | ||
def docs(session: nox.Session) -> None: | ||
"""Builds and tests the docs.""" | ||
session.install(".[docs]") | ||
|
||
# create a temporary directory to store the doctrees | ||
tmp_dir = session.create_tmp() | ||
|
||
for builder in ["html", "doctest"]: | ||
# fmt: off | ||
session.run( | ||
"python", "-m", "sphinx", | ||
"-T", # display full traceback when an exception occurs | ||
"-E", # rebuild the environment | ||
"-W", "--keep-going", # turn warnings into errors, but continue to the end of the build | ||
"-b", builder, # selects a builder | ||
"-d", str(Path(tmp_dir) / "doctrees"), # directory to save doctree pickles | ||
"-D", "language=en", # set language | ||
"docs", # source directory | ||
str(Path("docs") / "_build" / "html"), # output directory | ||
) | ||
# fmt: on | ||
session.run("python", "-m", "doctest", "README.md") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8a78706
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Demo: https://github.com/sgraaf/cookiecutter-python-package-demo/tree/6e53b6f