Skip to content

Commit c3d1107

Browse files
authored
Merge pull request numpy#19547 from DWesl/cyg2win32-use-cygpath
BLD: Use cygpath utility for path conversion in cyg2win32
2 parents 3409bd3 + 84f54ce commit c3d1107

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

numpy/distutils/misc_util.py

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -376,10 +376,42 @@ def blue_text(s):
376376

377377
#########################
378378

379-
def cyg2win32(path):
380-
if sys.platform=='cygwin' and path.startswith('/cygdrive'):
381-
path = path[10] + ':' + os.path.normcase(path[11:])
382-
return path
379+
def cyg2win32(path: str) -> str:
380+
"""Convert a path from Cygwin-native to Windows-native.
381+
382+
Uses the cygpath utility (part of the Base install) to do the
383+
actual conversion. Falls back to returning the original path if
384+
this fails.
385+
386+
Handles the default ``/cygdrive`` mount prefix as well as the
387+
``/proc/cygdrive`` portable prefix, custom cygdrive prefixes such
388+
as ``/`` or ``/mnt``, and absolute paths such as ``/usr/src/`` or
389+
``/home/username``
390+
391+
Parameters
392+
----------
393+
path : str
394+
The path to convert
395+
396+
Returns
397+
-------
398+
converted_path : str
399+
The converted path
400+
401+
Notes
402+
-----
403+
Documentation for cygpath utility:
404+
https://cygwin.com/cygwin-ug-net/cygpath.html
405+
Documentation for the C function it wraps:
406+
https://cygwin.com/cygwin-api/func-cygwin-conv-path.html
407+
408+
"""
409+
if sys.platform != "cygwin":
410+
return path
411+
return subprocess.check_output(
412+
["/usr/bin/cygpath", "--windows", path], universal_newlines=True
413+
)
414+
383415

384416
def mingw32():
385417
"""Return true when using mingw32 environment.

0 commit comments

Comments
 (0)