Commit 20f028eb authored by Robert Bradshaw's avatar Robert Bradshaw

Merge pull request #473 from watsona4/path-search-fix

Path search fix
parents 0c62e665 81c126c6
...@@ -8,6 +8,7 @@ from __future__ import absolute_import ...@@ -8,6 +8,7 @@ from __future__ import absolute_import
import re import re
import os.path import os.path
import sys
from collections import defaultdict from collections import defaultdict
from coverage.plugin import CoveragePlugin, FileTracer, FileReporter # requires coverage.py 4.0+ from coverage.plugin import CoveragePlugin, FileTracer, FileReporter # requires coverage.py 4.0+
...@@ -35,6 +36,12 @@ def _find_dep_file_path(main_file, file_path): ...@@ -35,6 +36,12 @@ def _find_dep_file_path(main_file, file_path):
pxi_file_path = os.path.join(os.path.dirname(main_file), file_path) pxi_file_path = os.path.join(os.path.dirname(main_file), file_path)
if os.path.exists(pxi_file_path): if os.path.exists(pxi_file_path):
abs_path = os.path.abspath(pxi_file_path) abs_path = os.path.abspath(pxi_file_path)
# search sys.path for external locations if a valid file hasn't been found
if not os.path.exists(abs_path):
for sys_path in sys.path:
test_path = os.path.realpath(os.path.join(sys_path, file_path))
if os.path.exists(test_path):
return test_path
return abs_path return abs_path
...@@ -132,7 +139,7 @@ class Plugin(CoveragePlugin): ...@@ -132,7 +139,7 @@ class Plugin(CoveragePlugin):
try: try:
with open(c_file, 'rb') as f: with open(c_file, 'rb') as f:
if b'/* Generated by Cython ' not in f.read(30): if b'/* Generated by Cython ' not in f.read(30):
return None # not a Cython file return None, None # not a Cython file
except (IOError, OSError): except (IOError, OSError):
c_file = None c_file = None
...@@ -238,7 +245,7 @@ class CythonModuleTracer(FileTracer): ...@@ -238,7 +245,7 @@ class CythonModuleTracer(FileTracer):
return self._file_path_map[source_file] return self._file_path_map[source_file]
except KeyError: except KeyError:
pass pass
abs_path = os.path.abspath(source_file) abs_path = _find_dep_file_path(filename, source_file)
if self.py_file and source_file[-3:].lower() == '.py': if self.py_file and source_file[-3:].lower() == '.py':
# always let coverage.py handle this case itself # always let coverage.py handle this case itself
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment