Skip to content

Commit

Permalink
Merge pull request #19547 from DWesl/cyg2win32-use-cygpath
Browse files Browse the repository at this point in the history
BLD: Use cygpath utility for path conversion in cyg2win32
  • Loading branch information
charris committed Jul 23, 2021
2 parents 3409bd3 + 84f54ce commit c3d1107
Showing 1 changed file with 36 additions and 4 deletions.
40 changes: 36 additions & 4 deletions numpy/distutils/misc_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,42 @@ def blue_text(s):

#########################

def cyg2win32(path):
if sys.platform=='cygwin' and path.startswith('/cygdrive'):
path = path[10] + ':' + os.path.normcase(path[11:])
return path
def cyg2win32(path: str) -> str:
"""Convert a path from Cygwin-native to Windows-native.
Uses the cygpath utility (part of the Base install) to do the
actual conversion. Falls back to returning the original path if
this fails.
Handles the default ``/cygdrive`` mount prefix as well as the
``/proc/cygdrive`` portable prefix, custom cygdrive prefixes such
as ``/`` or ``/mnt``, and absolute paths such as ``/usr/src/`` or
``/home/username``
Parameters
----------
path : str
The path to convert
Returns
-------
converted_path : str
The converted path
Notes
-----
Documentation for cygpath utility:
https://cygwin.com/cygwin-ug-net/cygpath.html
Documentation for the C function it wraps:
https://cygwin.com/cygwin-api/func-cygwin-conv-path.html
"""
if sys.platform != "cygwin":
return path
return subprocess.check_output(
["/usr/bin/cygpath", "--windows", path], universal_newlines=True
)


def mingw32():
"""Return true when using mingw32 environment.
Expand Down

0 comments on commit c3d1107

Please sign in to comment.