|
1 | | - |
2 | 1 | from . import utils |
3 | 2 | from . import controller |
4 | 3 | from . import commands |
5 | 4 | from . import logger |
6 | 5 |
|
7 | | -import argparse, os, warnings, json, logging |
| 6 | +import argparse, os, warnings, json |
8 | 7 | from types import SimpleNamespace |
9 | 8 | from pathlib import Path |
10 | 9 | from sys import argv |
11 | 10 | from importlib import import_module |
12 | | -from ngcsimlib.configManager import GlobalConfig |
| 11 | +from ngcsimlib.configManager import init_config, get_config |
13 | 12 |
|
14 | 13 | from pkg_resources import get_distribution |
15 | 14 |
|
16 | 15 | __version__ = get_distribution('ngcsimlib').version ## set software version |
17 | 16 |
|
18 | 17 |
|
19 | 18 | ###### Preload Modules |
20 | | -def preload(): |
21 | | - parser = argparse.ArgumentParser(description='Build and run a model using ngclearn') |
22 | | - parser.add_argument("--modules", type=str, help='location of modules.json file') |
23 | | - |
24 | | - ## ngc-sim-lib only cares about --modules argument |
25 | | - args, unknown = parser.parse_known_args() # args = parser.parse_args() |
26 | | - try: |
27 | | - module_path = args.modules |
28 | | - except: |
29 | | - module_path = None |
30 | | - |
31 | | - if module_path is None: |
32 | | - module_config = GlobalConfig.get_config("modules") |
33 | | - if module_config is None: |
34 | | - module_path = "json_files/modules.json" |
35 | | - else: |
36 | | - module_path = module_config.get("module_path", "json_files/modules.json") |
| 19 | +def preload_modules(): |
| 20 | + module_config = get_config("modules") |
| 21 | + if module_config is None: |
| 22 | + module_path = "json_files/modules.json" |
| 23 | + else: |
| 24 | + module_path = module_config.get("module_path", "json_files/modules.json") |
37 | 25 |
|
38 | 26 | if not os.path.isfile(module_path): |
39 | 27 | warnings.warn("\nMissing file to preload modules from. Attempted to locate file at \"" + str(module_path) + |
40 | 28 | "\". No modules will be preloaded. " |
41 | | - "\nSee https://ngc-learn.readthedocs.io/en/latest/tutorials/model_basics/json_modules.html for additional information") |
| 29 | + "\nSee https://ngc-learn.readthedocs.io/en/latest/tutorials/model_basics/json_modules.html for additional information") |
42 | 30 | return |
43 | 31 |
|
44 | 32 | with open(module_path, 'r') as file: |
@@ -76,18 +64,16 @@ def configure(): |
76 | 64 | if not os.path.isfile(config_path): |
77 | 65 | warnings.warn("\nMissing configuration file. Attempted to locate file at \"" + str(config_path) + |
78 | 66 | "\". Default Config will be used. " |
79 | | - "\nSee PUT LINK HERE for additional information") |
| 67 | + "\nSee https://ngc-learn.readthedocs.io/en/latest/tutorials/model_basics/configuration.html for " |
| 68 | + "additional information") |
80 | 69 | return |
81 | 70 |
|
82 | | - GlobalConfig.init_config(config_path) |
83 | | - |
84 | 71 |
|
| 72 | + init_config(config_path) |
85 | 73 |
|
86 | 74 |
|
87 | 75 | if not Path(argv[0]).name == "sphinx-build" or Path(argv[0]).name == "build.py": |
88 | 76 | if "readthedocs" not in argv[0]: ## prevent readthedocs execution of preload |
89 | 77 | configure() |
90 | 78 | logger.init_logging() |
91 | | - |
92 | | - preload() |
93 | | - |
| 79 | + preload_modules() |
0 commit comments