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

Fix shebang and executable paths in gitbash #1364

Conversation

amorphousWaste
Copy link

@amorphousWaste amorphousWaste commented Aug 20, 2022

Fixes #1302.

Originally, I thought "shebang and executable paths incorrect in gitbash" was the cause of issues when working with rez in gitbash/Windows, however after investigation and discussion, there were much deeper issues. This PR addresses issues with pathing by adding multiple options for pathing to the needed shells and executor classes.

With these options, complex shell implementation can choose to use differently converted paths for different reasons.

Signed-off-by: amorphousWaste <20346603+amorphousWaste@users.noreply.github.com>
With these options, complex shell implementation can choose to use differently converted paths for different reasons.

Signed-off-by: amorphousWaste <20346603+amorphousWaste@users.noreply.github.com>
With these options, complex shell implementation can choose to use differently converted paths for different reasons.

Signed-off-by: amorphousWaste <20346603+amorphousWaste@users.noreply.github.com>
This is for working with non-posix paths.

Signed-off-by: amorphousWaste <20346603+amorphousWaste@users.noreply.github.com>
Allows for working with Windows drive directories like posix root paths.

Signed-off-by: amorphousWaste <20346603+amorphousWaste@users.noreply.github.com>
Fixes issues with spaces in names.

Signed-off-by: amorphousWaste <20346603+amorphousWaste@users.noreply.github.com>
Signed-off-by: amorphousWaste <20346603+amorphousWaste@users.noreply.github.com>
With these options, complex shell implementation can choose to use differently converted paths for different reasons.

Signed-off-by: amorphousWaste <20346603+amorphousWaste@users.noreply.github.com>
Signed-off-by: amorphousWaste <20346603+amorphousWaste@users.noreply.github.com>
@JeanChristopheMorinPerso
Copy link
Member

@amorphousWaste we will be happy to get the fixes for the linter, but I think it would be more appropriate if it was done in a separate PR.

@maxnbk
Copy link
Contributor

maxnbk commented Aug 20, 2022

linting fixes can be placed against this issue.
#1356

@JeanChristopheMorinPerso JeanChristopheMorinPerso changed the title Fixes #1302 Fix shebang and executable paths in gitbash Aug 20, 2022
Signed-off-by: amorphousWaste <20346603+amorphousWaste@users.noreply.github.com>
@amorphousWaste
Copy link
Author

My apologies. I misunderstood the workflow checks and thought that linting was blocking the PR. It has been removed.

@nerdvegas
Copy link
Contributor

For visibility please see recent comments: #1302
Would be good to clear this one up, it's been kicking on for a bit.

@amorphousWaste amorphousWaste requested a review from a team as a code owner September 22, 2022 23:02
Signed-off-by: amorphousWaste <20346603+amorphousWaste@users.noreply.github.com>
Signed-off-by: amorphousWaste <20346603+amorphousWaste@users.noreply.github.com>
Signed-off-by: amorphousWaste <20346603+amorphousWaste@users.noreply.github.com>
Add check and key conversion for shell pathed key based on arg

Signed-off-by: amorphousWaste <20346603+amorphousWaste@users.noreply.github.com>
Signed-off-by: amorphousWaste <20346603+amorphousWaste@users.noreply.github.com>
Signed-off-by: amorphousWaste <20346603+amorphousWaste@users.noreply.github.com>
@JeanChristopheMorinPerso
Copy link
Member

@amorphousWaste can you update the PR description please to give us an overview of how all this is used, describe what has been tested, potential gray areas, areas not covered, etc please?

That would be greatly appreciated!

@amorphousWaste
Copy link
Author

This update to the PR adds the functionality of choosing whether or not to modify paths and shell paths via the rezconfig.py on a per-shell and per-variable basis. The implementation is delegated to the shell plugin so that how the paths are changed or not is up to the shell. This will apply to environment building and package building. This should conform the previous fixes to fit the points brought up in the various conversations. All previous tests pass in CMD, PowerShell, and Gitbash on Windows. Gitbash has been a struggle to implement and further grey areas are unknown. Hopefully, this will give Gitbash the same functionality as existing shells with no further caveats.

Signed-off-by: amorphousWaste <20346603+amorphousWaste@users.noreply.github.com>
Signed-off-by: amorphousWaste <20346603+amorphousWaste@users.noreply.github.com>
@JeanChristopheMorinPerso
Copy link
Member

Thanks @amorphousWaste for walking us through your PR during the TSC meeting. Here are the points we would like to see be implemented before we can merge this PR:

  • Add a feature flag so that we can have the feature disabled by default. This would be off for a while until we are fully confident that things are working as expected. And it would also help when troubleshooting issues.
  • Add logs that will tell us which environment variable were normalized and the paths.
  • Add comments in the shell scripts for each normalized paths (or environment variables) affected.
  • Add tests.

Signed-off-by: amorphousWaste <20346603+amorphousWaste@users.noreply.github.com>
Signed-off-by: amorphousWaste <20346603+amorphousWaste@users.noreply.github.com>
Signed-off-by: amorphousWaste <20346603+amorphousWaste@users.noreply.github.com>
Signed-off-by: amorphousWaste <20346603+amorphousWaste@users.noreply.github.com>
Signed-off-by: amorphousWaste <20346603+amorphousWaste@users.noreply.github.com>
Add path conversion info into file.

Signed-off-by: amorphousWaste <20346603+amorphousWaste@users.noreply.github.com>
@JeanChristopheMorinPerso
Copy link
Member

Hi @amorphousWaste , I see you pushed some new commits to the PR. What's the state of things right now? Can see start reviewing or there is still more work to do before it's ready to review?

Signed-off-by: Jean-Christophe Morin <38703886+JeanChristopheMorinPerso@users.noreply.github.com>
@maxnbk
Copy link
Contributor

maxnbk commented Feb 12, 2023

Just want to write that during the last TSC meeting (january) that @amorphousWaste mentioned that the PR is ready for review and testing by interested parties.

@JeanChristopheMorinPerso registered interest in reviewing, and @instinct-vfx registered willingness to try throwing it in front of a few tester individuals in a studio environment, though I imagine that is subject to the whims and priorities of the studio.

@JeanChristopheMorinPerso
Copy link
Member

@maxnbk I am actively reviewing this PR. I've been doing for a couple of hours now. I should be done today.

Copy link
Member

@JeanChristopheMorinPerso JeanChristopheMorinPerso 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 all your work on this @amorphousWaste! I did a first pass on this. There is some things to fix, but the other things are mostly questions, comments, notes, etc.

Note that I haven't tested it yet.

Apart from that, we requested to add some tests. I see some tests were added, but they are pretty light. The path normalization functions are not well covered, corner cases aren't unit tested, etc. I'd also love to see real integration tests, i.e. have packages that we build, resolve in multiple shells and verify that everything looks like it should work works as expected.

Lastly, it's missing documentation. I believe @jasoncscott volunteered to help on that? I would see a new section of our wiki dedicated to that, with example, explanations, etc.

# as a result of both the shell and the settings in "pathed_env_vars" and
# "shell_pathed_env_vars". This is meant to aid in debugging and should be
# False unless needed.
disable_normalization = False

Choose a reason for hiding this comment

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

I would call it disable_path_normalization, also it should be set to True so that it's disabled by default.

@@ -261,6 +261,10 @@ def as_path(self, path):
Returns:
(str): Transformed file path.
"""
# Prevent path conversion if normalization is disabled in the config.
if config.disable_normalization:

Choose a reason for hiding this comment

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

Could this be done in the normalize_path path instead?

converted_path = convert_path(path, 'windows')
if path != converted_path:
print_debug(
'Path converted: {} -> {}'.format(path, converted_path)

Choose a reason for hiding this comment

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

How about Path normalized? Also, both converted and changed are used. I think we should make sure the message is consistent. Lastly, I'd use {!r} to automatically quote the paths. This usually helps with debugging whitespace issues, etc.


return path
if path != new_path:
print_debug('Path converted: {} -> {}'.format(path, new_path))

Choose a reason for hiding this comment

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

Won't this cause duplicate logs? Should the responsibility to log be of the caller or the callee? In general the responsibility is delegated to the caller, but we could say that in this case it's the callee.


if path != converted_path:
self._addline(
'REM Path converted: {} -> {}'.format(

Choose a reason for hiding this comment

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

Again, converted vs changed.

"""
Git Bash (for Windows) shell
"""
"""Git Bash (for Windows) shell."""

Choose a reason for hiding this comment

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

Small note: Please avoid unnecessary formatting changes.


return super(GitBash, self).normalize_paths(value2)
def shebang(self):
self._addline('#! /usr/bin/env bash')

Choose a reason for hiding this comment

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

Suggested change
self._addline('#! /usr/bin/env bash')
self._addline('#!/usr/bin/env bash')

config.override('disable_normalization', True)

test_path = r'C:\foo\bar\spam'
normalized_path = shell.normalize_path(test_path)

Choose a reason for hiding this comment

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

shell is a string, which cause the test to fail with

AttributeError: 'str' object has no attribute 'normalize_path' (in shell 'bash')

if shell_name not in config.shell_pathed_env_vars:
return False

return any(

Choose a reason for hiding this comment

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

This is not covered by any tests

@@ -1359,7 +1422,7 @@ def normalize_path(self, path):
Returns:
str: The normalized path.
"""
return self.interpreter.normalize_path(path)
return self.interpreter.as_path(path)

Choose a reason for hiding this comment

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

This is not covered by any tests. It could be a good occasion to add coverage here.

@JeanChristopheMorinPerso JeanChristopheMorinPerso marked this pull request as ready for review February 12, 2023 18:59
@JeanChristopheMorinPerso JeanChristopheMorinPerso requested a review from a team as a code owner February 12, 2023 18:59
@JeanChristopheMorinPerso
Copy link
Member

Hey @amorphousWaste @Jawabiscuit , would one of you be willing and have time to pick this up again? If not, please let us know so that we can see if we can find someone else that might be interested.

This PR is important for our community, so we would like to get things moving.

@Jawabiscuit
Copy link

@JeanChristopheMorinPerso yeah, definitely trying to carve out some time in the near future to revisit this.

I'm wrapping up an extended effort for Linux/Windows Deadline rendering, which also incorporates rez. I'm better positioned now to take another look and continue with the converting to rez on Windows effort soon.

I've enabled gitbash on Windows for myself at least since the last meeting to verify our experience and it has been stable for me working as a developer. Beginning next week I should be able to get more than just me testing and take a look at the comments on this PR in more detail.

I defer to @amorphousWaste on what his plans are, but happy to jump in and take it home if he's preoccupied.

@JeanChristopheMorinPerso
Copy link
Member

Great news @Jawabiscuit! Just let us know how we can help and of your plans change.

@predat
Copy link
Contributor

predat commented Mar 5, 2023

If I may put my two cents in, i was able to build zlib library with cmake & msvc like i do on linux with a CMakeLists.txt with this PR.

def test_path_conversion_mixed(self):
"""Test the path conversion to mixed style."""
test_path = r'C:\foo\bar\spam'
converted_path = convert_path(test_path, 'unix')
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this the same test as the previous one? Should it be testing mixed?

@JeanChristopheMorinPerso
Copy link
Member

Closing in favor of #1475.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
os:windows Windows-specific
Projects
None yet
Development

Successfully merging this pull request may close these issues.

shebang and executable paths incorrect in gitbash
7 participants