def display_errors(errors: List[Error], options: Namespace): """Format and display the given errors.""" if options.format == "json": LOGGER.warning(dumps([err.to_dict() for err in errors])) else: pattern = MESSAGE_FORMATS.get(options.format, DEFAULT_FORMAT) for err in errors: LOGGER.warning(err.format(pattern))
def parse_options(args=None, config=True, rootdir=pylamaconfig.CURDIR, **overrides): """ Parse options from command line and configuration files. :return argparse.Namespace: """ args = args or [] # Parse args from command string options = pylamaconfig.PARSER.parse_args(args) options.file_params = dict() options.linters_params = dict() # Compile options from ini if config: cfg = get_config(str(options.options), rootdir=rootdir) for opt, val in cfg.default.items(): LOGGER.info("Find option %s (%s)", opt, val) passed_value = getattr(options, opt, pylamaconfig._Default()) if isinstance(passed_value, pylamaconfig._Default): if opt == "paths": val = val.split() elif opt == "skip": val = pylamaconfig.fix_pathname_sep(val) setattr(options, opt, pylamaconfig._Default(val)) # Parse file related options for name, opts in cfg.sections.items(): if name == cfg.default_section: continue if name.startswith(cfg.default_section): name = name[7:] if name in pylamaconfig.LINTERS: options.linters_params[name] = dict(opts) continue mask = re.compile( pylamaconfig.fnmatch.translate(pylamaconfig.fix_pathname_sep(name)) ) options.file_params[mask] = dict(opts) # Override options pylamaconfig._override_options(options, **overrides) # Postprocess options for name in options.__dict__: value = getattr(options, name) if isinstance(value, pylamaconfig._Default): setattr(options, name, pylamaconfig.process_value(name, value.value)) if options.concurrent and "pylint" in options.linters: LOGGER.warning("Can't parse code asynchronously with pylint enabled.") options.concurrent = False return options
def process_paths(options, candidates=None, error=True): """Process files and log errors.""" errors = pylama.check_path(options, rootdir=pylamaconfig.CURDIR, candidates=candidates) pattern = "%(filename)s:%(lnum)s:%(col)s:%(type)s:%(number)s:%(text)s" for er in errors: text = er._info["text"].split() if PATTERN_NUMBER.match(text[0]): er._info["text"] = " ".join(text[1:]) if not er._info["number"]: er._info["number"] = f"0000" if options.abspath: er._info["filename"] = ospath.abspath(er.filename) LOGGER.warning(pattern, er._info) if error: sys.exit(int(bool(errors))) return errors