Public Access
mirror of
https://github.com/xlorepdarkhelm/numinar-coding-project.git
synced 2026-09-11 18:37:36 -04:00
Fixing noxfiles a bit more.
Signed-off-by: Cliff Hill <xlorep@darkhelm.org>
This commit is contained in:
+12
-86
@@ -1,33 +1,23 @@
|
|||||||
"""Nox sessions."""
|
"""Nox sessions for backend tasks.
|
||||||
|
|
||||||
|
Run with `nox -s <session>` from the backend directory.
|
||||||
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import shlex
|
|
||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from textwrap import dedent
|
|
||||||
|
|
||||||
import nox
|
import nox
|
||||||
|
from nox_poetry import Session
|
||||||
|
from nox_poetry import session
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
package = "backend"
|
package = "backend"
|
||||||
python_versions = ["3.13"]
|
python_versions = ["3.13"]
|
||||||
nox.needs_version = ">= 2025.5.1"
|
nox.needs_version = ">= 2025.5.1"
|
||||||
nox.options.sessions = (
|
nox.options.sessions = (
|
||||||
"pre-commit",
|
"precommit",
|
||||||
"safety",
|
"safety",
|
||||||
"mypy",
|
"mypy",
|
||||||
"tests",
|
"tests",
|
||||||
@@ -37,81 +27,17 @@ nox.options.sessions = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def activate_virtualenv_in_precommit_hooks(session: Session) -> None:
|
@session(name="pre-commit", python=python_versions[0])
|
||||||
"""Activate virtualenv in hooks installed by pre-commit.
|
def precommit(session: Session) -> None:
|
||||||
|
"""Run pre-commit checks by delegating to the root noxfile.
|
||||||
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.
|
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
session: The Nox session object.
|
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 <bindir>/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")
|
package = "backend"
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
@session(python=python_versions[0])
|
@session(python=python_versions[0])
|
||||||
|
|||||||
+20
-1
@@ -1,6 +1,6 @@
|
|||||||
"""Nox sessions for frontend tasks.
|
"""Nox sessions for frontend tasks.
|
||||||
|
|
||||||
Run with `nox -s <session>` from the project root or frontend directory.
|
Run with `nox -s <session>` from the frontend directory.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
@@ -9,6 +9,25 @@ from pathlib import Path
|
|||||||
import nox
|
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")
|
@nox.session(name="typecheck")
|
||||||
def typecheck(session: nox.Session) -> None:
|
def typecheck(session: nox.Session) -> None:
|
||||||
"""Run TypeScript type checks.
|
"""Run TypeScript type checks.
|
||||||
|
|||||||
@@ -46,7 +46,6 @@ def precommit(session: Session) -> None:
|
|||||||
|
|
||||||
|
|
||||||
backend_sessions = [
|
backend_sessions = [
|
||||||
"pre-commit",
|
|
||||||
"safety",
|
"safety",
|
||||||
"mypy",
|
"mypy",
|
||||||
"tests",
|
"tests",
|
||||||
|
|||||||
Reference in New Issue
Block a user