From 96724105ec77c6ba92db60d3f1ede24af1a3d858 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C3=A9cureuil?= Date: Thu, 23 Jan 2025 15:01:33 +0100 Subject: [PATCH] (replicator) Fix sys.path after using the module_needed function In the module_needed function we alter the path of the python modules. To be sure that we have no side effect, we revert this modification on the end of the function (cherry picked from commit ee7e7719333fd1c3469b4ff58d9d22463062eac5) --- pulse_xmpp_agent/replicator.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pulse_xmpp_agent/replicator.py b/pulse_xmpp_agent/replicator.py index c10ef2c4..e757c578 100755 --- a/pulse_xmpp_agent/replicator.py +++ b/pulse_xmpp_agent/replicator.py @@ -280,6 +280,7 @@ def prepare_folder_rollback(rollback_pulse_xmpp_agent, agent_folder): def module_needed(agent_image, verbose=False): + original_sys_path = sys.path.copy() # sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)))) # create file __init.py si non exist boolfichier = False @@ -316,6 +317,7 @@ def module_needed(agent_image, verbose=False): except BaseException: print("Error while deleting file __init__.py") if error: + sys.path = original_sys_path return False for filename in [ @@ -330,7 +332,9 @@ def module_needed(agent_image, verbose=False): print( f"Some python modules needed for running lib/{filename} are missing. We will not switch to new agent" ) + sys.path = original_sys_path return False + sys.path = original_sys_path return True