Handle spaces and special characters in Python exec path and app file #26
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #16
Fixes #23
Implementation notes
When using the "Run Shiny App" command, the Python executable path and the app file path are both potentially in need of escaping, due to spaces or special characters. Today, we don't do that, so if you installed Python on Windows with "Install for all users", putting Python under C:\Program Files, we fail to launch every time if you try to use the system Python (as opposed to a venv, then it would depend if the venv path has any spaces in it).
However, the way that escaping needs to be performed differs based on what type of shell VS Code's integrated terminal is configured to launch. On my Windows installation, for example, I get the following choices:
Since the last two don't make any sense, I've narrowed it down to PowerShell, cmd.exe, and everything else, which I basically treat as bash. PowerShell, cmd, and bash all have very different escaping rules.
I've tried to avoid unnecessary escapes or quoting; in other words, the command is designed to look as human-like as possible.
Testing notes
First, you'll need a copy of the .vsix extension bundle, and install it with either
code --install-extension <path-to-vsix>
or using the VS Code command "Extensions: Install from VSIX...". Then reload VS Code.To test this feature, create a venv in a directory that contains a space or special character somewhere in its path. Then try the "Run Shiny App" button and see if it succeeds.
You can try with different shells by opening the VS Code settings UI and searching for
terminal.integrated.defaultProfile
, and use the select box for the OS you're on. Once you change that, you'll also need to close any already-opened integrated terminal labeled "Shiny", otherwise the Shiny extension will just re-use that terminal with whatever shell it was launched with. (And yes, with my changes, it's expected to work correctly in that case as well--reusing a cmd.exe terminal when you just changed the default setting to PowerShell, should still escape using cmd.exe rules.)