|
2 | 2 | import enum |
3 | 3 | import logging |
4 | 4 | import os |
| 5 | +import pathlib |
5 | 6 | import shutil |
6 | 7 | import sys |
7 | 8 |
|
|
16 | 17 | MODEL_SERVER_MODEL_LIST_PATH, |
17 | 18 | MODEL_SERVER_MODEL_REQ_PATH, |
18 | 19 | download_path, |
19 | | - getConfig, |
| 20 | + get_config, |
20 | 21 | initial_pipeline_urls, |
21 | 22 | model_toppath, |
22 | 23 | set_config_dir, |
@@ -102,7 +103,7 @@ class ModelListParam(enum.Enum): |
102 | 103 |
|
103 | 104 |
|
104 | 105 | ########################################### |
105 | | -MODEL_SERVER_PORT = int(getConfig("MODEL_SERVER_PORT", "8100")) |
| 106 | +MODEL_SERVER_PORT = get_config("MODEL_SERVER_PORT", 8100) |
106 | 107 |
|
107 | 108 | # pipelineName and nodeCollection are global dict values set at initial state (load_init_pipeline) |
108 | 109 | ## pipelineName: map of energy_source to target pipeline name |
@@ -190,9 +191,9 @@ def select_best_model( |
190 | 191 | continue |
191 | 192 | else: |
192 | 193 | response = get_archived_file(valid_group_path, model_name) |
193 | | - if not os.path.exists(response): |
| 194 | + if response.exists() is False: |
194 | 195 | # archived model file does not exists |
195 | | - logger.warning(f"archive failed: {response}") |
| 196 | + logger.warning(f"archive file for {model_name}: {response} does not exist") |
196 | 197 | continue |
197 | 198 | if best_cadidate is None or best_cadidate[ERROR_KEY] > metadata[ERROR_KEY]: |
198 | 199 | best_cadidate = metadata |
@@ -341,8 +342,7 @@ def unpack_zip_files(root_folder): |
341 | 342 | zip_file_path = os.path.join(folder, file) |
342 | 343 | extract_to = os.path.splitext(zip_file_path)[0] # Extract to same location as the ZIP file |
343 | 344 | # Make sure the destination folder exists, if not, create it |
344 | | - if not os.path.exists(extract_to): |
345 | | - os.makedirs(extract_to) |
| 345 | + os.makedirs(extract_to, exist_ok=True) |
346 | 346 | shutil.unpack_archive(zip_file_path, extract_to) |
347 | 347 | weight_file = os.path.join(folder, file.replace(".zip", ".json")) |
348 | 348 | if os.path.exists(weight_file): |
@@ -435,11 +435,11 @@ def fill_machine_spec(): |
435 | 435 | @click.option( |
436 | 436 | "--config-dir", |
437 | 437 | "-c", |
438 | | - type=click.Path(exists=False, dir_okay=True, file_okay=False), |
| 438 | + type=click.Path(exists=False, dir_okay=True, file_okay=False, path_type=pathlib.Path), |
439 | 439 | default=CONFIG_PATH, |
440 | 440 | required=False, |
441 | 441 | ) |
442 | | -def run(log_level: str, config_dir: str) -> int: |
| 442 | +def run(log_level: str, config_dir: pathlib.Path) -> int: |
443 | 443 | level = getattr(logging, log_level.upper()) |
444 | 444 | logging.basicConfig( |
445 | 445 | level=level, |
|
0 commit comments