Skip to content

Commit

Permalink
noxfile: add make session
Browse files Browse the repository at this point in the history
I know calling make via nox is a bit weird, but I think allowing to run
the Makefile in an isolated environment without having to manually
manage venvs and making it easy to choose between relaxed and stable
dependencies is quite useful.

We should eventually move away from the Makefile, but I think some level
of integration is better than nothing.
Translating the Makefile syntax and constructs into nox's Python syntax
and untangling all of the different Python scripts that pre process the
documentation is a longer term project.
  • Loading branch information
gotmax23 committed Oct 25, 2023
1 parent e27e273 commit 5c252bf
Showing 1 changed file with 38 additions and 5 deletions.
43 changes: 38 additions & 5 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from argparse import ArgumentParser, BooleanOptionalAction
from glob import iglob
from pathlib import Path
from typing import cast

import nox

Expand Down Expand Up @@ -121,11 +122,9 @@ def clone_core(session: nox.Session):
]


@nox.session
@nox.parametrize(["test"], checker_tests, checker_tests)
def checkers(session: nox.Session, test: str):
def _relaxed_parser(session: nox.Session) -> ArgumentParser:
"""
Run docs build checkers
Generate an argument parser with a --relaxed option.
"""
parser = ArgumentParser(prog=f"nox -e {session.name} --")
parser.add_argument(
Expand All @@ -134,8 +133,42 @@ def checkers(session: nox.Session, test: str):
action=BooleanOptionalAction,
help="Whether to use requirements-relaxed file. (Default: %(default)s)",
)
args = parser.parse_args(session.posargs)
return parser


def _env_python(session: nox.Session) -> str:
"""
Get the full path to an environment's python executable
"""
out = cast(
str,
session.run("python", "-c", "import sys; print(sys.executable)", silent=True),
)
return out.strip()


@nox.session
@nox.parametrize(["test"], checker_tests, checker_tests)
def checkers(session: nox.Session, test: str):
"""
Run docs build checkers
"""
args = _relaxed_parser(session).parse_args(session.posargs)

install(session, req="requirements-relaxed" if args.relaxed else "requirements")
session.run("make", "-C", "docs/docsite", "clean", external=True)
session.run("python", "tests/checkers.py", test)


@nox.session
def make(session: nox.Session):
"""
Run the docs build Makefile in an isolated environment
"""
parser = _relaxed_parser(session)
parser.add_argument("make_args", nargs="*", help="Arguments to pass on to make")
args = parser.parse_args(session.posargs)

install(session, req="requirements-relaxed" if args.relaxed else "requirements")
make_args: list[str] = [f"PYTHON={_env_python(session)}"] + args.make_args
session.run("make", "-C", "docs/docsite", *make_args, external=True)

0 comments on commit 5c252bf

Please sign in to comment.