-
Notifications
You must be signed in to change notification settings - Fork 337
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
shebang and executable paths incorrect in gitbash #1302
Comments
I just noticed the gitbash plugin, but I can't seem to get it to work. No matter what I do I get: |
Good point about the spaces. I think the solution might be to use DOS short paths: |
We had a bit of a discussion about this on Slack already. This needs to be fixed for good as this is only the default but other paths might also need escaping. We need proper cross platform escaping to really fix this in my eyes. |
(Adding quotes works in gitbash but not in rez. I think that they are stripped by rez when sanitizing?) |
Interesting, I tried using that DOS shortpath and it got a different error. So my
It seems to be because the path is using ; as pathsep, not :
There were other unrelated syspaths in there but I removed them to shorten the example. Whereas if I exit rez and echo $PATH:
It's closer than I've gotten before, but I still can't get it to handle the paths correctly. |
Ah good point. Had not thought about pathsep |
Just to give some quick background, the gitbash plugin is based on work I did to get executor_path = executor.env.PATH.value()
executor_path = re.sub(r'([a-zA-Z]):\\', r'/\g<1>/', executor_path)
executor_path = executor_path.replace('\\', '/')
executor_path = executor_path.replace(';', ':')
executor.env.PATH = executor_path Essentially the |
PYTHONPATH needs to be DOS style because the python process is a windows process. PATH needs to be POSIX because of bash. Note that is just from stuff I've read in the past. This path replacement is very fragile and is one reason why I was against it (and I'm still is). |
Some reading: https://www.msys2.org/docs/filesystem-paths/ |
So, git-bash is an example of a shell that requires path normalization - when in a bash shell, (eg) So I don't see how we can avoid normalization - if we do, we're simply making package commands unintentionally platform and/or shell- specific (and the whole idea is not to be!). However, Is this not just a case then of changing the default value of the new setting https://github.com/AcademySoftwareFoundation/rez/wiki/Configuring-Rez#pathed_env_vars to In any case, I don't think fixing this is as simple as adding the Currently I'm a little confused about where we are on this as there seem to be multiple overlapping things going on:
|
Thinking on this further, I think there's some more things to take into consideration:
|
For what it's worth, I've decided to look into Cmder which extends cmd with bash-like commands, rather than try to get git-bash to work. I've made a cmder-rez plugin, which I can share if anyone is interested. Edit: The reason behind this decision is that we feel it's safer to use a windows-native shell. So rather than try to get git-bash to work with rez, it makes more sense to extend cmd. Here is the cmder-rez plugin for anyone curious. |
Pinging this thread as would be good to get movement. @JeanChristopheMorinPerso - you mention that "This path replacement is very fragile and is one reason why I was against it (and I'm still is)." - but the git-bash shell requires this. Is there something else you had in mind? @amorphousWaste - clarification still needed on #1303 as to specifically what problem it fixes and how. Is it actually the space in path (ala It seems to me that PATH might be the only var that needs to be shell-normalised. For all other cases (eg PYTHONPATH), it's platform normalization that should happen, and it seems likely that this could simply default to What I have in mind is something like this (config settings):
|
@nerdvegas I completely forgot to explain what I was thinking about. Sorry for that. I think we could probably give https://www.msys2.org/docs/filesystem-paths/ a read (and I encourage everyone to do it). That's the first thing I'd do. I have a feeling it's a "solved" problem. I'd removed the pathed_env_vars setting all together at the global level and rely on
Unfortunately not. What about rez packages that contain bash scripts that don't call any windows executable that would stil require custom environment variables that would contain paths? We should probably still need to take into considerations that not just def commands():
# Instead of "env.MY_CUSTOM_PATH_ENV = 'value here', we could add a new
# 'set' method on the variables where a user could explicitly mark an environment variable as
# safe to convert/sanitize. This would cover cases where a package contains bash scripts
# that rely on custom environment variables that are not path lists and or
# that does not contains the name "PATH".
env.MY_CUSTOM_ENV_VAR.set('{root}/something', convert=True)
# Same for append and prepend.
env.MY_CUSTOM_ENV_VAR_OTHER.append('asd', convert=True)
env.MY_CUSTOM_ENV_VAR_OTHER_2.prepend('asd', convert=True) Going explicit like this would allow packages to control how environment variables should be handled. Though, I'm not sure how doable this is as I haven't played much with the internals of rex. And also note that I haven't put a huge amount of thoughts into this I also think the responsibility of sanitizing paths should be delegated to shell plugins. This means bash, powershell and others wouldn't be affected by any logic required by git-bash. This would make the implementation less fragile IMO. I'd particularly be happy with a solution that uses Lastly we could reach out to the cygwin and or msys2 folks for guidance on how this could be handled. |
Cheers for the link jc I just checked it out. Generally I think we're on the right path (pun intended). A few things:
One more thing. Perhaps instead of this
What I specifically like about this approach is that it can be used to deal with other edge cases. For example, your commands might source a script which sets a path into an env-var, which you then need to shell-normalize. With just the |
I created a new PR because I messed up the commits on the old one here: #1364 This should fix the issues with gitbash as well as addressing the concerns with pathing and using the config for that. Pathing has been moved to the individual shell plugins with different options depending on whether the plugin needs to use a shell path or differently formatted path. The config is not used at all. Please let me know if these are the sought after changes or if more work is needed. |
Apologies for not looking into this yet, have not had the time recently. I'm not clear on where we're at - my last comment in this thread was left hanging and there was no further discussion. To reiterate and tl;dr from memory:
I want to be clear on agreed approach before reviewing code. |
It makes sense to me, I've just decided to move away from gitbash so it's not as relevant for me anymore. |
Hi @nerdvegas, thanks for looking into it again. I've been testing the PR and from a gitbash user's perspective the behavior has been largely addressed with the current changes except for a couple minor things which I've relayed to @amorphousWaste. Briefly, what I'm experiencing is that the new posix paths that the gitbash plugin is normalizing to '/a/b/c' with ':' pathseps are working well except for PYTHONPATH where the windows python binary expects 'C:/a/b/c' with ';' pathseps. I have enabled ';' pathseps for PYTHONPATH in the config so all that is left is to replicate My experience with cmake also has been much better with the current changes. The only other minor thing I'm experiencing that is breaking some tests and inconsistent with |
OK, I think this PR should now address all the issues with gitbash pathing. It can be configured in the config.py file and implemented on a per-shell basis or not at all. |
@amorphousWaste please keep the discussions related to the PR in the PR. It's hard to keep track of comments related to PRs when they are made in issues. |
I never brought it to finish but I worked on this a while back: It adds missing semantics for variables to the configuration, so that platform cases can be handled centrally for each environment variable. It can also handle some of the problems mentioned, like CMAKE behaving non-standard in Windows (uses semicolon as separator but expects posixpath-like paths) etc. "CMAKE_MODULE_PATH": {
"parent_variables": "clear",
"pathsep": ";",
"modify_op": "posixpath",
}, It also solves the issue of certain variables needed to be inherited or cleared from a calling environment, where rez variables land (before or after inherited variables), can make platform dependent choices, and most importantly gives that control back to the user so we don't have to hard-code anything while we can still provide sane defaults. Maybe worth revisiting the idea because I remember that we pulled back and forth to fix windows env var issues, but the problem is that certain clients have certain expectation towards certain environment variables, and they don't always coincide with what the operating system expects. It would actually support mentioned functions to normalize/append in a particular way, but would be configurable and over-writable. Centrally because having the logic of how to add to environment variables in individual packages is a maintenance nightmare and should not differ for a single variable/environment anyway. I liked this approach better than extending the |
Hey @bfloch , thanks for remembering us of that issue! I'll have to carve some time out to read it carefully (with #739 too).
Extending |
Re-reading your comment - I think it is the same idea. The difference is the level: I don't believe that every environment variable is responsibility of the shell as not every variable follows the shell concatenation and normalization rules. My proposal spawned off the CMAKE_MODULE_PATH case which independent of platform/shell behaves by their rules. What I wanted to achieve is similar: Have the packages only define their intent: Add to the variable - and let a global config handle the rest of understanding what it means. The global default for un-specified variables means that the semantics do not change much. Maybe it is worth adding something along "ShellDependent" to #739 but I think that the approach of a config is not that bad. Since environment variables are by definition a shared resource - the nice thing is that they do generally apply to all packages. Hope you find some time to re-read both PRs. I might check if I can find some time to revisit them if the approach is deemed sound by the TSC. Another aspect it addresses is to define how to handle parent process variables - which is outside of the scope of this issue, but also worth exploring. |
When creating a rez environment with gitbash on Windows, the shebang and executable paths use a single slash which gets escaped and causes the paths to be incorrect.
Environment
To Reproduce
rez-env
Expected behavior
Taken into a rez environment.
Actual behavior
Command not found error
The text was updated successfully, but these errors were encountered: