Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saving the VCS Checkout dir path to an environment variable #564

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/taskgraph/transforms/run/run_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,17 @@ def common_setup(config, task, taskdesc, command):
)

vcs_path = taskdesc["worker"]["env"]["VCS_PATH"]

try:
primary_repo_path = taskdesc["worker"]["env"]["PRIMARY_REPO_PATH"]
except Exception:
primary_repo_path_exists = False
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will result in an exception because primary_repo_path_exists isn't defined if we don't get to this except clause. That said, you can remove this whole block, see my comment below.


for repo_config in repo_configs.values():
checkout_path = path.join(vcs_path, repo_config.path)
command.append(f"--{repo_config.prefix}-checkout={checkout_path}")
if primary_repo_path_exists is False or not primary_repo_path.strip():
taskdesc["worker"]["env"]["PRIMARY_REPO_PATH"] = checkout_path
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no need to check if the env was set above, Python dicts have a setdefault function that will only set the value if it doesn't already exist. E.g:

taskdesc["worker"]["env"].setdefault("PRIMARY_REPO_PATH", checkout_path)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is being executed for every loop in the for statement. You'll need to use the enumerate built-in function in the for loop to make sure you're only setting this variable on the first iteration. Otherwise, whatever is last in the list will overwrite whatever is earlier in the list.


if run["sparse-profile"]:
command.append(
Expand Down