-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathnoxfile.py
More file actions
113 lines (82 loc) · 2.98 KB
/
noxfile.py
File metadata and controls
113 lines (82 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
from __future__ import annotations
from typing import Any
import nox
from pydantic_settings import BaseSettings
class CLIArgs(
BaseSettings,
cli_parse_args=True,
cli_ignore_unknown_args=True,
):
"""CLIArgs is a class that extends BaseSettings to handle command line arguments."""
cov_report: str = ""
junitxml: str = ""
ruff: bool = False
sqlfluff: bool = False
ty: bool = False
@classmethod
def parse(cls, posargs: list[str]) -> CLIArgs:
"""Parse command line arguments from the provided list.
Args:
posargs (list[str]): List of positional arguments from the command line.
Returns:
CLIArgs: An instance of `CLIArgs` populated with the parsed arguments.
"""
arg_name: str | None = None
kwargs: dict[str, Any] = {}
for arg in posargs:
if arg.startswith("--"):
arg_name = arg[2:]
kwargs[arg_name] = True
elif arg_name is not None:
kwargs[arg_name] = arg
arg_name = None
return cls(**kwargs)
@nox.session(python=False)
def fmt(session: nox.Session) -> None:
"""Format the code using Ruff and SQLFluff.
Args:
session (nox.Session): The Nox session object.
Examples:
>>> uv run nox -s fmt -- --ruff --sqlfluff
"""
args = CLIArgs.parse(session.posargs)
if args.ruff:
session.run("uv", "run", "ruff", "format", ".")
session.log("✅ Ruff formatting completed successfully.")
if args.sqlfluff:
session.run("uv", "run", "sqlfluff", "fix", ".")
session.log("✅ SQLFluff formatting completed successfully.")
@nox.session(python=False)
def lint(session: nox.Session) -> None:
"""Lint the code using Ruff, SQLFluff, and ty.
Args:
session (nox.Session): The Nox session object.
Examples:
>>> uv run nox -s lint -- --ruff --sqlfluff --ty
"""
args = CLIArgs.parse(session.posargs)
if args.ruff:
session.run("uv", "run", "ruff", "check", ".", "--fix")
session.log("✅ Ruff linting completed successfully.")
if args.sqlfluff:
session.run("uv", "run", "sqlfluff", "lint", ".")
session.log("✅ SQLFluff linting completed successfully.")
if args.ty:
session.run("uv", "run", "ty", "check")
session.log("✅ ty linting completed successfully.")
@nox.session(python=False)
def test(session: nox.Session) -> None:
"""Run tests using pytest.
Args:
session (nox.Session): The Nox session object.
Examples:
>>> uv run nox -s test -- --cov_report xml --junitxml junit.xml
"""
args = CLIArgs.parse(session.posargs)
command = ["uv", "run", "pytest", "--cov", "--cov-branch"]
if args.cov_report:
command.append(f"--cov-report={args.cov_report}")
if args.junitxml:
command.append(f"--junitxml={args.junitxml}")
session.run(*command)
session.log("✅ Testing completed successfully.")