-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnoxfile.py
More file actions
66 lines (50 loc) · 1.75 KB
/
noxfile.py
File metadata and controls
66 lines (50 loc) · 1.75 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
import shutil
from pathlib import Path
from typing import List
import nox
nox.options.sessions = ("lint", "tests")
nox.options.reuse_existing_virtualenvs = True
SRCS = ("src", "tests", "noxfile.py")
@nox.session(python=["3.12"])
def test(session):
args = session.posargs or [
"--cov=src",
"--cov-report",
"xml:coverage.xml",
"--cov-report",
"term",
"--junitxml=junit.xml",
]
session.run("poetry", "install", external=True)
session.run("pytest", *args)
@nox.session(python=["3.12"])
def lint(session):
args = session.posargs or SRCS
session.run("poetry", "install", external=True)
session.run("flake8", *args)
session.run("pyright", *args)
@nox.session(python=["3.12"])
def format(session):
args = session.posargs or SRCS
session.run("poetry", "install", external=True)
session.run("black", *args)
session.run("isort", *args)
@nox.session(python=False)
def clean(_: nox.Session):
"""Cleans up the project by removing unnecessary files and directories"""
def remove_dir(directory_path: Path):
if directory_path.is_dir():
shutil.rmtree(directory_path)
print(f"Removed: {directory_path}")
def remove_recursively(pattern: str, exclude_dirs: List[str] | None = None):
if exclude_dirs is None:
exclude_dirs = []
def is_excluded(file: Path) -> bool:
return any(dir in str(file) for dir in exclude_dirs)
for file in Path(".").rglob(pattern):
if not is_excluded(file):
remove_dir(file)
remove_dir(Path(".nox"))
remove_dir(Path("dist"))
remove_recursively("__pycache__", exclude_dirs=[".venv"])
remove_recursively(".pytest_cache", exclude_dirs=[".venv"])