-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathginger.py
More file actions
57 lines (52 loc) · 2.15 KB
/
ginger.py
File metadata and controls
57 lines (52 loc) · 2.15 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
import os, importlib, sys
from argparse import ArgumentParser
from rich import print
from engine.structs import *
from engine.compiler import *
from engine.watcher import *
from engine.tools import *
if __name__ == "__main__":
sys.path.append(os.getcwd())
args = ArgumentParser()
args.add_argument("-k", "--key", required=True)
args.add_argument("-l", "--language", default="Python")
args.add_argument("-t", "--traceback", default="en-US")
args.add_argument("-i", "--indent", default=4)
args.add_argument("-o", "--output", default="$basename$extension")
args.add_argument("-m", "--model", default="chatglm")
args.add_argument("-p", "--show-prompt", action="store_true")
args.add_argument("-w", "--watch", action="store_true")
group = args.add_mutually_exclusive_group(required=True)
group.add_argument("-f", "--file")
group.add_argument("-c", "--config-file")
namespace = ArgNamespace(**vars(args.parse_args()))
namespace.indent = int(namespace.indent)
setKey(namespace.key)
for dirName in os.listdir("plugins"):
pluginDir = os.path.join("plugins", dirName)
pluginMainFile = os.path.join(pluginDir, "main.py")
if os.path.isdir(pluginDir):
if os.path.exists(pluginMainFile):
if os.path.isfile(pluginMainFile):
importlib.import_module(f"plugins.{dirName}.main")
else:
raise FileNotFoundError(f"Plugin {dirName} main.py is not a file")
else:
raise FileNotFoundError(f"Plugin {dirName} does not have main.py")
if namespace.file:
run(namespace, not namespace.watch)
if namespace.watch:
waitPress()
clearTerminal()
print("Watching...")
blockWait()
elif namespace.config_file:
config, merged, haveWatch = parseConfigFile(namespace.config_file)
for dirName in config.includes:
current = generateNamespaceFromInclude(dirName)
run(current, not current.watch)
if haveWatch:
waitPress()
clearTerminal()
print("Watching...")
blockWait()