From 60ef61c3e16a5c0d79bbcdc3c5fe8a7111ecfc4e Mon Sep 17 00:00:00 2001 From: Cliff Hill Date: Sun, 21 Sep 2025 07:07:56 -0400 Subject: [PATCH] Fixing noxfiles a bit more. Signed-off-by: Cliff Hill --- backend/noxfile.py | 98 ++++++--------------------------------------- frontend/noxfile.py | 21 +++++++++- noxfile.py | 1 - 3 files changed, 32 insertions(+), 88 deletions(-) diff --git a/backend/noxfile.py b/backend/noxfile.py index 1178499e..8ebd083b 100644 --- a/backend/noxfile.py +++ b/backend/noxfile.py @@ -1,33 +1,23 @@ -"""Nox sessions.""" +"""Nox sessions for backend tasks. + +Run with `nox -s ` from the backend directory. +""" import os -import shlex import shutil import sys from pathlib import Path -from textwrap import dedent import nox - - -try: - from nox_poetry import Session - from nox_poetry import session -except ImportError: - message = f"""\ - Nox failed to import the 'nox-poetry' package. - - Please install it using the following command: - - {sys.executable} -m pip install nox-poetry""" - raise SystemExit(dedent(message)) from None +from nox_poetry import Session +from nox_poetry import session package = "backend" python_versions = ["3.13"] nox.needs_version = ">= 2025.5.1" nox.options.sessions = ( - "pre-commit", + "precommit", "safety", "mypy", "tests", @@ -37,81 +27,17 @@ nox.options.sessions = ( ) -def activate_virtualenv_in_precommit_hooks(session: Session) -> None: - """Activate virtualenv in hooks installed by pre-commit. - - This function patches git hooks installed by pre-commit to activate the - session's virtual environment. This allows pre-commit to locate hooks in - that environment when invoked from git. +@session(name="pre-commit", python=python_versions[0]) +def precommit(session: Session) -> None: + """Run pre-commit checks by delegating to the root noxfile. Args: session: The Nox session object. - - Returns: - None, as the function modifies hooks in place or exits early. """ - assert session.bin is not None # noqa: S101 + session.run("nox", "-f", "../noxfile.py", "-s", "pre-commit", external=True) - # Only patch hooks containing a reference to this session's bindir. Support - # quoting rules for Python and bash, but strip the outermost quotes so we - # can detect paths within the bindir, like /python. - bindirs = [ - bindir[1:-1] if bindir[0] in "'\"" else bindir - for bindir in (repr(session.bin), shlex.quote(session.bin)) - ] - virtualenv = session.env.get("VIRTUAL_ENV") - if virtualenv is None: - return - - headers = { - # pre-commit < 2.16.0 - "python": f"""\ - import os - os.environ["VIRTUAL_ENV"] = {virtualenv!r} - os.environ["PATH"] = os.pathsep.join(( - {session.bin!r}, - os.environ.get("PATH", ""), - )) - """, - # pre-commit >= 2.16.0 - "bash": f"""\ - VIRTUAL_ENV={shlex.quote(virtualenv)} - PATH={shlex.quote(session.bin)}"{os.pathsep}$PATH" - """, - # pre-commit >= 2.17.0 on Windows forces sh shebang - "/bin/sh": f"""\ - VIRTUAL_ENV={shlex.quote(virtualenv)} - PATH={shlex.quote(session.bin)}"{os.pathsep}$PATH" - """, - } - - hookdir = Path(".git") / "hooks" - if not hookdir.is_dir(): - return - - for hook in hookdir.iterdir(): - if hook.name.endswith(".sample") or not hook.is_file(): - continue - - if not hook.read_bytes().startswith(b"#!"): - continue - - text = hook.read_text() - - if not any( - Path("A") == Path("a") and bindir.lower() in text.lower() or bindir in text - for bindir in bindirs - ): - continue - - lines = text.splitlines() - - for executable, header in headers.items(): - if executable in lines[0].lower(): - lines.insert(1, dedent(header)) - hook.write_text("\n".join(lines)) - break +package = "backend" @session(python=python_versions[0]) diff --git a/frontend/noxfile.py b/frontend/noxfile.py index f09f6b9e..a102cf36 100644 --- a/frontend/noxfile.py +++ b/frontend/noxfile.py @@ -1,6 +1,6 @@ """Nox sessions for frontend tasks. -Run with `nox -s ` from the project root or frontend directory. +Run with `nox -s ` from the frontend directory. """ import os @@ -9,6 +9,25 @@ from pathlib import Path import nox +nox.options.sessions = ( + "precommit", + "coverage", + "audit", + "storybook", + "jest", +) + + +@nox.session(name="pre-commit") +def precommit(session: nox.Session) -> None: + """Run pre-commit checks by delegating to the root noxfile. + + Args: + session: The Nox session object. + """ + session.run("nox", "-f", "../noxfile.py", "-s", "pre-commit", external=True) + + @nox.session(name="typecheck") def typecheck(session: nox.Session) -> None: """Run TypeScript type checks. diff --git a/noxfile.py b/noxfile.py index f0ffd506..86a243eb 100644 --- a/noxfile.py +++ b/noxfile.py @@ -46,7 +46,6 @@ def precommit(session: Session) -> None: backend_sessions = [ - "pre-commit", "safety", "mypy", "tests",