Skip to content

Commit ff9003b

Browse files
author
Winter Deng
committed
classify flags to 'general', 'linear', 'nn' categories, and change some flags orders in main.py
1 parent e0079e5 commit ff9003b

File tree

5 files changed

+100
-272
lines changed

5 files changed

+100
-272
lines changed

dev/classifier.py

Lines changed: 0 additions & 153 deletions
This file was deleted.

dev/excel_tools.py

Lines changed: 0 additions & 59 deletions
This file was deleted.

docs/cli/classifier.py

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,29 @@
99
lib_path = os.path.abspath(os.path.join(current_dir, "..", ".."))
1010
sys.path.insert(0, lib_path)
1111

12+
import subprocess
13+
14+
def load_exclude_authors(file_path):
15+
path = Path(file_path)
16+
if not path.exists():
17+
return []
18+
with open(path, "r", encoding="utf-8") as f:
19+
return [line.strip() for line in f if line.strip()]
20+
21+
def get_last_commit_excluding(exclude_file):
22+
exclude_authors = set(load_exclude_authors(exclude_file))
23+
24+
logs = subprocess.check_output([
25+
"git", "log",
26+
"--pretty=format:%H|%ae", # commit hash | author email
27+
]).decode("utf-8").splitlines()
28+
29+
for line in logs:
30+
commit, email = line.split("|", 1)
31+
if email not in exclude_authors:
32+
return commit
33+
return None
34+
1235
def classify_file_category(path):
1336

1437
relative_path = Path(path).relative_to(lib_path)
@@ -25,7 +48,6 @@ def classify_file_category(path):
2548

2649

2750
def fetch_option_flags(flags):
28-
# flags = genflags.parser.flags
2951
flag_list = []
3052

3153
for flag in flags:
@@ -42,6 +64,7 @@ def fetch_option_flags(flags):
4264

4365
def fetch_all_files():
4466
main_files = [
67+
os.path.join(lib_path, "main.py"),
4568
os.path.join(lib_path, "linear_trainer.py"),
4669
os.path.join(lib_path, "torch_trainer.py")
4770
]
@@ -61,13 +84,27 @@ def find_config_usages_in_file(file_path, allowed_keys):
6184

6285
category, path = classify_file_category(file_path)
6386

87+
if file_path.endswith("main.py"):
88+
for idx in range(len(lines)):
89+
if lines[idx].startswith("def main("):
90+
lines = lines[idx:]
91+
main_start = idx
92+
break
93+
for i, line in enumerate(lines[1:]):
94+
if line and line[0] not in (" ", "\t") and line.strip() != "":
95+
lines = lines[:i]
96+
break
97+
6498
for i, line in enumerate(lines, start=1):
6599
matches = pattern.findall(line)
66100
for key in matches:
67101
if key in allowed_keys:
68102
if key not in detailed_results:
69103
detailed_results[key] = {"file": path, "lines": []}
70-
detailed_results[key]["lines"].append(str(i))
104+
if file_path.endswith("main.py"):
105+
detailed_results[key]["lines"].append(str(i + main_start))
106+
else:
107+
detailed_results[key]["lines"].append(str(i))
71108

72109
return detailed_results
73110

@@ -125,6 +162,7 @@ def classify(raw_flags):
125162
for flag in flags:
126163
if flag["category"] not in result:
127164
result[flag["category"]] = []
165+
128166
result[flag["category"]].append({"name": flag["name"].replace("--", r"\-\-"), "description": flag["description"]})
129167

130168
result["details"] = []
@@ -134,4 +172,4 @@ def classify(raw_flags):
134172
for i in v[1:]:
135173
result["details"].append({"name": "", "file": i["file"], "location": ", ".join(i["lines"])})
136174

137-
return result
175+
return result

docs/cli/genflags.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
sys.path.insert(1, os.path.join(sys.path[0], "..", ".."))
55

66
import main
7-
87
from classifier import classify
98

10-
119
class FakeParser(dict):
1210
def __init__(self):
1311
self.flags = []
@@ -70,4 +68,4 @@ def print_table(title, flags, intro):
7068
classified["nn"],
7169
intro="**Neural network options**:\n\
7270
Configurations specific to torch (neural networks) trainer."
73-
)
71+
)

0 commit comments

Comments
 (0)