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

Try relpath first, if failed use the user specified path #1337

Merged
merged 5 commits into from
Aug 23, 2019

Conversation

feldschlachtiv
Copy link
Contributor

For compatibility with Windows. relpath() fails when the specified path is on a different drive.

Issue #, if available: #1336

Description of changes: use abspath() instead of relpath(), so cli command succeeds even when running on windows where sam and build_dir/template are located on different drive.

Checklist:

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

For compatibility with Windows. relpath() fails when the specified path is on a different drive.
@feldschlachtiv feldschlachtiv changed the title use abspath instead of relpath Try relpath first, then abspath Aug 16, 2019
Copy link
Contributor

@sanathkr sanathkr 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 making this change. I have two minor comments, and then we should be good to go :)

output_template_path = os.path.relpath(ctx.output_template_path)
except ValueError:
LOG.debug("Failed to retrieve relpath - using abspath instead")
build_dir = os.path.abspath(ctx.build_dir)
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we got a ValueError computing relative path, I would just use the original path without computing absolute path.

# under Windows, when SAM and (build_dir or output_template_path) are
# on different drive, relpath() fails.
try:
build_dir = os.path.relpath(ctx.build_dir)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: can you rename build_dir and output_template_path to be something more descriptive? I just don't want someone to use these values without knowing what it means.

Also rename a couple of variables to be a little more descriptive.
@feldschlachtiv feldschlachtiv changed the title Try relpath first, then abspath Try relpath first, if failed use the user specified path Aug 22, 2019
@feldschlachtiv
Copy link
Contributor Author

@sanathkr - Thank you for your comment. I think your suggestion makes sense, so I made a couple of changes. Let me know your thoughts about it - especially the renaming looks in-line with what you meant?

@sanathkr
Copy link
Contributor

Appreciate the changes. Approved.

@sanathkr sanathkr added the stage/accepted Accepted and will be fixed label Aug 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stage/accepted Accepted and will be fixed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants