From 8a2e6dc4a88ebd6be9c53950a27ae6f965101bb2 Mon Sep 17 00:00:00 2001 From: Shashank Srikanth Date: Mon, 11 Aug 2025 21:48:03 -0700 Subject: [PATCH] Add option to ignore parent proc env vars in runner/deployer --- metaflow/runner/deployer_impl.py | 7 ++++++- metaflow/runner/metaflow_runner.py | 8 ++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/metaflow/runner/deployer_impl.py b/metaflow/runner/deployer_impl.py index f0f8143f25b..074dbb20567 100644 --- a/metaflow/runner/deployer_impl.py +++ b/metaflow/runner/deployer_impl.py @@ -40,6 +40,10 @@ class variable that matches the name of the CLI group. directory is used. file_read_timeout : int, default 3600 The timeout until which we try to read the deployer attribute file (in seconds). + extend_existing_env : bool, default True + If True, the environment variables from the current process are extended + with the ones specified in `env`. If False, the environment variables + specified in `env` will be used as the only environment variables **kwargs : Any Additional arguments that you would pass to `python myflow.py` before the deployment command. @@ -55,6 +59,7 @@ def __init__( env: Optional[Dict] = None, cwd: Optional[str] = None, file_read_timeout: int = 3600, + extend_existing_env: bool = True, **kwargs ): if self.TYPE is None: @@ -88,7 +93,7 @@ def __init__( self.cwd = cwd or os.getcwd() self.file_read_timeout = file_read_timeout - self.env_vars = os.environ.copy() + self.env_vars = os.environ.copy() if extend_existing_env else {} self.env_vars.update(self.env or {}) if self.profile: self.env_vars["METAFLOW_PROFILE"] = profile diff --git a/metaflow/runner/metaflow_runner.py b/metaflow/runner/metaflow_runner.py index 84eb8ac4284..eca7bd15352 100644 --- a/metaflow/runner/metaflow_runner.py +++ b/metaflow/runner/metaflow_runner.py @@ -262,6 +262,10 @@ class Runner(metaclass=RunnerMeta): directory is used. file_read_timeout : int, default 3600 The timeout until which we try to read the runner attribute file (in seconds). + extend_existing_env : bool, default True + If True, the environment variables from the current process are extended + with the ones specified in `env`. If False, the environment variables + specified in `env` will be used as the only environment variables **kwargs : Any Additional arguments that you would pass to `python myflow.py` before the `run` command. @@ -275,6 +279,7 @@ def __init__( env: Optional[Dict[str, str]] = None, cwd: Optional[str] = None, file_read_timeout: int = 3600, + extend_existing_env: bool = True, **kwargs ): # these imports are required here and not at the top @@ -311,8 +316,7 @@ def __init__( self.flow_file = flow_file self.show_output = show_output - - self.env_vars = os.environ.copy() + self.env_vars = os.environ.copy() if extend_existing_env else {} self.env_vars.update(env or {}) if profile: self.env_vars["METAFLOW_PROFILE"] = profile