From e0a8e8dedc68a57f0af15b91e20b1f170b774257 Mon Sep 17 00:00:00 2001 From: Khaleel Al-Adhami Date: Tue, 19 Nov 2024 16:03:10 -0800 Subject: [PATCH] modify sys path --- reflex/config.py | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/reflex/config.py b/reflex/config.py index 0955d24b9..ef48895ea 100644 --- a/reflex/config.py +++ b/reflex/config.py @@ -812,18 +812,19 @@ def get_config(reload: bool = False) -> Config: if reload and constants.Config.MODULE in sys.modules: del sys.modules[constants.Config.MODULE] - sys.path.insert(0, os.getcwd()) - # only import the module if it exists. If a module spec exists then - # the module exists. - spec = find_spec(constants.Config.MODULE) - cwd = Path(os.getcwd()).resolve() - if not spec or ( - # Config module path must be relative to the working directory. - (spec.origin is not None) - 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`. - return Config(app_name="") - rxconfig = importlib.import_module(constants.Config.MODULE) - return rxconfig.config + sys_path = list(sys.path) + sys.path.clear() + sys.path.append(os.getcwd()) + try: + # only import the module if it exists. If a module spec exists then + # the module exists. + spec = find_spec(constants.Config.MODULE) + if not spec: + # we need this condition to ensure that a ModuleNotFound error is not thrown when + # running unit/integration tests or during `reflex init`. + return Config(app_name="") + rxconfig = importlib.import_module(constants.Config.MODULE) + return rxconfig.config + finally: + sys.path.clear() + sys.path.extend(sys_path)