summaryrefslogtreecommitdiff
path: root/coverage
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2022-10-09 18:41:24 -0400
committerNed Batchelder <ned@nedbatchelder.com>2022-10-15 13:58:50 -0400
commitcb67b1feb2d68972f0eeb81a0e20b836b64c21dd (patch)
treea1da4137b476b6a201e14b8364a28c8100b893a2 /coverage
parentc28544cc9a0c5113bd3a9279f47a2b7ea8826980 (diff)
downloadpython-coveragepy-git-cb67b1feb2d68972f0eeb81a0e20b836b64c21dd.tar.gz
feat: implicitly combine relative paths
Diffstat (limited to 'coverage')
-rw-r--r--coverage/control.py18
-rw-r--r--coverage/files.py14
-rw-r--r--coverage/sqldata.py4
3 files changed, 25 insertions, 11 deletions
diff --git a/coverage/control.py b/coverage/control.py
index 5e1e54bf..91e604e0 100644
--- a/coverage/control.py
+++ b/coverage/control.py
@@ -741,16 +741,14 @@ class Coverage:
self._post_init()
self.get_data()
- aliases = None
- if self.config.paths:
- aliases = PathAliases(
- debugfn=(self._debug.write if self._debug.should("pathmap") else None),
- relative=self.config.relative_files,
- )
- for paths in self.config.paths.values():
- result = paths[0]
- for pattern in paths[1:]:
- aliases.add(pattern, result)
+ aliases = PathAliases(
+ debugfn=(self._debug.write if self._debug.should("pathmap") else None),
+ relative=self.config.relative_files,
+ )
+ for paths in self.config.paths.values():
+ result = paths[0]
+ for pattern in paths[1:]:
+ aliases.add(pattern, result)
combine_parallel_data(
self._data,
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
diff --git a/coverage/sqldata.py b/coverage/sqldata.py
index 5d62b15b..5d7fbecf 100644
--- a/coverage/sqldata.py
+++ b/coverage/sqldata.py
@@ -596,7 +596,9 @@ class CoverageData(SimpleReprMixin):
"""Update this data with data from several other :class:`CoverageData` instances.
If `aliases` is provided, it's a `PathAliases` object that is used to
- re-map paths to match the local machine's.
+ re-map paths to match the local machine's. Note: `aliases` is None
+ only when called directly from the test suite.
+
"""
if self._debug.should("dataop"):
self._debug.write("Updating with data from {!r}".format(