From 8d8939fb67783e66c7dce66d194c72728a3c854b Mon Sep 17 00:00:00 2001 From: Rishabh Sharma Date: Wed, 20 Mar 2024 13:28:02 -0700 Subject: [PATCH] DVC_STAGE: Added environment variable to track DVC stage name (#10357) DVC_STAGE_NAME: Added environment variable to track DVC stage name Fixes #10355 Co-authored-by: Rishabh Sharma --- dvc/env.py | 1 + dvc/stage/run.py | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/dvc/env.py b/dvc/env.py index 72c5b89006..af36342dc3 100644 --- a/dvc/env.py +++ b/dvc/env.py @@ -19,3 +19,4 @@ DVC_SQLALCHEMY_ECHO = "DVC_SQLALCHEMY_ECHO" DVC_SYSTEM_CONFIG_DIR = "DVC_SYSTEM_CONFIG_DIR" DVC_UPDATER_ENDPOINT = "DVC_UPDATER_ENDPOINT" +DVC_STAGE = "DVC_STAGE" diff --git a/dvc/stage/run.py b/dvc/stage/run.py index 250c5c4d37..40369780eb 100644 --- a/dvc/stage/run.py +++ b/dvc/stage/run.py @@ -39,7 +39,7 @@ def _enforce_cmd_list(cmd): def prepare_kwargs(stage, run_env=None): - from dvc.env import DVC_ROOT + from dvc.env import DVC_ROOT, DVC_STAGE kwargs = {"cwd": stage.wdir, "env": fix_env(None), "close_fds": True} @@ -48,6 +48,9 @@ def prepare_kwargs(stage, run_env=None): if DVC_ROOT not in kwargs["env"]: kwargs["env"][DVC_ROOT] = stage.repo.root_dir + # Create DVC_STAGE env variable for every command + kwargs["env"][DVC_STAGE] = stage.addressing + # NOTE: when you specify `shell=True`, `Popen` [1] will default to # `/bin/sh` on *nix and will add ["/bin/sh", "-c"] to your command. # But we actually want to run the same shell that we are running