modify sys path

This commit is contained in:
Khaleel Al-Adhami 2024-11-19 16:03:10 -08:00
parent 8742723d34
commit e0a8e8dedc

View File

@ -812,18 +812,19 @@ def get_config(reload: bool = False) -> Config:
if reload and constants.Config.MODULE in sys.modules: if reload and constants.Config.MODULE in sys.modules:
del sys.modules[constants.Config.MODULE] del sys.modules[constants.Config.MODULE]
sys.path.insert(0, os.getcwd()) sys_path = list(sys.path)
# only import the module if it exists. If a module spec exists then sys.path.clear()
# the module exists. sys.path.append(os.getcwd())
spec = find_spec(constants.Config.MODULE) try:
cwd = Path(os.getcwd()).resolve() # only import the module if it exists. If a module spec exists then
if not spec or ( # the module exists.
# Config module path must be relative to the working directory. spec = find_spec(constants.Config.MODULE)
(spec.origin is not None) if not spec:
and not Path(spec.origin).resolve().is_relative_to(cwd) # we need this condition to ensure that a ModuleNotFound error is not thrown when
): # running unit/integration tests or during `reflex init`.
# we need this condition to ensure that a ModuleNotFound error is not thrown when return Config(app_name="")
# running unit/integration tests or during `reflex init`. rxconfig = importlib.import_module(constants.Config.MODULE)
return Config(app_name="") return rxconfig.config
rxconfig = importlib.import_module(constants.Config.MODULE) finally:
return rxconfig.config sys.path.clear()
sys.path.extend(sys_path)