Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
except Exception:
proc.kill()
proc.wait()
raise
except Exception as exc:
raise CustomClickException('Failed to run %s: %s' % (cmd, exc))
if profile_file:
if not os.path.exists(profile_file):
if not exit_code:
raise CustomClickException(
'The profile file (%s) has not been created.' % (
profile_file))
elif write_data or report:
logger.info('Parsing profile file %s.', profile_file)
p = Profile(profile_file)
p.parse()
if append:
m = MergedProfiles([p], source=source, append_to=data_file)
else:
m = MergedProfiles([p], source=source)
if write_data:
m.write_coveragepy_data(data_file)
if report:
cov_data = m.get_coveragepy_data()
if not cov_data:
raise CustomClickException('No data to report.')
report_opts['data'] = cov_data
except click.exceptions.UsageError as exc:
raise click.exceptions.UsageError(
'Failed to parse --report-options: %s' % exc.message,
ctx=ctx)
else:
report_opts = {}
args = list(args)
unlink_profile_file = False
if wrap_profile:
if not profile_file:
profile_file = tempfile.mktemp(prefix='covimerage.profile.')
unlink_profile_file = True
args += build_vim_profile_args(profile_file, source)
cmd = args
logger.info('Running cmd: %s (in %s)', join_argv(cmd), os.getcwd())
try:
proc = subprocess.Popen(cmd)
def forward_signals(signalnum, stackframe):
"""Forward SIGHUP to the subprocess."""
proc.send_signal(signalnum)
signal.signal(signal.SIGHUP, forward_signals)
try:
exit_code = proc.wait()
except Exception:
proc.kill()
proc.wait()
raise
except Exception as exc:
cov_dict = {}
cov_file_tracers = {}
source_files = []
for source in self.source:
source = os.path.abspath(source)
if os.path.isfile(source):
source_files.append(source)
else:
source_files.extend(find_executable_files(source))
logger.debug('source_files: %r', source_files)
for fname, lines in self.lines.items():
fname = os.path.abspath(fname)
if self.source and fname not in source_files:
logger.info('Ignoring non-source: %s', fname)
continue
cov_dict[fname] = {
# lnum: line.count for lnum, line in lines.items()
# XXX: coveragepy does not support hit counts?!
lnum: None for lnum, line in lines.items() if line.count
}
# Add our plugin as file tracer, so that it gets used with e.g.
# `coverage annotate`.
cov_file_tracers[fname] = 'covimerage.CoveragePlugin'
measured_files = cov_dict.keys()
non_measured_files = set(source_files) - set(measured_files)
for fname in non_measured_files:
logger.debug('Non-measured file: %s', fname)
cov_dict[fname] = {}
cov_file_tracers[fname] = 'covimerage.CoveragePlugin'
return False
if isinstance(data_file, string_types):
logger.info('Writing coverage file %s.', data_file)
try:
write_file = cov_data.write_file
except AttributeError:
# coveragepy 5
write_file = cov_data._write_file
write_file(data_file)
else:
try:
filename = data_file.name
except AttributeError:
filename = str(data_file)
logger.info('Writing coverage file %s.', filename)
cov_data.write_fileobj(data_file)
return True
def write_coveragepy_data(self, data_file='.coverage'):
import coverage
cov_data = self.get_coveragepy_data()
try:
line_counts = cov_data.line_counts()
except AttributeError:
line_counts = coverage.data.line_counts(cov_data)
if not line_counts:
logger.warning('Not writing coverage file: no data to report!')
return False
if isinstance(data_file, string_types):
logger.info('Writing coverage file %s.', data_file)
try:
write_file = cov_data.write_file
except AttributeError:
# coveragepy 5
write_file = cov_data._write_file
write_file(data_file)
else:
try:
filename = data_file.name
except AttributeError:
filename = str(data_file)
logger.info('Writing coverage file %s.', filename)
cov_data.write_fileobj(data_file)
return True