Added 'native_path()' for use on pathnames from the setup script: split on

slashes, and put back together again using the local directory separator.
This commit is contained in:
Greg Ward 2000-03-07 03:27:08 +00:00
parent e2b4452d0c
commit 5091929c2c

View file

@ -458,3 +458,31 @@ def get_platform ():
return sys.platform
# get_platform()
def native_path (pathname):
"""Return 'pathname' as a name that will work on the native
filesystem, i.e. split it on '/' and put it back together again
using the current directory separator. Needed because filenames in
the setup script are always supplied in Unix style, and have to be
converted to the local convention before we can actually use them in
the filesystem. Raises DistutilsValueError if 'pathname' is
absolute (starts with '/') or contains local directory separators
(unless the local separator is '/', of course)."""
if pathname[0] == '/':
raise DistutilsValueError, "path '%s' cannot be absolute" % pathname
if pathname[-1] == '/':
raise DistutilsValueError, "path '%s' cannot end with '/'" % pathname
if os.sep != '/':
if os.sep in pathname:
raise DistutilsValueError, \
"path '%s' cannot contain '%c' character" % \
(pathname, os.sep)
paths = string.split (pathname, '/')
return apply (os.path.join, paths)
else:
return pathname
# native_path ()