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

Enhancements for shell plugins #698

Merged

Conversation

bfloch
Copy link
Contributor

@bfloch bfloch commented Aug 26, 2019

This fixes and improves the shell plugins, especially on Windows for cmd and PowerShell-like.
Formally excluded shell dependent tests are now passing.

I would love to have someone run the test-suite on MacOS.

Future work

  • Better Visual Studio handling in CMake for Windows
  • Remove dependency of pwsh on SH-class for get_syspaths under Linux

Fixes

Features / Enhancements

  • Added get_all_key_tokens to allow for multiple key-forms

  • Added convert_tokens to normalize token forms to shell specific form

  • Allow pwsh shell on Linux (and pass tests)

  • Implements optional script execution on windows via PATHEXT.

    • Windows shells may add custom PATHEXT values in plugin config file
    • create_executable_script now returns list of created scripts based on config.create_executable_script_mode:
      • single (default) Just create the requested script. Usually extension-less.
      • py create .py script that will allow launching scripts on windows,
      • platform_specific will create .py script on windows and requested on other platforms
      • both creates the requested file and a .py script for windows
  • Introduced Shell specific regex parsing to handle ambiguous case like set PATH=$ENV:VAR in PowerShell vs. Bash within the NamespaceFormatter

  • Introduced printout of shell name for shell_dependent test failure

Tests passing

Backwards compatibility

  • Fully backwards compatible, new features use config options default to current behaviour
  • Shell Plugin API has been extended slightly.
    • Implement get_all_key_tokens(key) (with safest/common form at index 0)
    • Implement line_terminator() for shell/platform specific line_terminator as expected by the shell
    • join now a class method
    • Extend ENV_VAR_REGEX if needed with shell specific token forms
    • You can make use of new convert_tokens in you implementation of info and error

src/rezplugins/shell/cmd.py Outdated Show resolved Hide resolved
src/rez/rex.py Outdated Show resolved Hide resolved
src/rez/rezconfig.py Outdated Show resolved Hide resolved
src/rez/shells.py Outdated Show resolved Hide resolved
src/rez/util.py Outdated Show resolved Hide resolved
@bfloch
Copy link
Contributor Author

bfloch commented Aug 29, 2019

Thanks for the review. I'll dropped notes/questions and will look into the fixes.

@bfloch
Copy link
Contributor Author

bfloch commented Aug 29, 2019

I've updated the first post and addressed everything in your review.
One thing I could not solve is the SH reference in pwsh, but I limited the scope and added a proper comment with a reference how this might be solved upstream of pwsh.

Ran the tests again, pass as before.

@bfloch bfloch force-pushed the enhancements_for_shell_plugins branch 2 times, most recently from e626781 to 89acad7 Compare August 29, 2019 20:05
@maxnbk
Copy link
Contributor

maxnbk commented Aug 30, 2019

FYI, zsh tests on master should be fixed when #711 is merged in.
Notifying in case it matters for this PR.

@nerdvegas
Copy link
Contributor

I'm ready to merge this, but would like to hear RE OSX testing also. In the meantime I'm going to start looking at GitHub Actions, so we'll have this testing covered anyway (and across py2/3 also, which is going to become important pretty soon).

@nerdvegas nerdvegas mentioned this pull request Aug 31, 2019
2 tasks
@bfloch
Copy link
Contributor Author

bfloch commented Sep 5, 2019

FYI, zsh tests on master should be fixed when #711 is merged in.
Notifying in case it matters for this PR.

Cool will try merging this in. Thanks!

@bfloch
Copy link
Contributor Author

bfloch commented Sep 5, 2019

Will fix the conflict and I'll give the de-duplication on cmd another shot today.
Might have to do with shell=False again, not sure. The syntax certainly works within cmd sessions ...

EDIT: Got it to work with cmd. Only thing left is rebasing on latest master which should also have the zsh changes.

@bfloch bfloch force-pushed the enhancements_for_shell_plugins branch from 7bff0cf to d55b4f4 Compare September 6, 2019 15:30
…all shell tests.

This implements ${VAR} and $VAR variables for cmd and Powershell like, as
well as their native forms like %VAR% and $Env:VAR.
In order to handle the ambiguity of variables in the form of $Env:Literal
in Unix and Windows the NamespaceFormatter may take interpreter regex into
account that is being supplied by the underlying shell.

For command execution on Windows .PY is being added to the PATHEXT and
the create_script function is extended to create any form of execution
script. This behaviour can be controlled via a rezconfig, but defaults to
backwards compatible Unix-only behaviour.
This introduced quotation issues as detailed in AcademySoftwareFoundation#691

This reverts commit e513b69.

# Conflicts:
#	src/rezplugins/shell/cmd.py
It should be noted that according to [1] this is not an officially exposed
API, but in order to avoid License clearance for now I just used it similar
like we use pipes.quote in `shells.py`.
[1] https://bugs.python.org/issue10838
Line termination is not necessarirly platform dependent, but also shell
dependent.
Shells which do not use the generic ${VAR} or $VAR form should use
convert_token to convert to their native form.
This only assumes that a shell correctly extends ENV_VAR_REGEX to also
parse their own variables.
Also fixes spelling of attribute to conform to PowerShell style.
@bfloch bfloch force-pushed the enhancements_for_shell_plugins branch from d55b4f4 to e2f4242 Compare September 6, 2019 17:07
@bfloch
Copy link
Contributor Author

bfloch commented Sep 6, 2019

FYI, zsh tests on master should be fixed when #711 is merged in.
Notifying in case it matters for this PR.

Notable changes since your last review:

  • Fixed promp not expanded with cmd (probably because variable expansion now works properly)
  • Supressing PowerShell header
  • Added PATHEXT deduplication for cmd and PowerShell as suggested
  • Rebased on current master. Fixed the zsh failure as advertised. Thanks.

So now it is just a question if we want #707 first.
I guess since it technically does not rely on it and we do have quite a lot of changes here we should probably go ahead and merge it. At least we get some real feedback early on, while there still might be some design discussions happening in #707.

All tests (except cmake related) pass on Win & Linux.
MacOS testing is dependent on the github actions setup, I presume. I'll leave that part to you guys since I don't have access to a Mac.

@nerdvegas
Copy link
Contributor

Thanks Blazej. I'm happy to merge this and will do soon - it stands on its own from #707 and fixes an outstanding bug on Windows.

@nerdvegas
Copy link
Contributor

Just an update - getting to this soon. We're near the end of the py3 work, I'm hoping to get that done first then merge this right after.

@bfloch
Copy link
Contributor Author

bfloch commented Sep 11, 2019

No worries, there is no rush with this merge. I would love to hear your feedback on #737 though since this is the last missing piece for our Rez deployment.

Btw. I haven't tested this PR with python 3, so let me know if there is any work to be done.
In fact, we as a Blender-based animation studio would love to run rez with python 3 so I might be running tests based on your effort soon.

@nerdvegas
Copy link
Contributor

nerdvegas commented Sep 11, 2019 via email

@nerdvegas nerdvegas merged commit e2f4242 into AcademySoftwareFoundation:master Sep 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants