-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathautofix_entrypoints.py
More file actions
48 lines (41 loc) · 2.11 KB
/
autofix_entrypoints.py
File metadata and controls
48 lines (41 loc) · 2.11 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
import os
import re
from pathlib import Path
WORKSPACE = Path(__file__).parent.resolve()
SCAN_DIRS = ["skills", "nexus", "plugins", "evals", "basis-research", "quantum", "criador-artigo"]
def scan_and_fix():
fixed_files = []
for sd in SCAN_DIRS:
base = WORKSPACE / sd
if base.exists():
for f in sorted(base.rglob("*.py")):
if "temp" in str(f):
continue
content = f.read_text(encoding="utf-8", errors="ignore")
is_init = f.name == "__init__.py"
has_entrypoint = "def main()" in content or "if __name__" in content
if is_init or has_entrypoint:
continue
# Detecta se ha codigo module-level com side effects (nao apenas imports/defs/class)
has_side_effects = False
for line in content.splitlines():
st = line.strip()
if not st or st.startswith("#") or st.startswith("import ") or st.startswith("from ") or \
st.startswith("def ") or st.startswith("class ") or st.startswith("@") or \
st.startswith('"""') or st.startswith("'''") or st in ('"""', "'''"):
continue
has_side_effects = True
break
if has_side_effects:
# Append entrypoint
new_content = content
if not new_content.endswith("\n"):
new_content += "\n"
new_content += "\n\ndef main():\n # Entrypoint auto-gerado para conformidade com a arquitetura\n print(f\"Modulo {__name__} executado diretamente.\")\n\n\nif __name__ == \"__main__\":\n main()\n"
f.write_text(new_content, encoding="utf-8")
fixed_files.append(str(f.relative_to(WORKSPACE)))
print(f"Total de arquivos corrigidos: {len(fixed_files)}")
for pf in fixed_files:
print(f" - {pf}")
if __name__ == "__main__":
scan_and_fix()