diff options
Diffstat (limited to 'coverage/files.py')
-rw-r--r-- | coverage/files.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/coverage/files.py b/coverage/files.py index 87a18bc2..2c520b8a 100644 --- a/coverage/files.py +++ b/coverage/files.py @@ -409,6 +409,20 @@ class PathAliases: f"producing {new!r}" ) return new + + # If we get here, no pattern matched. + + if self.relative and not isabs_anywhere(path): + parts = re.split(r"[/\\]", path) + if len(parts) > 1: + dir1 = parts[0] + pattern = f"*/{dir1}" + regex = rf"^(.*[\\/])?{re.escape(dir1)}[\\/]" + result = f"{dir1}{os.sep}" + self.debugfn(f"Generating rule: {pattern!r} -> {result!r} using regex {regex!r}") + self.aliases.append((pattern, re.compile(regex), result)) + return self.map(path) + self.debugfn(f"No rules match, path {path!r} is unchanged") return path |