Commit 3408ec02 authored by Matt Wala's avatar Matt Wala
Browse files

Merge branch 'pylint-flexible-config' into 'master'

Make Pylint more flexible with a YAML-based config

See merge request !17
parents ee199e32 ab8ecd97
Loading
Loading
Loading
Loading

.pylintrc-default

deleted100644 → 0
+0 −814

File deleted.

Preview size limit exceeded, changes collapsed.

.pylintrc-default.yml

0 → 100644
+6 −0
Original line number Diff line number Diff line
- arg: extension-pkg-whitelist
  val: numpy
- arg: disable
  val: all
- arg: enable
  val: E
+13 −5
Original line number Diff line number Diff line
@@ -10,13 +10,21 @@ if [ "$PY_EXE" == "" ]; then
  PY_EXE=python${py_version}
fi

curl -L -O -k https://gitlab.tiker.net/inducer/ci-support/raw/master/build-py-project.sh
curl -L -O -k https://gitlab.tiker.net/inducer/ci-support/raw/pylint-flexible-config/build-py-project.sh
source build-py-project.sh

$PY_EXE -m pip install pylint
curl -L -O -k https://gitlab.tiker.net/inducer/ci-support/raw/pylint-flexible-config/run-pylint.py

if ! test -f .pylintrc; then
  curl -o .pylintrc https://gitlab.tiker.net/inducer/ci-support/raw/master/.pylintrc-default
$PY_EXE -m pip install pylint PyYAML

if ! test -f .pylintrc.yml; then
  curl -o .pylintrc.yml https://gitlab.tiker.net/inducer/ci-support/raw/pylint-flexible-config/.pylintrc-default.yml
fi

PYLINT_RUNNER_ARGS="--yaml-rcfile=.pylintrc.yml"

if test -f .pylintrc-local.yml; then
  PYLINT_RUNNER_ARGS="$PYLINT_RUNNER_ARGS --yaml-rcfile=.pylintrc-local.yml"
fi

python -m pylint "$@"
python run-pylint.py $PYLINT_RUNNER_ARGS "$@"

run-pylint.py

0 → 100755
+76 −0
Original line number Diff line number Diff line
#!/usr/bin/env python
"""This script allows using Pylint with YAML-based config files.

The usage of this script is identical to Pylint, except that this script accepts
an additional argument "--yaml-rcfile=", which specifies a path to a YAML file
from which command line options are derived. The "--yaml-rcfile=" argument may
be given multiple times.

The YAML config file format is a list of "arg"/"val" entries. Multiple or
omitted values are allowed. Repeated arguments are allowed. An example is as
follows:

    ---
    - arg: errors-only
    - arg: ignore
      val:
        - dir1
        - dir2
    - arg: ignore
        val: dir3

This example is equivalent to invoking pylint with the options

    pylint --errors-only --ignore=dir1,dir2 --ignore=dir3

"""

import sys

import pylint.lint
import yaml


def generate_args_from_yaml(input_yaml):
    """Generate a list of strings suitable for use as Pylint args, from YAML.

    Arguments:
        input_yaml: YAML data, as an input file or bytes

    """

    parsed_data = yaml.safe_load(input_yaml)

    for entry in parsed_data:
        arg = entry["arg"]
        val = entry.get("val", None)

        if val is not None:
            if isinstance(val, list):
                val = ",".join(str(item) for item in val)

            yield "--%s=%s" % (arg, val)
        else:
            yield "--%s" % arg


YAML_RCFILE_PREFIX = "--yaml-rcfile="


def main():
    """Process command line args and run Pylint."""
    args = []

    for arg in sys.argv[1:]:
        if arg.startswith(YAML_RCFILE_PREFIX):
            config_path = arg[len(YAML_RCFILE_PREFIX):]
            with open(config_path, "r") as config_file:
                args.extend(generate_args_from_yaml(config_file))
        else:
            args.append(arg)

    pylint.lint.Run(args)


if __name__ == "__main__":
    main()