Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
ignore_stdin, staged, verbose, silent, debug)
LOG.debug(u"Configuration\n%s", ustr(config))
ctx.obj = (config, config_builder, commits, msg_filename)
# If no subcommand is specified, then just lint
if ctx.invoked_subcommand is None:
ctx.invoke(lint)
except GitContextError as e:
click.echo(ustr(e))
ctx.exit(GIT_CONTEXT_ERROR_CODE)
except GitLintUsageError as e:
click.echo(u"Error: {0}".format(ustr(e)))
ctx.exit(USAGE_ERROR_CODE)
except LintConfigError as e:
click.echo(u"Config Error: {0}".format(ustr(e)))
ctx.exit(CONFIG_ERROR_CODE)
def set_config_from_string_list(self, config_options):
""" Given a list of config options of the form ".<option>=", parses out the correct rule and option
and sets the value accordingly in this factory object. """
for config_option in config_options:
try:
config_name, option_value = config_option.split("=", 1)
if not option_value:
raise ValueError()
rule_name, option_name = config_name.split(".", 1)
self.set_option(rule_name, option_name, option_value)
except ValueError: # raised if the config string is invalid
raise LintConfigError(
u"'{0}' is an invalid configuration option. Use '.<option>='".format(config_option))
</option></option>
def wrapped(*args):
try:
return func(*args)
except options.RuleOptionError as e:
raise LintConfigError(ustr(e))
self.rules.delete_rules_by_attr("is_contrib", True)
# Load all classes from the contrib directory
contrib_dir_path = os.path.dirname(os.path.realpath(contrib_rules.__file__))
rule_classes = rule_finder.find_rule_classes(contrib_dir_path)
# For each specified contrib rule, check whether it exists among the contrib classes
for rule_id_or_name in self.contrib:
rule_class = next((rc for rc in rule_classes if
rc.id == ustr(rule_id_or_name) or rc.name == ustr(rule_id_or_name)), False)
# If contrib rule exists, instantiate it and add it to the rules list
if rule_class:
self.rules.add_rule(rule_class, rule_class.id, {'is_contrib': True})
else:
raise LintConfigError(u"No contrib rule with id or name '{0}' found.".format(ustr(rule_id_or_name)))
except (options.RuleOptionError, rules.UserRuleError) as e:
raise LintConfigError(ustr(e))
def _get_option(self, rule_name_or_id, option_name):
rule_name_or_id = ustr(rule_name_or_id) # convert to unicode first
option_name = ustr(option_name)
rule = self.rules.find_rule(rule_name_or_id)
if not rule:
raise LintConfigError(u"No such rule '{0}'".format(rule_name_or_id))
option = rule.options.get(option_name)
if not option:
raise LintConfigError(u"Rule '{0}' has no option '{1}'".format(rule_name_or_id, option_name))
return option
def set_general_option(self, option_name, option_value):
attr_name = option_name.replace("-", "_")
# only allow setting general options that exist and don't start with an underscore
if not hasattr(self, attr_name) or attr_name[0] == "_":
raise LintConfigError(u"'{0}' is not a valid gitlint option".format(option_name))
# else:
setattr(self, attr_name, option_value)
else:
self._extra_path = options.PathOption(
'extra-path', value,
"Path to a directory or module with extra user-defined rules",
type='both'
)
# Make sure we unload any previously loaded extra-path rules
self.rules.delete_rules_by_attr("is_user_defined", True)
# Find rules in the new extra-path and add them to the existing rules
rule_classes = rule_finder.find_rule_classes(self.extra_path)
self.rules.add_rules(rule_classes, {'is_user_defined': True})
except (options.RuleOptionError, rules.UserRuleError) as e:
raise LintConfigError(ustr(e))
def set_from_config_file(self, filename):
""" Loads lint config from a ini-style config file """
if not os.path.exists(filename):
raise LintConfigError(u"Invalid file path: {0}".format(filename))
self._config_path = os.path.realpath(filename)
try:
parser = ConfigParser()
with io.open(filename, encoding=DEFAULT_ENCODING) as config_file:
# readfp() is deprecated in python 3.2+, but compatible with 2.7
parser.readfp(config_file, filename) # pylint: disable=deprecated-method
for section_name in parser.sections():
for option_name, option_value in parser.items(section_name):
self.set_option(section_name, option_name, ustr(option_value))
except ConfigParserError as e:
raise LintConfigError(ustr(e))
if not os.path.exists(filename):
raise LintConfigError(u"Invalid file path: {0}".format(filename))
self._config_path = os.path.realpath(filename)
try:
parser = ConfigParser()
with io.open(filename, encoding=DEFAULT_ENCODING) as config_file:
# readfp() is deprecated in python 3.2+, but compatible with 2.7
parser.readfp(config_file, filename) # pylint: disable=deprecated-method
for section_name in parser.sections():
for option_name, option_value in parser.items(section_name):
self.set_option(section_name, option_name, ustr(option_value))
except ConfigParserError as e:
raise LintConfigError(ustr(e))
contrib_dir_path = os.path.dirname(os.path.realpath(contrib_rules.__file__))
rule_classes = rule_finder.find_rule_classes(contrib_dir_path)
# For each specified contrib rule, check whether it exists among the contrib classes
for rule_id_or_name in self.contrib:
rule_class = next((rc for rc in rule_classes if
rc.id == ustr(rule_id_or_name) or rc.name == ustr(rule_id_or_name)), False)
# If contrib rule exists, instantiate it and add it to the rules list
if rule_class:
self.rules.add_rule(rule_class, rule_class.id, {'is_contrib': True})
else:
raise LintConfigError(u"No contrib rule with id or name '{0}' found.".format(ustr(rule_id_or_name)))
except (options.RuleOptionError, rules.UserRuleError) as e:
raise LintConfigError(ustr(e))