Commit 19e6c6a6 authored by Stefan Behnel's avatar Stefan Behnel

Support more C file extensions when searching modules during coverage...

Support more C file extensions when searching modules during coverage analysis: .cc and .cxx in addition to the current .c and .cpp.
Closes #2266.
parent 0c3e3613
...@@ -16,6 +16,9 @@ Features added ...@@ -16,6 +16,9 @@ Features added
* Some internal and 1-argument method calls are faster. * Some internal and 1-argument method calls are faster.
* The coverage plugin considers more C file extensions such as ``.cc`` and ``.cxx``.
(Github issue #2266)
Bugs fixed Bugs fixed
---------- ----------
......
...@@ -20,14 +20,17 @@ from .Utils import find_root_package_dir, is_package_dir, open_source_file ...@@ -20,14 +20,17 @@ from .Utils import find_root_package_dir, is_package_dir, open_source_file
from . import __version__ from . import __version__
C_FILE_EXTENSIONS = ['.c', '.cpp', '.cc', '.cxx']
MODULE_FILE_EXTENSIONS = set(['.py', '.pyx', '.pxd'] + C_FILE_EXTENSIONS)
def _find_c_source(base_path): def _find_c_source(base_path):
if os.path.exists(base_path + '.c'): file_exists = os.path.exists
c_file = base_path + '.c' for ext in C_FILE_EXTENSIONS:
elif os.path.exists(base_path + '.cpp'): file_name = base_path + ext
c_file = base_path + '.cpp' if file_exists(file_name):
else: return file_name
c_file = None return None
return c_file
def _find_dep_file_path(main_file, file_path): def _find_dep_file_path(main_file, file_path):
...@@ -107,7 +110,7 @@ class Plugin(CoveragePlugin): ...@@ -107,7 +110,7 @@ class Plugin(CoveragePlugin):
def _find_source_files(self, filename): def _find_source_files(self, filename):
basename, ext = os.path.splitext(filename) basename, ext = os.path.splitext(filename)
ext = ext.lower() ext = ext.lower()
if ext in ('.py', '.pyx', '.pxd', '.c', '.cpp'): if ext in MODULE_FILE_EXTENSIONS:
pass pass
elif ext == '.pyd': elif ext == '.pyd':
# Windows extension module # Windows extension module
...@@ -130,7 +133,7 @@ class Plugin(CoveragePlugin): ...@@ -130,7 +133,7 @@ class Plugin(CoveragePlugin):
# none of our business # none of our business
return None, None return None, None
c_file = filename if ext in ('.c', '.cpp') else _find_c_source(basename) c_file = filename if ext in C_FILE_EXTENSIONS else _find_c_source(basename)
if c_file is None: if c_file is None:
# a module "pkg/mod.so" can have a source file "pkg/pkg.mod.c" # a module "pkg/mod.so" can have a source file "pkg/pkg.mod.c"
package_root = find_root_package_dir.uncached(filename) package_root = find_root_package_dir.uncached(filename)
...@@ -164,7 +167,7 @@ class Plugin(CoveragePlugin): ...@@ -164,7 +167,7 @@ class Plugin(CoveragePlugin):
splitext = os.path.splitext splitext = os.path.splitext
for filename in os.listdir(dir_path): for filename in os.listdir(dir_path):
ext = splitext(filename)[1].lower() ext = splitext(filename)[1].lower()
if ext in ('.c', '.cpp'): if ext in C_FILE_EXTENSIONS:
self._parse_lines(os.path.join(dir_path, filename), source_file) self._parse_lines(os.path.join(dir_path, filename), source_file)
if source_file in self._c_files_map: if source_file in self._c_files_map:
return return
......
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