forked from gabrielhayoun/PIE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
56 lines (48 loc) · 1.74 KB
/
run.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
""" Main function to launch a training / inference from the command line using the configuration files.
"""
import sys, getopt
from pathlib import Path
# https://www.tutorialspoint.com/python/python_command_line_arguments.htm
import pynance
def print_usage():
print('Usage : ')
print('run.py -n <cfg_name> -k <process_kind>')
print('`.cfg` is automatically added to the name')
print(f'File <cfg_name>.cfg should exist in folder {pynance.utils.user.get_path_to_config_files()}')
print('To change it, modify `USERCFG` file.')
print('Available kind process: train, infer, crypto, coint.')
def get_function_from_kind(kind):
switch = {
'train': pynance.train.main,
'infer': pynance.infer.main,
'coint': pynance.coint.main,
'crypto': pynance.crypto.main
}
return switch.get(kind, "Invalid input")
def run(argv):
try:
opts, args = getopt.getopt(argv,"hn:k:", ['path=']) # h for help, s for save
except getopt.GetoptError:
print_usage()
sys.exit(2)
if(len(opts)==0):
print_usage()
sys.exit()
if(opts[0][0] == '-h'):
print_usage()
sys.exit()
elif opts[0][0] in ('-n','--name'):
cfg_name = opts[0][1]
cfg_path = pynance.utils.user.get_path_to_config_files() / f'{cfg_name}.cfg'
print(f'Config file used: {cfg_path}')
if(opts[1][0] in ('-k', '--kind')):
kind = opts[1][1]
print(f'Process kind: {kind}')
main_fn = get_function_from_kind(kind)
main_fn(cfg_path)
else :
print('Please precise path to cfg.')
print_usage()
sys.exit()
if __name__ == "__main__":
run(sys.argv[1:]) # because the first arg is always the name of the file