Skip to content

Commit e110d81

Browse files
committed
Refactor the function to load config
1 parent a4053c7 commit e110d81

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

atcodertools/tools/envgen.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from multiprocessing import Pool, cpu_count
77
from os.path import expanduser
88
from time import sleep
9-
from typing import Tuple
9+
from typing import Tuple, Optional
1010

1111
from atcodertools.codegen.code_gen_config import CodeGenConfig
1212
from atcodertools.codegen.cpp_code_generator import CppCodeGenerator
@@ -213,17 +213,18 @@ def check_lang(lang: str):
213213
os.path.join(script_dir_path, "./atcodertools-default.toml"))
214214

215215

216-
def get_code_gen_config(config_path: str = None):
216+
def get_code_gen_config(config_path: Optional[str] = None):
217+
def _load(path: str):
218+
logging.info("Going to load {} as config".format(path))
219+
return CodeGenConfig.load(path)
220+
217221
if config_path:
218-
logging.info("Going to load {} as config".format(config_path))
219-
return CodeGenConfig.load(config_path)
222+
return _load(config_path)
223+
220224
if os.path.exists(PRIMARY_DEFAULT_CONFIG_PATH):
221-
logging.info("Going to load {} as config".format(
222-
PRIMARY_DEFAULT_CONFIG_PATH))
223-
return CodeGenConfig.load(PRIMARY_DEFAULT_CONFIG_PATH)
224-
logging.info("Going to load {} as config".format(
225-
SECONDARY_DEFAULT_CONFIG_PATH))
226-
return CodeGenConfig.load(SECONDARY_DEFAULT_CONFIG_PATH)
225+
return _load(PRIMARY_DEFAULT_CONFIG_PATH)
226+
227+
return _load(SECONDARY_DEFAULT_CONFIG_PATH)
227228

228229

229230
def main(prog, args):
@@ -280,7 +281,9 @@ def main(prog, args):
280281
help="{0}{1}{2}".format("file path to your config file\n",
281282
"[Default (Primary)] {}\n".format(
282283
PRIMARY_DEFAULT_CONFIG_PATH),
283-
"[Default (Secondary)] {}\n".format(SECONDARY_DEFAULT_CONFIG_PATH)))
284+
"[Default (Secondary)] {}\n".format(
285+
SECONDARY_DEFAULT_CONFIG_PATH))
286+
)
284287

285288
args = parser.parse_args(args)
286289

0 commit comments

Comments
 (0)