| 288 | |
| 289 | |
| 290 | def get_config(): |
| 291 | config_directory = os.path.dirname(__file__) # this will be "scripts" |
| 292 | config_yaml = os.path.abspath(os.path.join(config_directory, "..", "config.yaml")) |
| 293 | config_json = os.path.join(config_directory, "config.json") |
| 294 | |
| 295 | config = None |
| 296 | |
| 297 | # migrate the old config yaml location |
| 298 | config_legacy_yaml = os.path.join(config_directory, "config.yaml") |
| 299 | if os.path.isfile(config_legacy_yaml): |
| 300 | shutil.move(config_legacy_yaml, config_yaml) |
| 301 | |
| 302 | if os.path.isfile(config_yaml): |
| 303 | from ruamel.yaml import YAML |
| 304 | |
| 305 | yaml = YAML(typ="safe") |
| 306 | with open(config_yaml, "r") as configfile: |
| 307 | try: |
| 308 | config = yaml.load(configfile) |
| 309 | except Exception as e: |
| 310 | print(e, file=sys.stderr) |
| 311 | elif os.path.isfile(config_json): |
| 312 | import json |
| 313 | |
| 314 | with open(config_json, "r") as configfile: |
| 315 | try: |
| 316 | config = json.load(configfile) |
| 317 | except Exception as e: |
| 318 | print(e, file=sys.stderr) |
| 319 | |
| 320 | if config is None: |
| 321 | config = {} |
| 322 | return config |
| 323 | |
| 324 | |
| 325 | def launch_uvicorn(): |