Skip to content
New issue

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

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

Already on GitHub? # to your account

fix[ux]: fix relpath compiler panic on windows #4228

Merged
merged 2 commits into from
Oct 4, 2024

Conversation

charles-cooper
Copy link
Member

@charles-cooper charles-cooper commented Sep 6, 2024

fix a bug where relpath raises an exception on window, when the source path and the destination path are on different drives.

What I did

fix #4227

How I did it

How to verify it

Commit message

fix a bug where `os.path.relpath()` raises an exception on window
- when the source path and the destination path are on different
drives. this commit introduces the helper function `safe_relpath()`,
which tries hard to construct a relpath (using `os.path.relpath()`),
but falls back to the original path (which might be an absolute path)
instead of raising an exception.

references:
- https://docs.python.org/3/library/os.path.html#os.path.relpath

Description for the changelog

Cute Animal Picture

Put a link to a cute animal picture inside the parenthesis-->

fix a bug where relpath raises an exception on window, when the source
path and the destination path are on different drives.
Copy link

codecov bot commented Sep 6, 2024

Codecov Report

Attention: Patch coverage is 83.33333% with 2 lines in your changes missing coverage. Please review.

Project coverage is 90.36%. Comparing base (9a208a6) to head (7ba1972).

Files with missing lines Patch % Lines
vyper/utils.py 66.66% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4228      +/-   ##
==========================================
- Coverage   91.35%   90.36%   -0.99%     
==========================================
  Files         109      109              
  Lines       15637    15641       +4     
  Branches     3443     3443              
==========================================
- Hits        14285    14134     -151     
- Misses        920     1043     +123     
- Partials      432      464      +32     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

try:
return os.path.relpath(path)
except ValueError:
# on Windows, if path and curdir are on different drives, an exception
Copy link
Member

Choose a reason for hiding this comment

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

Would the path be an absolute path in this scenario?

Copy link
Collaborator

@cyberthirst cyberthirst Sep 16, 2024

Choose a reason for hiding this comment

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

yeah, I'm not sure about this

the reported issue targeted builtins, which use __path__, which is absolute, and thus, the approach should work. although safe_relpath which returns an abs path is a bit weird

but it might be that a relative path is in search paths, right? And that path could reference a different drive causing the exception. but in that case it's likely a user error?

Copy link
Member Author

Choose a reason for hiding this comment

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

relpath is also used even if a different search path is used to resolve a path, for instance for error reporting it is used to report relative to the user's current directory. but on windows if you can't construct the relpath, you can't construct the relpath

@charles-cooper charles-cooper enabled auto-merge (squash) October 4, 2024 20:09
@charles-cooper charles-cooper merged commit c7669bd into vyperlang:master Oct 4, 2024
156 checks passed
@charles-cooper charles-cooper deleted the fix/safe-relpath branch October 4, 2024 21:17
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Panic in Windows when running on different mounts
3 participants