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

Implement #1196 #1199

Conversation

instinct-vfx
Copy link
Contributor

This is a work in progress PR to implement #1196. Initial prototype done by @davidlatwe has been integrated here as a start.

@instinct-vfx instinct-vfx added bug os:windows Windows-specific labels Feb 8, 2022
@instinct-vfx
Copy link
Contributor Author

I need to clean up the code because i think it uses an older version of the plugin as base (still using $Env instead of Set-Item). Will do so today and try to move this out of WIP status. This actually solves another issue for me where on some Machines rez fails to get_syspath when already in a rez created shell. This seems to also fix this issue.

@instinct-vfx
Copy link
Contributor Author

Added License text back and removed the now unused ENV_VAR_REGEX

@instinct-vfx instinct-vfx marked this pull request as ready for review February 11, 2022 13:08
@instinct-vfx
Copy link
Contributor Author

Updated with current master

@instinct-vfx
Copy link
Contributor Author

So i consider this ready to be merged now. Thanks again @davidlatwe for helping find the remaining issue (see last commit reverting one of the changes). Tests are all green now, in addition to the Actions all running successfully i also checked locally that tests run fine with python 3.x.

@nerdvegas
Copy link
Contributor

Hey Thorsten,

Any chance we can get a TL;DR on this? I'm still not quite sure of the whole picture on this one, and info seems to be fairly scattered.

I'm specifically not clear on the ENV_VAR_REGEX override. This regex is used to convert env-var refs in package commands (ie non-shell-specific) into shell-specific representation (via convert_tokens). However, (and confusingly) the docstring on ENV_VAR_REGEX suggests it may be extended to support shell-specific forms.

I just want to be sure that this fix isn't a fix for the wrong reasons, if you see what I mean?

Thx
A

@instinct-vfx
Copy link
Contributor Author

instinct-vfx commented Feb 22, 2022

Hey Allan,

yes totally and sorry for the lack of context. The ENV_VAR_REGEX is not introduced by this PR. I had removed it because i thought it was not needed anymore after the changes to get_syspaths (i was not aware this was also used in shells.py for example).

The TL;DR is changing get_syspaths to use PowerShell to get the PATH variable contents.

There are two reasons for this: First, the old implementation used the REG command line tool that ships with windows and then parses the result. On the one hand this is less stable than the new implementation because the output of REG is not directly parseable and as you can tell by the RegEx there are at least two different variants that are accounted for already.

Secondly - and the bigger issue - this actually breaks in certain constellations when you call rez from a rez shell (in PowerShell / PowerShell Core). This is because it is not a built in command of cmd.exe or PowerShell but an actual executable (like doskey for the alias command in cmd.exe).

In addition i think this will also solve an issue that Chad Vernon reported on Slack where in their environment using REG is blocked by IT whereas the PowerShell commands worked (at least directly in a shell).

In regards to ENV_VAR_REGEX I think this is beyond the scope of this PR to introduce any changes there so i reverted it to the state it was before and now the only change is get_syspaths

@nerdvegas
Copy link
Contributor

Ah right yes, sorry I did check ENV_VAR_REGEX in master and yes it was already there, I didn't see it and thought it had been added in this PR.

I agree that it's outside the scope of this PR, but I'm left wondering why we did this. Let's address this in #1233

"HKEY_CURRENT_USER\\\\Environment", "PATH", "REG_(EXPAND_)?SZ",
"(.*)"
])
cmd = ["powershell", "(Get-ItemProperty -Path HKCU:Environment).Path"]
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we could collapse this into a loop over the two different powershell calls and get rid of some code here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nerdvegas Also a good point, i changed that, please check again if the new version is okay for you

Copy link
Contributor

@nerdvegas nerdvegas left a comment

Choose a reason for hiding this comment

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

see inline comments

@nerdvegas
Copy link
Contributor

oh I think maybe you accidentally reintroduced the shell=True when refactoring into a loop?

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@instinct-vfx
Copy link
Contributor Author

You are totally right. It's 1am already, i should have pushed this to tomorrow i guess. sigh I THINK i got it all corrected now, tests are still passing and formatting is fixed too. Sorry for the additional loops.

@nerdvegas nerdvegas merged commit 53a447e into AcademySoftwareFoundation:master Feb 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug os:windows Windows-specific
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants