-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
59 lines (49 loc) · 1.75 KB
/
main.py
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
# main.py
import sys
import time
import traceback
from argparse import ArgumentParser
from concurrent.futures import ThreadPoolExecutor
from tqdm import tqdm
from Core.config import SinglePythonInfo
from Core.shell import SinglePythonShell
from Core.utils import execute_code_from_file, get_version
def init():
"""
初始化进度条显示。
"""
print("Initializing...")
for _ in tqdm(range(100), desc="Initialization", ncols=75, leave=False):
time.sleep(0.001) # 更快的进度条
print("Initialization complete.")
sys.stdout.write("\x1b[A" * 3)
sys.stdout.flush()
def main():
"""
主程序入口,解析命令行参数,执行文件或进入交互式 shell。
"""
parser = ArgumentParser(description="Interactive Python Shell with additional features.")
parser.add_argument("file", nargs='?', type=str, help="Execute Python code from the specified file")
parser.add_argument("-i", "--interactive", action="store_true",
help="Enter interactive mode after executing a file.")
parser.add_argument("-v", "--version", action="version", version=get_version(), help="Show version information")
args = parser.parse_args()
try:
if args.file:
execute_code_from_file(args.file) # 直接调用,无需线程池
if args.interactive:
shell = SinglePythonShell(SinglePythonInfo)
init()
shell.run()
else:
sys.exit(0)
else:
shell = SinglePythonShell(SinglePythonInfo)
init()
shell.run()
except Exception as e:
print(f"An error occurred: {e}")
traceback.print_exc()
sys.exit(1)
if __name__ == "__main__":
main()