22import click
33import importlib
44import sys
5+ import copy
56import GPUtil
67from mlchain import logger
78from mlchain .server import MLServer
@@ -92,25 +93,33 @@ def run_command(entry_file, host, port, bind, wrapper, server, workers, config,
9293 name , mode , api_format , ngrok , kws ):
9394 kws = list (kws )
9495 if isinstance (entry_file , str ) and not os .path .exists (entry_file ):
95- kws = [entry_file ] + kws
96+ kws = [f'-- entry_file= { entry_file } ' ] + kws
9697 entry_file = None
9798 from mlchain import config as mlconfig
9899 default_config = False
100+
99101 if config is None :
100102 default_config = True
101103 config = 'mlconfig.yaml'
102104
103- if os .path .isfile (config ):
104- config = mlconfig .load_file (config )
105+ config_path = copy .deepcopy (config )
106+ if os .path .isfile (config_path ) and os .path .exists (config_path ):
107+ config = mlconfig .load_file (config_path )
105108 if config is None :
106- raise AssertionError ( "Not support file config {0}" .format (config ))
109+ raise SystemExit ( "Config file {0} are not supported " .format (config_path ))
107110 else :
108111 if not default_config :
109- raise FileNotFoundError ("Not found file {0}" .format (config ))
110- config = {}
112+ raise SystemExit ("Can't find config file {0}" .format (config_path ))
113+ else :
114+ raise SystemExit ("Can't find mlchain config file. Please double check your current working directory. Or use `mlchain init` to initialize a new ones here." )
111115 if 'mode' in config and 'env' in config ['mode' ]:
112116 if mode in config ['mode' ]['env' ]:
113117 config ['mode' ]['default' ] = mode
118+ elif mode is not None :
119+ available_mode = list (config ['mode' ]['env' ].keys ())
120+ available_mode = [each for each in available_mode if each != 'default' ]
121+ raise SystemExit (
122+ f"No { mode } mode are available. Found these mode in config file: { available_mode } " )
114123 mlconfig .load_config (config )
115124 for kw in kws :
116125 if kw .startswith ('--' ):
@@ -124,6 +133,8 @@ def run_command(entry_file, host, port, bind, wrapper, server, workers, config,
124133 raise AssertionError ("Unexpected param {0}" .format (kw ))
125134 model_id = mlconfig .get_value (None , config , 'model_id' , None )
126135 entry_file = mlconfig .get_value (entry_file , config , 'entry_file' , 'server.py' )
136+ if not os .path .exists (entry_file ):
137+ raise SystemExit (f"Entry file { entry_file } not found in current working directory." )
127138 host = mlconfig .get_value (host , config , 'host' , 'localhost' )
128139 port = mlconfig .get_value (port , config , 'port' , 5000 )
129140 server = mlconfig .get_value (server , config , 'server' , 'flask' )
0 commit comments