Coverage for src/rejuvenation/cli.py: 0%
29 statements
« prev ^ index » next coverage.py v7.17.0, created at 2026-11-16 16:04 +0000
« prev ^ index » next coverage.py v7.17.0, created at 2026-11-16 16:04 +0000
1# Copyright (C) 2024-2026 TNO
2#
3# Licensed under the terms specified in the LICENSE file in the root directory
4# of this repository, also available at:
5# https://github.com/TNO/Renaissance.Py/blob/main/LICENSE
7"""AI: Command-line entry point for running Python refactoring recipes on source files."""
9import sys
10from pathlib import Path
12from renaissance.integrations.python.ast.extractor import PythonExtractor
13from renaissance.integrations.python.ast.rst_node import PythonRstNode
14from renaissance.project.project_scanner import PythonScanner
15from renaissance.recipes.python_refactoring import PythonRefactoring
16from renaissance.syntax_tree import ASTShower
19def refactor() -> None:
20 """AI: Run the `refactor`/`extract`/`inspect` CLI subcommands based on `sys.argv`."""
21 if sys.argv[1] == "refactor":
22 refactoring = sys.argv[2]
23 files = [sys.argv[3]] if len(sys.argv) > 3 else PythonScanner().find_sources()
24 print(f"Refactor {Path().cwd()}")
25 for file in files:
26 PythonRefactoring.process(refactoring, file)
28 if sys.argv[1] == "extract":
29 print(f"Extracting {Path().cwd()}")
30 extractor = PythonExtractor()
31 for file in PythonScanner().find_sources():
32 filename = sys.argv[2]
33 extractor.process(Path(file))
34 extractor.save_graph(filename)
35 if sys.argv[1] == "inspect":
36 print(f"inspect {Path().cwd()}")
37 file = sys.argv[2]
38 ASTShower.focus = f"|{sys.argv[3]}"
39 atu = PythonRstNode.load(Path(file))
40 ASTShower.show_node(atu)
43if __name__ == "__main__":
44 refactor()