-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathnoxfile.py
More file actions
134 lines (113 loc) · 3.52 KB
/
Copy pathnoxfile.py
File metadata and controls
134 lines (113 loc) · 3.52 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import shutil
from pathlib import Path
from typing import List
import nox
nox.options.reuse_existing_virtualenvs = True
nox.options.sessions = ["tests"]
SRCS = (
"aidial_rag",
"docs",
"tests",
"noxfile.py",
"generate_json_schema.py",
)
@nox.session()
def test(session):
"""Runs tests"""
refresh = "--refresh" in session.posargs
args = session.posargs
if refresh:
print("The cache would be refreshed")
session.env["REFRESH"] = "true"
args.remove("--refresh")
session.run("poetry", "install", "--only", "main, test", external=True)
session.run(
"python",
"-m",
"nltk.downloader",
"stopwords",
"punkt_tab",
)
session.run("pytest", *args, env=session.env)
@nox.session()
def eval(session):
"""Runs RAG evaluation"""
session.run("poetry", "install", "--with", "eval", external=True)
session.run(
"python",
"-m",
"nltk.downloader",
"stopwords",
"punkt_tab",
)
session.run("python", "./eval/eval_retriever.py")
@nox.session()
def update_docs(session):
session.run("poetry", "install", "--with", "doc", external=True)
session.run(
"settings-doc",
"generate",
"--class",
"aidial_rag.app_config.AppConfig",
"--output-format",
"markdown",
"--update",
"README.md",
"--between",
"<!-- generated-app-config-env-start -->",
"<!-- generated-app-config-env-end -->",
"--heading-offset",
"4",
)
session.run(
"python",
"./generate_json_schema.py",
"aidial_rag.retrieval_api.RetrievalResponse",
"docs/retrieval_response.generated.schema.json",
)
session.run(
"python",
"./generate_json_schema.py",
"aidial_rag.indexing_api.IndexingResponse",
"docs/indexing_response.generated.schema.json",
)
session.run(
"python",
"./generate_json_schema.py",
"aidial_rag.configuration_endpoint.Configuration",
"docs/configuration.generated.schema.json",
)
@nox.session()
def lint(session):
"""Runs linters and typecheckers"""
session.run("poetry", "install", "--with", "lint", external=True)
args = session.posargs or SRCS
session.run("ruff", "check", *args)
session.run("ruff", "format", "--check", *args)
session.run("pyright", *args)
@nox.session()
def format(session: nox.Session):
"""Runs formatters to fix linting errors"""
session.run("poetry", "install", "--only", "lint", external=True)
args = session.posargs or SRCS
session.run("ruff", "check", "--fix", *args)
session.run("ruff", "format", *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"])