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

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

Closed
wants to merge 8 commits into from
Prev Previous commit
Next Next commit
Fix mypy windows type not defined errors
achekerylla committed Mar 12, 2024
commit b9d50e4903d87a74095658bff870091ba009e2ae
50 changes: 31 additions & 19 deletions invoke/terminals.py
Original file line number Diff line number Diff line change
@@ -249,6 +249,36 @@
return 1


if sys.platform == "win32":

def _get_short_path_name(long_path: str) -> str:

Check warning on line 254 in invoke/terminals.py

Codecov / codecov/patch

invoke/terminals.py#L254

Added line #L254 was not covered by tests
# Access `GetShortPathNameW()` function from `kernel32.dll`.
GetShortPathNameW = windll.kernel32.GetShortPathNameW
GetShortPathNameW.argtypes = [

Check warning on line 257 in invoke/terminals.py

Codecov / codecov/patch

invoke/terminals.py#L256-L257

Added lines #L256 - L257 were not covered by tests
wintypes.LPCWSTR,
wintypes.LPWSTR,
wintypes.DWORD,
]
GetShortPathNameW.restype = wintypes.DWORD

Check warning on line 262 in invoke/terminals.py

Codecov / codecov/patch

invoke/terminals.py#L262

Added line #L262 was not covered by tests
# Call function to get short path form.
buffer_size = 0
while True:
buffer_array = create_unicode_buffer(buffer_size)
required_size = GetShortPathNameW(

Check warning on line 267 in invoke/terminals.py

Codecov / codecov/patch

invoke/terminals.py#L264-L267

Added lines #L264 - L267 were not covered by tests
long_path,
buffer_array,
buffer_size,
)
if required_size > buffer_size:
buffer_size = required_size

Check warning on line 273 in invoke/terminals.py

Codecov / codecov/patch

invoke/terminals.py#L273

Added line #L273 was not covered by tests
else:
return buffer_array.value

Check warning on line 275 in invoke/terminals.py

Codecov / codecov/patch

invoke/terminals.py#L275

Added line #L275 was not covered by tests

else:

def _get_short_path_name(long_path: str) -> str:
return long_path

def get_short_path_name(long_path: str) -> str:
"""
Get short path form for long path.
@@ -263,22 +293,4 @@

:returns: `str` Short path form of the long path.
"""
if not WINDOWS:
return long_path
# Access `GetShortPathNameW()` function from `kernel32.dll`.
GetShortPathNameW = windll.kernel32.GetShortPathNameW
GetShortPathNameW.argtypes = [
wintypes.LPCWSTR,
wintypes.LPWSTR,
wintypes.DWORD,
]
GetShortPathNameW.restype = wintypes.DWORD
# Call function to get short path form.
buffer_size = 0
while True:
buffer_array = create_unicode_buffer(buffer_size)
required_size = GetShortPathNameW(long_path, buffer_array, buffer_size)
if required_size > buffer_size:
buffer_size = required_size
else:
return buffer_array.value
return _get_short_path_name(long_path)

Unchanged files with check annotations Beta

if self.opts["echo"]:
self.echo(command)
if WINDOWS:
self.opts["shell"] = get_short_path_name(self.opts["shell"])

Check warning on line 420 in invoke/runners.py

Codecov / codecov/patch

invoke/runners.py#L420

Added line #L420 was not covered by tests
# Prepare common result args.
# TODO: I hate this. Needs a deeper separate think about tweaking
# Runner.generate_result in a way that isn't literally just this same
def wrapper(*args, **kwargs):
if not WINDOWS:
skip()
return fn(*args, **kwargs)

Check warning on line 40 in tests/_util.py

Codecov / codecov/patch

tests/_util.py#L40

Added line #L40 was not covered by tests
return wrapper
@skip_if_posix
def may_be_configured_with_short_path_on_windows(self):
runner = self._runner(

Check warning on line 237 in tests/runners.py

Codecov / codecov/patch

tests/runners.py#L237

Added line #L237 was not covered by tests
run={"shell": "C:\\Program Files\\PowerShell\\7\\pwsh.exe"}
)
assert runner.run(_).shell == "C:\\PROGRA~1\\POWERS~1\\7\\pwsh.exe"

Check warning on line 240 in tests/runners.py

Codecov / codecov/patch

tests/runners.py#L240

Added line #L240 was not covered by tests
@skip_if_windows
def may_be_configured_with_passthru_on_posix(self):