Skip to content

Commit b4073ef

Browse files
committed
meta: lint-generated-project
1 parent 48d46cc commit b4073ef

File tree

4 files changed

+94
-37
lines changed

4 files changed

+94
-37
lines changed

noxfile.py

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
GITHUB_USER: str = "56kyle"
3333

3434
ENV: str = "env"
35-
STYLE: str = "style"
35+
FORMAT: str = "format"
3636
LINT: str = "lint"
3737
TYPE: str = "type"
3838
TEST: str = "test"
@@ -42,15 +42,16 @@
4242
DOCS: str = "docs"
4343
BUILD: str = "build"
4444
RELEASE: str = "release"
45-
MAINTENANCE: str = "maintenance"
4645
CI: str = "ci"
46+
PYTHON: str = "python"
47+
RUST: str = "rust"
4748

4849

4950
@nox.session(python=None, name="setup-git", tags=[ENV])
5051
def setup_git(session: Session) -> None:
5152
"""Set up the git repo for the current project."""
5253
session.run(
53-
"python", SCRIPTS_FOLDER / "setup-git.py", REPO_ROOT, "-u", GITHUB_USER, "-n", PROJECT_NAME, external=True
54+
"python", SCRIPTS_FOLDER / "setup-git.py", REPO_ROOT, external=True
5455
)
5556

5657

@@ -60,7 +61,8 @@ def setup_venv(session: Session) -> None:
6061
session.run("python", SCRIPTS_FOLDER / "setup-venv.py", REPO_ROOT, "-p", PYTHON_VERSIONS[0], external=True)
6162

6263

63-
@nox.session(python=DEFAULT_PYTHON_VERSION, name="pre-commit")
64+
65+
@nox.session(python=DEFAULT_PYTHON_VERSION, name="pre-commit", tags=[CI])
6466
def precommit(session: Session) -> None:
6567
"""Lint using pre-commit."""
6668
args: list[str] = session.posargs or ["run", "--all-files", "--hook-stage=manual", "--show-diff-on-failure"]
@@ -73,21 +75,42 @@ def precommit(session: Session) -> None:
7375
activate_virtualenv_in_precommit_hooks(session)
7476

7577

76-
@nox.session(python=PYTHON_VERSIONS, name="typecheck", tags=[TYPE])
78+
@nox.session(python=DEFAULT_PYTHON_VERSION, name="format-python", tags=[FORMAT, PYTHON])
79+
def format_python(session: Session) -> None:
80+
"""Run Python code formatter (Ruff format)."""
81+
session.log("Installing formatting dependencies...")
82+
session.install("-e", ".", "--group", "dev")
83+
84+
session.log(f"Running Ruff formatter check with py{session.python}.")
85+
# Use --check, not fix. Fixing is done by pre-commit or manual run.
86+
session.run("ruff", "format", *session.posargs)
87+
88+
89+
@nox.session(python=DEFAULT_PYTHON_VERSION, name="lint-python", tags=[LINT, PYTHON])
90+
def lint_python(session: Session) -> None:
91+
"""Run Python code linters (Ruff check, Pydocstyle rules)."""
92+
session.log("Installing linting dependencies...")
93+
session.install("-e", ".", "--group", "dev")
94+
95+
session.log(f"Running Ruff check with py{session.python}.")
96+
session.run("ruff", "check", "--verbose")
97+
98+
99+
@nox.session(python=PYTHON_VERSIONS, name="typecheck", tags=[TYPE, PYTHON, CI])
77100
def typecheck(session: Session) -> None:
78101
"""Run static type checking (Pyright) on Python code."""
79102
session.log("Installing type checking dependencies...")
80-
session.install("-e", ".", "--group", "dev", "--group", "typecheck")
103+
session.install("-e", ".", "--group", "dev")
81104

82105
session.log(f"Running Pyright check with py{session.python}.")
83106
session.run("pyright")
84107

85108

86-
@nox.session(python=DEFAULT_PYTHON_VERSION, name="security-python", tags=[SECURITY])
109+
@nox.session(python=DEFAULT_PYTHON_VERSION, name="security-python", tags=[SECURITY, PYTHON, CI])
87110
def security_python(session: Session) -> None:
88111
"""Run code security checks (Bandit) on Python code."""
89112
session.log("Installing security dependencies...")
90-
session.install("-e", ".", "--group", "dev", "--group", "security")
113+
session.install("-e", ".", "--group", "dev")
91114

92115
session.log(f"Running Bandit static security analysis with py{session.python}.")
93116
session.run("bandit", "-r", PACKAGE_NAME, "-c", "bandit.yml", "-ll")
@@ -96,11 +119,11 @@ def security_python(session: Session) -> None:
96119
session.run("pip-audit")
97120

98121

99-
@nox.session(python=PYTHON_VERSIONS, name="tests-python", tags=[TEST])
122+
@nox.session(python=PYTHON_VERSIONS, name="tests-python", tags=[TEST, PYTHON, CI])
100123
def tests_python(session: Session) -> None:
101124
"""Run the Python test suite (pytest with coverage)."""
102125
session.log("Installing test dependencies...")
103-
session.install("-e", ".", "--group", "dev", "--group", "test")
126+
session.install("-e", ".", "--group", "dev")
104127

105128
session.log(f"Running test suite with py{session.python}.")
106129
test_results_dir = Path("test-results")
@@ -120,7 +143,7 @@ def tests_python(session: Session) -> None:
120143
def docs_build(session: Session) -> None:
121144
"""Build the project documentation (Sphinx)."""
122145
session.log("Installing documentation dependencies...")
123-
session.install("-e", ".", "--group", "dev", "--group", "docs")
146+
session.install("-e", ".", "--group", "dev")
124147

125148
session.log(f"Building documentation with py{session.python}.")
126149
docs_build_dir = Path("docs") / "_build" / "html"
@@ -132,7 +155,7 @@ def docs_build(session: Session) -> None:
132155
session.run("sphinx-build", "-b", "html", "docs", str(docs_build_dir), "-W")
133156

134157

135-
@nox.session(python=DEFAULT_PYTHON_VERSION, name="build-python", tags=[BUILD])
158+
@nox.session(python=DEFAULT_PYTHON_VERSION, name="build-python", tags=[BUILD, PYTHON])
136159
def build_python(session: Session) -> None:
137160
"""Build sdist and wheel packages (uv build)."""
138161
session.log("Installing build dependencies...")
@@ -232,7 +255,7 @@ def release(session: Session) -> None:
232255
)
233256

234257

235-
@nox.session(venv_backend="none", tags=[MAINTENANCE])
258+
@nox.session(venv_backend="none")
236259
def tox(session: Session) -> None:
237260
"""Run the 'tox' test matrix.
238261
@@ -266,7 +289,7 @@ def coverage(session: Session) -> None:
266289
session.log("Note: Ensure 'nox -s test-python' was run across all desired Python versions first to generate coverage data.")
267290

268291
session.log("Installing dependencies for coverage report session...")
269-
session.install("-e", ".", "--group", "dev", "--group", "test")
292+
session.install("-e", ".", "--group", "dev")
270293

271294
coverage_combined_file: Path = Path.cwd() / ".coverage"
272295

pyproject.toml

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,18 @@ dev = [
2828
"nox>=2025.5.1",
2929
"pre-commit>=4.2.0",
3030
"pre-commit-hooks>=5.0.0",
31-
]
32-
docs = [
3331
"furo>=2024.8.6",
3432
"myst-parser>=3.0.1",
3533
"sphinx>=7.4.7",
3634
"sphinx-autodoc-typehints>=2.3.0",
3735
"sphinx-copybutton>=0.5.2",
3836
"sphinx-tabs>=3.4.7",
39-
]
40-
lint = [
4137
"pydocstyle>=6.3.0",
4238
"ruff>=0.11.9",
43-
]
44-
security = [
4539
"bandit>=1.8.3",
4640
"pip-audit>=2.9.0",
47-
]
48-
test = [
4941
"pytest>=8.3.5",
5042
"pytest-cov>=6.1.1",
51-
]
52-
typecheck = [
5343
"pyright>=1.1.400",
5444
]
5545

@@ -59,4 +49,4 @@ Repository = "https://github.com/56kyle/robust-python-demo"
5949

6050
[build-system]
6151
requires = ["setuptools>=61.0" ]
62-
build-backend = "setuptools.build_meta"
52+
build-backend = "setuptools.build_meta"

scripts/setup-git.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Script responsible for first time setup of the project's git repo.
22
3-
Since this a first time setup script, we intentionally only use builtin Python dependencies.
3+
Since this is a first time setup script, we intentionally only use builtin Python dependencies.
44
"""
55
import argparse
66
import subprocess
@@ -14,25 +14,18 @@ def main() -> None:
1414
"""Parses command line input and passes it through to setup_git."""
1515
parser: argparse.ArgumentParser = get_parser()
1616
args: argparse.Namespace = parser.parse_args()
17-
setup_git(path=args.path, github_user=args.github_user, repo_name=args.repo_name)
17+
setup_git(path=args.path)
1818

1919

20-
def setup_git(path: Path, github_user: str, repo_name: str) -> None:
20+
def setup_git(path: Path) -> None:
2121
"""Set up the provided cookiecutter-robust-python project's git repo."""
2222
commands: list[list[str]] = [
2323
["git", "init"],
2424
["git", "branch", "-m", "master", "main"],
2525
["git", "checkout", "main"],
26-
["git", "remote", "add", "origin", f"https://github.com/{github_user}/{repo_name}.git"],
27-
["git", "remote", "set-url", "origin", f"https://github.com/{github_user}/{repo_name}.git"],
28-
["git", "fetch", "origin"],
29-
["git", "pull"],
30-
["git", "push", "-u", "origin", "main"],
3126
["git", "checkout", "-b", "develop", "main"],
32-
["git", "push", "-u", "origin", "develop"],
3327
["git", "add", "."],
3428
["git", "commit", "-m", "feat: initial commit"],
35-
["git", "push", "origin", "develop"]
3629
]
3730
check_dependencies(path=path, dependencies=["git"])
3831

@@ -53,8 +46,6 @@ def get_parser() -> argparse.ArgumentParser:
5346
metavar="PATH",
5447
help="Path to the repo's root directory (must already exist).",
5548
)
56-
parser.add_argument("-u", "--user", dest="github_user", help="GitHub user name.")
57-
parser.add_argument("-n", "--name", dest="repo_name", help="Name of the repo.")
5849
return parser
5950

6051

scripts/setup-remote.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
"""Script responsible for first time setup of the project's git repo's remote connection.
2+
3+
Since this is a first time setup script, we intentionally only use builtin Python dependencies.
4+
"""
5+
import argparse
6+
import subprocess
7+
from pathlib import Path
8+
9+
from util import check_dependencies
10+
from util import existing_dir
11+
12+
13+
def main() -> None:
14+
"""Parses command line input and passes it through to setup_git."""
15+
parser: argparse.ArgumentParser = get_parser()
16+
args: argparse.Namespace = parser.parse_args()
17+
setup_remote(path=args.path, github_user=args.github_user, repo_name=args.repo_name)
18+
19+
20+
def setup_remote(path: Path, github_user: str, repo_name: str) -> None:
21+
"""Set up the provided cookiecutter-robust-python project's git repo."""
22+
commands: list[list[str]] = [
23+
["git", "fetch", "origin"],
24+
["git", "remote", "add", "origin", f"https://github.com/{github_user}/{repo_name}.git"],
25+
["git", "remote", "set-url", "origin", f"https://github.com/{github_user}/{repo_name}.git"],
26+
["git", "pull"],
27+
["git", "checkout", "main"],
28+
["git", "push", "-u", "origin", "main"],
29+
["git", "checkout", "develop"],
30+
["git", "push", "-u", "origin", "develop"],
31+
]
32+
check_dependencies(path=path, dependencies=["git"])
33+
34+
for command in commands:
35+
subprocess.run(command, cwd=path, stderr=subprocess.STDOUT)
36+
37+
38+
def get_parser() -> argparse.ArgumentParser:
39+
"""Creates the argument parser for setup-git."""
40+
parser: argparse.ArgumentParser = argparse.ArgumentParser(
41+
prog="setup-git",
42+
usage="python ./scripts/setup-remote.py . -u 56kyle -n robust-python-demo",
43+
description="Set up the provided cookiecutter-robust-python project's remote repo connection.",
44+
)
45+
parser.add_argument(
46+
"path",
47+
type=existing_dir,
48+
metavar="PATH",
49+
help="Path to the repo's root directory (must already exist).",
50+
)
51+
parser.add_argument("-u", "--user", dest="github_user", help="GitHub user name.")
52+
parser.add_argument("-n", "--name", dest="repo_name", help="Name of the repo.")
53+
return parser

0 commit comments

Comments
 (0)