--- a/eric7/DebugClients/Python/coverage/data.py Sun Jan 16 20:28:42 2022 +0100 +++ b/eric7/DebugClients/Python/coverage/data.py Sat Jan 22 14:44:56 2022 +0100 @@ -13,8 +13,8 @@ import glob import os.path -from coverage.exceptions import CoverageException -from coverage.misc import file_be_gone +from coverage.exceptions import CoverageException, NoDataError +from coverage.misc import file_be_gone, human_sorted, plural from coverage.sqldata import CoverageData @@ -53,11 +53,36 @@ hasher.update(data.file_tracer(filename)) +def combinable_files(data_file, data_paths=None): + """Make a list of data files to be combined. + + `data_file` is a path to a data file. `data_paths` is a list of files or + directories of files. + + Returns a list of absolute file paths. + """ + data_dir, local = os.path.split(os.path.abspath(data_file)) + + data_paths = data_paths or [data_dir] + files_to_combine = [] + for p in data_paths: + if os.path.isfile(p): + files_to_combine.append(os.path.abspath(p)) + elif os.path.isdir(p): + pattern = os.path.join(os.path.abspath(p), f"{local}.*") + files_to_combine.extend(glob.glob(pattern)) + else: + raise NoDataError(f"Couldn't combine from non-existent path '{p}'") + return files_to_combine + + def combine_parallel_data( data, aliases=None, data_paths=None, strict=False, keep=False, message=None, ): """Combine a number of data files together. + `data` is a CoverageData. + Treat `data.filename` as a file prefix, and combine the data from all of the data files starting with that prefix plus a dot. @@ -79,24 +104,10 @@ raised. """ - # Because of the os.path.abspath in the constructor, data_dir will - # never be an empty string. - data_dir, local = os.path.split(data.base_filename()) - localdot = local + '.*' - - data_paths = data_paths or [data_dir] - files_to_combine = [] - for p in data_paths: - if os.path.isfile(p): - files_to_combine.append(os.path.abspath(p)) - elif os.path.isdir(p): - pattern = os.path.join(os.path.abspath(p), localdot) - files_to_combine.extend(glob.glob(pattern)) - else: - raise CoverageException(f"Couldn't combine from non-existent path '{p}'") + files_to_combine = combinable_files(data.base_filename(), data_paths) if strict and not files_to_combine: - raise CoverageException("No data to combine") + raise NoDataError("No data to combine") files_combined = 0 for f in files_to_combine: @@ -127,4 +138,26 @@ file_be_gone(f) if strict and not files_combined: - raise CoverageException("No usable data files") + raise NoDataError("No usable data files") + + +def debug_data_file(filename): + """Implementation of 'coverage debug data'.""" + data = CoverageData(filename) + filename = data.data_filename() + print(f"path: {filename}") + if not os.path.exists(filename): + print("No data collected: file doesn't exist") + return + data.read() + print(f"has_arcs: {data.has_arcs()!r}") + summary = line_counts(data, fullpath=True) + filenames = human_sorted(summary.keys()) + nfiles = len(filenames) + print(f"{nfiles} file{plural(nfiles)}:") + for f in filenames: + line = f"{f}: {summary[f]} line{plural(summary[f])}" + plugin = data.file_tracer(f) + if plugin: + line += f" [{plugin}]" + print(line)