Local config no longer fails to import silently (#8006)

* Local config no longer fails to import silently

* fix types, use f-strings

* fix unhelpful pylint import error

* tweaked comment
This commit is contained in:
Dave Smith 2019-08-08 13:36:27 -07:00 committed by Beto Dealmeida
parent 73cdad2375
commit cd544fa6bc

View File

@ -23,7 +23,9 @@ at the end of this file.
""" """
from collections import OrderedDict from collections import OrderedDict
import imp import imp
import importlib.util
import json import json
import logging
import os import os
import sys import sys
@ -622,29 +624,29 @@ TALISMAN_CONFIG = {
# SQLALCHEMY_DATABASE_URI by default if set to `None` # SQLALCHEMY_DATABASE_URI by default if set to `None`
SQLALCHEMY_EXAMPLES_URI = None SQLALCHEMY_EXAMPLES_URI = None
try: if CONFIG_PATH_ENV_VAR in os.environ:
if CONFIG_PATH_ENV_VAR in os.environ: # Explicitly import config module that is not necessarily in pythonpath; useful
# Explicitly import config module that is not in pythonpath; useful # for case where app is being executed via pex.
# for case where app is being executed via pex. try:
print( cfg_path = os.environ[CONFIG_PATH_ENV_VAR]
"Loaded your LOCAL configuration at [{}]".format(
os.environ[CONFIG_PATH_ENV_VAR]
)
)
module = sys.modules[__name__] module = sys.modules[__name__]
override_conf = imp.load_source( override_conf = imp.load_source("superset_config", cfg_path)
"superset_config", os.environ[CONFIG_PATH_ENV_VAR]
)
for key in dir(override_conf): for key in dir(override_conf):
if key.isupper(): if key.isupper():
setattr(module, key, getattr(override_conf, key)) setattr(module, key, getattr(override_conf, key))
else: print(f"Loaded your LOCAL configuration at [{cfg_path}]")
from superset_config import * # noqa except Exception:
import superset_config logging.exception(
f"Failed to import config for {CONFIG_PATH_ENV_VAR}={cfg_path}"
print(
"Loaded your LOCAL configuration at [{}]".format(superset_config.__file__)
) )
except ImportError: raise
pass elif importlib.util.find_spec("superset_config"):
try:
from superset_config import * # noqa pylint: disable=import-error
import superset_config # noqa pylint: disable=import-error
print(f"Loaded your LOCAL configuration at [{superset_config.__file__}]")
except Exception:
logging.exception("Found but failed to import local superset_config")
raise