Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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:
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)
import click
class CustomClickException(click.ClickException):
"""Wrap click.ClickException for exit_code."""
def __init__(self, *args, **kwargs):
self.exit_code = kwargs.pop('exit_code', 1)
super(CustomClickException, self).__init__(*args, **kwargs)
class CoverageWrapperException(CustomClickException):
"""Inherit from CustomClickException for automatic handling."""
def __init__(self, message, orig_exc=None):
self.orig_exc = orig_exc
super(CoverageWrapperException, self).__init__(message)
def format_message(self):
"""Append information about original exception if any."""
msg = super(CoverageWrapperException, self).format_message()
if self.orig_exc:
return '%s (%s: %s)' % (
msg,
self.orig_exc.__class__.__name__,
self.orig_exc)
return msg
def __str__(self):
def __init__(self, *args, **kwargs):
self.exit_code = kwargs.pop('exit_code', 1)
super(CustomClickException, self).__init__(*args, **kwargs)
def write_coverage(profile_file, data_file, source, append):
"""
Parse PROFILE_FILE (output from Vim's :profile) and write it into DATA_FILE
(Coverage.py compatible).
"""
if append:
m = MergedProfiles(source=source, append_to=data_file)
else:
m = MergedProfiles(source=source)
m.add_profile_files(*profile_file)
if not m.write_coveragepy_data(data_file=data_file):
raise CustomClickException('No data to report.')
if report:
cov_data = m.get_coveragepy_data()
if not cov_data:
raise CustomClickException('No data to report.')
report_opts['data'] = cov_data
ctx.invoke(report_cmd, report_file=report_file,
**report_opts)
if unlink_profile_file:
try:
os.unlink(profile_file)
except Exception: # ignore FileNotFoundError (OSError on py2).
if os.path.exists(profile_file):
raise
if exit_code != 0:
raise CustomClickException(
'Command exited non-zero: %d.' % exit_code,
exit_code=exit_code
)
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
ctx.invoke(report_cmd, report_file=report_file,
**report_opts)
if unlink_profile_file:
try:
os.unlink(profile_file)
except Exception: # ignore FileNotFoundError (OSError on py2).
if os.path.exists(profile_file):
raise
if exit_code != 0:
raise CustomClickException(
'Command exited non-zero: %d.' % exit_code,
exit_code=exit_code
)