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

Conversation

gshiva53
Copy link

Hi, This is my first pull request for a good first issue #9. Please do let me know if the env path where I am saving the checkout-dir path is incorrect. I would love any feedback on my pull request.

@@ -82,6 +82,7 @@ def common_setup(config, task, taskdesc, command):
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}")
taskdesc["worker"]["env"]["VCS_CHECKOUT_DIR_PATH"] = checkout_path
Copy link
Collaborator

@ahal ahal Aug 18, 2024

Choose a reason for hiding this comment

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

Thanks for the patch! This is close, but there are a couple things to fix:

  1. Can we call the env PRIMARY_REPO_PATH instead?
  2. If there are multiple entries in repo_configs, later entries will overwrite the earlier ones. Instead, I think we should only save the first entry in the repo_configs. So we should only save the env if it doesn't exist yet.
  3. It looks like this causes the tests to fail. You'll need to fix that up before this can land. This should be a matter of updating the expectations, though it looks like the tests also set repo_config.path to an empty string.. it would be nice to change them to use a proper value here as well.

Thanks for your interest and please don't hesitate to reach out if you need help with any of this.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for your message, I really appreciate the feedback.

  1. Changed the path var name.
  2. Added a check to see if a checkout dir path already exists, it will only save if the dir path does not exist.
  3. I am a bit unsure of how to change the repo_config.path to some meaningful value. I looked at the failing tests and it seems like it's primarily because the task is unable to run. So, multiple tests fail for the same reason it seems.

I would love to make any further changes if required. Thanks again for your feedback.

Copy link
Collaborator

@ahal ahal left a comment

Choose a reason for hiding this comment

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

Thanks for the changes! There's an issue with the for loop and a simplification that you can make however. Please see the in-line comments

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}")
primary_repo_path = taskdesc["worker"]["env"]["PRIMARY_REPO_PATH"]
if primary_repo_path is None or not vcs_path.strip():
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)

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}")
primary_repo_path = taskdesc["worker"]["env"]["PRIMARY_REPO_PATH"]
if primary_repo_path is None or not vcs_path.strip():
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.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants