mirror of
https://github.com/apache/superset.git
synced 2024-09-12 08:39:45 -04:00
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:
parent
73cdad2375
commit
cd544fa6bc
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user