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

Handle spaces and special characters in Python exec path and app file #26

Merged
merged 4 commits into from
Feb 29, 2024

Conversation

jcheng5
Copy link
Collaborator

@jcheng5 jcheng5 commented Feb 29, 2024

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:

  • PowerShell
  • Git Bash
  • Command Prompt (cmd.exe)
  • Ubuntu (WSL)
  • JavaScript Debug Terminal
  • R Terminal

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.)

@jcheng5 jcheng5 merged commit 31759f2 into main Feb 29, 2024
@gadenbuie gadenbuie mentioned this pull request Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants