@@ -61,9 +61,24 @@ def __init__(self, config_path=constances.CONFIG_FILE_LOCATION):
6161 self ._team_id = None
6262 self ._user_id = None
6363 self ._team_name = None
64- self .init (config_path )
64+ self ._config_path = Path (config_path )
65+ if str (self ._config_path ) == constances .CONFIG_FILE_LOCATION :
66+ if not self ._config_path .is_file ():
67+ self .configs .insert (ConfigEntity ("main_endpoint" , constances .BACKEND_URL ))
68+ self .configs .insert (ConfigEntity ("token" , "" ))
69+ try :
70+ self .init (config_path )
71+ except AppException :
72+ pass
6573
66- def init (self , config_path ):
74+ def init (self , config_path = constances .CONFIG_FILE_LOCATION ):
75+ config_path = Path (config_path )
76+ if not config_path .is_file ():
77+ raise AppException (
78+ f"SuperAnnotate config file { str (config_path )} not found."
79+ f" Please provide correct config file location to sa.init(<path>) or use "
80+ f"CLI's superannotate init to generate default location config file."
81+ )
6782 self ._config_path = config_path
6883 token , main_endpoint = (
6984 self .configs .get_one ("token" ),
@@ -72,13 +87,9 @@ def init(self, config_path):
7287 token = None if not token else token .value
7388 main_endpoint = None if not main_endpoint else main_endpoint .value
7489 if not main_endpoint :
75- self .configs .insert (ConfigEntity ("main_endpoint" , constances .BACKEND_URL ))
7690 main_endpoint = constances .BACKEND_URL
7791 if not token :
78- self .configs .insert (ConfigEntity ("token" , "" ))
79- # TODO check
80- #self._logger.warning(f"Fill token in the {config_path}")
81- return
92+ raise AppException (f"Incorrect config file: token is not present in the config file { config_path } " )
8293 verify_ssl_entity = self .configs .get_one ("ssl_verify" )
8394 if not verify_ssl_entity :
8495 verify_ssl = True
0 commit comments