eric6/Utilities/__init__.py

changeset 7849
70e464748aaa
parent 7843
0a569bf8ca45
child 7900
72b88fb20261
child 7924
8a96736d465e
--- a/eric6/Utilities/__init__.py	Wed Dec 02 19:09:38 2020 +0100
+++ b/eric6/Utilities/__init__.py	Fri Dec 04 18:29:31 2020 +0100
@@ -755,7 +755,6 @@
     return QDir.fromNativeSeparators(path)
 
 
-# TODO: check which path functions are already covered by Python 3
 def normcasepath(path):
     """
     Function returning a path, that is normalized with respect to its case
@@ -767,16 +766,6 @@
     return os.path.normcase(os.path.normpath(path))
 
 
-def normabspath(path):
-    """
-    Function returning a normalized, absolute path.
-    
-    @param path file path (string)
-    @return absolute, normalized path (string)
-    """
-    return os.path.abspath(path)
-
-
 def normcaseabspath(path):
     """
     Function returning an absolute path, that is normalized with respect to
@@ -793,7 +782,7 @@
     Function returning a normalized path of the joined parts passed into it.
     
     @param a first path to be joined (string)
-    @param p variable number of path parts to be joind (string)
+    @param p variable number of path parts to be joined (string)
     @return normalized path (string)
     """
     return os.path.normpath(os.path.join(a, *p))
@@ -811,30 +800,6 @@
     return os.path.abspath(os.path.join(a, *p))
 
 
-def relpath(path, start=os.path.curdir):
-    """
-    Return a relative version of a path.
-    
-    @param path path to make relative (string)
-    @param start path to make relative from (string)
-    @return relative path (string)
-    @exception ValueError raised to indicate an invalid path
-    """
-    if not path:
-        raise ValueError("no path specified")
-
-    start_list = os.path.abspath(start).split(os.path.sep)
-    path_list = os.path.abspath(path).split(os.path.sep)
-
-    # Work out how much of the filepath is shared by start and path.
-    i = len(os.path.commonprefix([start_list, path_list]))
-
-    rel_list = [os.path.pardir] * (len(start_list) - i) + path_list[i:]
-    if not rel_list:
-        return os.path.curdir
-    return os.path.join(*rel_list)
-
-
 def isinpath(file):
     """
     Function to check for an executable file.
@@ -875,8 +840,8 @@
     if start:
         if path == start:
             return True
-        elif normcasepath(toNativeSeparators(path)).startswith(
-                normcasepath(toNativeSeparators(start + "/"))):
+        elif normcasepath(path).startswith(
+                normcasepath(start + "/")):
             return True
         else:
             return False
@@ -884,27 +849,6 @@
         return False
 
 
-def relativePath(path, start):
-    """
-    Function to convert a file path to a path relative to a start path.
-    
-    @param path file or directory name to convert (string)
-    @param start start path (string)
-    @return relative path or unchanged path, if path does not start with
-        the start path (string)
-    """
-    if startswithPath(path, start):
-        if path == start:
-            return ""
-        else:
-            if start.endswith(("/", "\\")):
-                return path[len(start):]
-            else:
-                return path[len(start) + 1:]
-    else:
-        return path
-
-
 def relativeUniversalPath(path, start):
     """
     Function to convert a file path to a path relative to a start path
@@ -915,7 +859,7 @@
     @return relative path or unchanged path, if path does not start with
         the start path with universal separators (string)
     """
-    return fromNativeSeparators(relativePath(path, start))
+    return fromNativeSeparators(os.path.relpath(path, start))
 
 
 def absolutePath(path, start):
@@ -928,7 +872,7 @@
     @return absolute path (string)
     """
     if not os.path.isabs(path):
-        path = os.path.join(start, path)
+        path = os.path.normpath(os.path.join(start, path))
     return path
 
 
@@ -942,7 +886,7 @@
     @return absolute path with native separators (string)
     """
     if not os.path.isabs(path):
-        path = toNativeSeparators(os.path.join(start, path))
+        path = toNativeSeparators(os.path.normpath(os.path.join(start, path)))
     return path
 
 

eric ide

mercurial