8000 BLD: Change `cyg2win32` to use the `cygpath` utility. · numpy/numpy@e30548d · GitHub
[go: up one dir, main page]

Skip to content

Commit e30548d

Browse files
committed
BLD: Change cyg2win32 to use the cygpath utility.
The old function only handled the default `/cygdrive` prefix. This can be customized to different values: `/` and `/mnt` are both common. `/proc/cygdrive` does the same thing, regardless of user customization. `cygpath` handles all of these. There's also a C function if you'd prefer to avoid the `fork()` call, which tends to be slow on Cygwin. Edit: Fix the cyg2win32 function to have correct types. It returned bytes earlier; this should return a string. Edit: Fix docsrting to follow numpydoc.
1 parent 2f20c93 commit e30548d

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

numpy/distutils/misc_util.py

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,40 @@ def blue_text(s):
377377
#########################
378378

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

384415
def mingw32():
385416
"""Return true when using mingw32 environment.

0 commit comments

Comments
 (0)
0