pyinvoke / invoke

Pythonic task management & command execution.
http://pyinvoke.org
BSD 2-Clause "Simplified" License
4.31k stars 365 forks source link

QOL: Config run should handle shell paths with spaces #989

Open achekery opened 3 months ago

achekery commented 3 months ago

Description

  1. Added terminals.get_short_path_name() utility function that uses ctypes.windll.kernel32.GetShortPathNameW to get short path form for long path. Only applies to Windows-based systems; on Unix this is a pass-thru.
  2. Updated Runner._setup() function to use the new utility function when setting self.opts["shell"] on windows platform.
  3. Added skip_if_posix() decorator function that skips the decorated test when on UNIX.
  4. Updated Runner_.shell test class to check the new behavior.
  5. Updated terminals test class to check the new behavior.

Demo

With invoke main:

```pwsh PS > pipx uninstall invoke ; pipx install 'git+https://github.com/pyinvoke/invoke@main' ; invoke demo ** Setup Start: shell_name='cmd.exe', shell_which='C:\\WINDOWS\\system32\\cmd.exe' ** Demo #1-whichformat: with shell_path_='C:\\WINDOWS\\system32\\cmd.exe' run command_='git status --porcelain' git status --porcelain M projects/bce-patch-builder/tasks.py ** Demo Success!: res_= ** Demo #1-83format: with shell_path_='C:\\WINDOWS\\system32\\cmd.exe' run command_='git status --porcelain' git status --porcelain M projects/bce-patch-builder/tasks.py ** Demo Success!: res_= ========================================== ** Setup Start: shell_name='pwsh.exe', shell_which='C:\\Program Files\\PowerShell\\7\\pwsh.exe' ** Demo #2-whichformat: with shell_path_='C:\\Program Files\\PowerShell\\7\\pwsh.exe' run command_='git status --porcelain' git status --porcelain The argument 'Files\PowerShell\7\pwsh.exe' is not recognized as the name of a script file. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. Usage: pwsh[.exe] [-Login] [[-File] [args]] [-Command { - | [-args ] | [] } ] [-CommandWithArgs [] [-ConfigurationName ] [-ConfigurationFile ] [-CustomPipeName ] [-EncodedCommand ] [-ExecutionPolicy ] [-InputFormat {Text | XML}] [-Interactive] [-MTA] [-NoExit] [-NoLogo] [-NonInteractive] [-NoProfile] [-NoProfileLoadTime] [-OutputFormat {Text | XML}] [-SettingsFile ] [-SSHServerMode] [-STA] [-Version] [-WindowStyle