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.
Updated Runner._setup() function to use the new utility function when setting self.opts["shell"] on windows platform.
Added skip_if_posix() decorator function that skips the decorated test when on UNIX.
Updated Runner_.shell test class to check the new behavior.
Updated terminals test class to check the new behavior.
Demo
With invoke main:
Both long format and short format work for cmd.exe
Although short format works for pwsh.exe, long format does not.
```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
Description
terminals.get_short_path_name()
utility function that usesctypes.windll.kernel32.GetShortPathNameW
to get short path form for long path. Only applies to Windows-based systems; on Unix this is a pass-thru.Runner._setup()
function to use the new utility function when settingself.opts["shell"]
on windows platform.skip_if_posix()
decorator function that skips the decorated test when on UNIX.Runner_.shell
test class to check the new behavior.terminals
test class to check the new behavior.Demo
With invoke main:
cmd.exe
pwsh.exe
, long format does not.