"""Root noxfile for orchestrating backend and frontend tasks. Run with `nox -s ` from the project root. """ import os import nox from nox_poetry import Session python_versions = ["3.13"] @nox.session(name="pre-commit", python=python_versions[0]) def precommit(session: Session) -> None: """Lint using pre-commit for the whole project. Args: session: The Nox session object. """ args = session.posargs or [ "run", "--all-files", "--hook-stage=manual", "--show-diff-on-failure", ] session.install( "black", "darglint", "flake8", "flake8-bandit", "flake8-bugbear", "flake8-docstrings", "flake8-rst-docstrings", "isort", "pep8-naming", "pre-commit", "pre-commit-hooks", "pyupgrade", ) session.run("pre-commit", *args) # Run frontend lint using yarn lint os.chdir("frontend") session.run("yarn", "lint", external=True) backend_sessions = [ "safety", "mypy", "tests", "coverage", "typeguard", "xdoctest", "docs-build", "docs", ] frontend_sessions = [ "jest", "typecheck", "coverage", "audit", "storybook", ] def _delegate(session: nox.Session, subdir: str, session_name: str) -> None: # type: ignore """Delegate session execution to a subdirectory noxfile. Args: session: The Nox session object. subdir: Subdirectory containing the noxfile. session_name: Name of the session to run. """ session.run( "nox", "-f", f"{subdir}/noxfile.py", "-s", session_name, *session.posargs, external=True, ) for name in backend_sessions: func_name = name.replace("-", "_") exec( f''' @nox.session(name={name!r}) def {func_name}_delegator(session: nox.Session) -> None: """Delegates to backend/{name} session. Args: session: The Nox session object. """ _delegate(session, 'backend', {name!r}) ''' ) for name in frontend_sessions: func_name = name.replace("-", "_") exec( f''' @nox.session(name={name!r}) def {func_name}_delegator(session: nox.Session) -> None: """Delegates to frontend/{name} session. Args: session: The Nox session object. """ _delegate(session, 'frontend', {name!r}) ''' )