summaryrefslogtreecommitdiff
path: root/coverage/files.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2022-11-30 18:44:40 -0500
committerNed Batchelder <ned@nedbatchelder.com>2022-12-01 10:21:45 -0500
commit2adeb8bb5c2a12a080d7a528e35e5df9ffe7785f (patch)
tree2f95b6017927c5a1dfeb62c6f0169f022ca0d401 /coverage/files.py
parentc2e35658d8311fd2b5d1460c2cb56762d5fe0ec7 (diff)
downloadpython-coveragepy-git-2adeb8bb5c2a12a080d7a528e35e5df9ffe7785f.tar.gz
fix: when checking source existence for remapping, zipfiles are ok
Diffstat (limited to 'coverage/files.py')
-rw-r--r--coverage/files.py31
1 files changed, 30 insertions, 1 deletions
diff --git a/coverage/files.py b/coverage/files.py
index 63e9afb2..5f222419 100644
--- a/coverage/files.py
+++ b/coverage/files.py
@@ -153,6 +153,35 @@ def abs_file(path):
return actual_path(os.path.abspath(os.path.realpath(path)))
+def zip_location(filename):
+ """Split a filename into a zipfile / inner name pair.
+
+ Only return a pair if the zipfile exists. No check is made if the inner
+ name is in the zipfile.
+
+ """
+ for ext in ['.zip', '.egg', '.pex']:
+ zipbase, extension, inner = filename.partition(ext + sep(filename))
+ if extension:
+ zipfile = zipbase + ext
+ if os.path.exists(zipfile):
+ return zipfile, inner
+ return None
+
+
+def source_exists(path):
+ """Determine if a source file path exists."""
+ if os.path.exists(path):
+ return True
+
+ if zip_location(path):
+ # If zip_location returns anything, then it's a zipfile that
+ # exists. That's good enough for us.
+ return True
+
+ return False
+
+
def python_reported_file(filename):
"""Return the string as Python would describe this file name."""
if env.PYBEHAVIOR.report_absolute_files:
@@ -408,7 +437,7 @@ class PathAliases:
result = result.rstrip(r"\/") + result_sep
self.aliases.append((original_pattern, regex, result))
- def map(self, path, exists=os.path.exists):
+ def map(self, path, exists=source_exists):
"""Map `path` through the aliases.
`path` is checked against all of the patterns. The first pattern to