This repository was archived by the owner on Oct 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__main__.py
85 lines (70 loc) · 2.21 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import sys, json, re
from . import decodeModel
from collections import OrderedDict
from .utils import makeSerializeable
import importlib.util
def ifModExists(modName):
return importlib.util.find_spec(modName) is not None
useML = (ifModExists("numpy") and ifModExists("pandas") and ifModExists("xgboost") and ifModExists("Chassis") and ifModExists("AutoXGBoost"))
try:
from RichConsole import groups, rsjoin
styles={
"prefix": groups.Fore.lightcyanEx,
"cli": groups.Fore.lightgreenEx,
"help": groups.Fore.lightmagentaEx,
}
except:
styles={
"prefix": lambda x:x,
"cli": lambda x:x,
"help": lambda x:x,
}
def rsjoin(self, *args, **kwargs):
return self.join(*args, **kwargs)
endMainRx=re.compile("\.__main__$")
wsRx=re.compile("\s")
def splitByWhitespaces(file):
for l in file:
yield from wsRx.split(l)
def showHelp():
if sys.platform=="win32":
try:
import colorama
colorama.init()
except:
pass
prefix=styles["prefix"](rsjoin(" ", ("python -m", endMainRx.sub("", __spec__.name))))
print(
rsjoin("\n", (
styles["cli"](rsjoin(" ", (prefix, cliArg))) + styles["help"](" - "+par[1])
for cliArg, par in singleArgLUT.items()
))
)
def getModelObj(mn):
return makeSerializeable(decodeModel(mn, useML, True))
def whole(modelNames):
json.dump( OrderedDict(( (el, getModelObj(el)) for el in modelNames )), sys.stdout, indent="\t")
def fromStdinByOne():
for el in filter(None, splitByWhitespaces(sys.stdin)):
json.dump(getModelObj(el), sys.stdout, indent="\t")
sys.stdout.write("\n")
sys.stdout.flush()
def fromStdinWhole():
whole(filter(None, splitByWhitespaces(sys.stdin)))
singleArgLUT=OrderedDict((
("model_name_1, model_name_2, ...", (None, "to pass models namebers as parameters")),
("--", (fromStdinByOne, "to pipe models namebers into stdin and get the results as JSON one by one")),
("-" , (fromStdinWhole, "to pipe models namebers file into stdin and get the results as a JSON array")),
("-h", (showHelp, "shows help")),
("--help", (showHelp, "shows help")),
))
def main():
if len(sys.argv)<2:
showHelp()
elif len(sys.argv)==2 and sys.argv[1] in singleArgLUT:
singleArgLUT[sys.argv[1]][0]()
else:
whole(sys.argv[1:])
sys.stdout.write("\n")
if __name__ == "__main__":
main()