src/eric7/DebugClients/Python/coverage/files.py

branch
eric7
changeset 9374
ed79209469ad
parent 9252
32dd11232e06
diff -r e074358157f4 -r ed79209469ad src/eric7/DebugClients/Python/coverage/files.py
--- a/src/eric7/DebugClients/Python/coverage/files.py	Sat Oct 01 17:30:55 2022 +0200
+++ b/src/eric7/DebugClients/Python/coverage/files.py	Sat Oct 01 17:37:10 2022 +0200
@@ -3,8 +3,8 @@
 
 """File wrangling."""
 
+import fnmatch
 import hashlib
-import fnmatch
 import ntpath
 import os
 import os.path
@@ -24,8 +24,14 @@
     """Set the directory that `relative_filename` will be relative to."""
     global RELATIVE_DIR, CANONICAL_FILENAME_CACHE
 
+    # The current directory
+    abs_curdir = abs_file(os.curdir)
+    if not abs_curdir.endswith(os.sep):
+        # Suffix with separator only if not at the system root
+        abs_curdir = abs_curdir + os.sep
+
     # The absolute path to our current directory.
-    RELATIVE_DIR = os.path.normcase(abs_file(os.curdir) + os.sep)
+    RELATIVE_DIR = os.path.normcase(abs_curdir)
 
     # Cache of results of calling the canonical_filename() method, to
     # avoid duplicating work.
@@ -320,15 +326,17 @@
     map a path through those aliases to produce a unified path.
 
     """
-    def __init__(self, relative=False):
-        self.aliases = []
+    def __init__(self, debugfn=None, relative=False):
+        self.aliases = []   # A list of (original_pattern, regex, result)
+        self.debugfn = debugfn or (lambda msg: 0)
         self.relative = relative
+        self.pprinted = False
 
-    def pprint(self):       # pragma: debugging
+    def pprint(self):
         """Dump the important parts of the PathAliases, for debugging."""
-        print(f"Aliases (relative={self.relative}):")
-        for regex, result in self.aliases:
-            print(f"{regex.pattern!r} --> {result!r}")
+        self.debugfn(f"Aliases (relative={self.relative}):")
+        for original_pattern, regex, result in self.aliases:
+            self.debugfn(f" Rule: {original_pattern!r} -> {result!r} using regex {regex.pattern!r}")
 
     def add(self, pattern, result):
         """Add the `pattern`/`result` pair to the list of aliases.
@@ -343,6 +351,7 @@
         match an entire tree, and not just its root.
 
         """
+        original_pattern = pattern
         pattern_sep = sep(pattern)
 
         if len(pattern) > 1:
@@ -354,8 +363,7 @@
 
         # The pattern is meant to match a filepath.  Let's make it absolute
         # unless it already is, or is meant to match any prefix.
-        if not pattern.startswith('*') and not isabs_anywhere(pattern +
-                                                              pattern_sep):
+        if not pattern.startswith('*') and not isabs_anywhere(pattern + pattern_sep):
             pattern = abs_file(pattern)
         if not pattern.endswith(pattern_sep):
             pattern += pattern_sep
@@ -366,7 +374,7 @@
         # Normalize the result: it must end with a path separator.
         result_sep = sep(result)
         result = result.rstrip(r"\/") + result_sep
-        self.aliases.append((regex, result))
+        self.aliases.append((original_pattern, regex, result))
 
     def map(self, path):
         """Map `path` through the aliases.
@@ -384,14 +392,23 @@
         of `path` unchanged.
 
         """
-        for regex, result in self.aliases:
+        if not self.pprinted:
+            self.pprint()
+            self.pprinted = True
+
+        for original_pattern, regex, result in self.aliases:
             m = regex.match(path)
             if m:
                 new = path.replace(m[0], result)
                 new = new.replace(sep(path), sep(result))
                 if not self.relative:
                     new = canonical_filename(new)
+                self.debugfn(
+                    f"Matched path {path!r} to rule {original_pattern!r} -> {result!r}, " +
+                    f"producing {new!r}"
+                )
                 return new
+        self.debugfn(f"No rules match, path {path!r} is unchanged")
         return path
 
 

eric ide

mercurial