Beispiel #1
0
def run_pylint():
    from pylint.lint import Run as PylintRun

    try:
        PylintRun(sys.argv[1:])
    except KeyboardInterrupt:
        sys.exit(1)
Beispiel #2
0
def run_pylint():
    """run pylint"""

    try:
        PylintRun(sys.argv[1:])
    except KeyboardInterrupt:
        sys.exit(1)
Beispiel #3
0
    def run(self: PylintRunner) -> ToolResult:
        """Run pylint."""
        with patch("sys.stdout", self.make_logger(TextIOLogger, logging.INFO)):
            try:
                PylintRun([str(p) for p in self.src_paths])

                return ToolResult.SUCCESS

            except SystemExit as sysexit:
                return ToolResult.SUCCESS if sysexit.code == 0 else ToolResult.FAILURE
Beispiel #4
0
def run_pylint(argv: Optional[Sequence[str]] = None):
    """Run pylint.

    argv can be a sequence of strings normally supplied as arguments on the command line
    """
    from pylint.lint import Run as PylintRun

    try:
        PylintRun(argv or sys.argv[1:])
    except KeyboardInterrupt:
        sys.exit(1)
Beispiel #5
0
    def python_tests(self, base_dir=None, pylint_rc_file=None):  # noqa pylint: disable=too-many-branches,too-many-locals
        """Run python tests."""
        from pylint.lint import Run as PylintRun

        if base_dir is None:
            base_dir = self.env_root
        if pylint_rc_file is None:
            if os.path.isfile(os.path.join(base_dir, '.pylintrc')):
                pylint_config = [
                    "--rcfile=%s" % os.path.join(base_dir, '.pylintrc')
                ]
            else:
                # Only reporting on errors ('-E') overrides any ignored errors
                # set in .pylintrc, so it is only being used here when a
                # pylint configuration file is not being used.
                pylint_config = ['-E']

        # Check all python files in repo
        dirs_to_skip = set(['.git',
                            'node_modules',
                            '.serverless'])
        nonblueprint_files = []
        blueprint_files = []
        for root, dirs, files in os.walk(base_dir):
            dirs[:] = [d for d in dirs if d not in dirs_to_skip]
            for name in files:
                filepath = os.path.join(root, name)
                if name[-3:] == '.py' and (
                        root.endswith('blueprints') and
                        not filepath.endswith('__init__.py')):
                    blueprint_files.append(filepath)
                elif name[-3:] == '.py':
                    nonblueprint_files.append(filepath)

        if nonblueprint_files + blueprint_files:
            LOGGER.info("Checking python files with pylint (\"No config file "
                        "found...\" messages can be ignored)")
            with use_embedded_pkgs():  # for embedded stacker
                with ignore_exit_code_0():
                    LOGGER.debug("Executing pylint with the following options: \"%s\"",  # noqa
                                 ' '.join(pylint_config + nonblueprint_files + blueprint_files))  # noqa pylint: disable=line-too-long
                    PylintRun(pylint_config + nonblueprint_files + blueprint_files)  # noqa
            LOGGER.info('pylint complete.')
            for filepath in blueprint_files:
                # Blueprints should output their template when executed
                ensure_file_is_executable(filepath)
                try:
                    shell_out_env = os.environ.copy()
                    if 'PYTHONPATH' in shell_out_env:
                        shell_out_env['PYTHONPATH'] = (
                            "%s:%s" % (get_embedded_lib_path(),
                                       shell_out_env['PYTHONPATH'])
                        )
                    else:
                        shell_out_env['PYTHONPATH'] = get_embedded_lib_path()
                    cfn_template = check_output(
                        [sys.executable, filepath],
                        env=shell_out_env
                    ).decode()
                    if not cfn_template:
                        raise ValueError('Template output should not be empty!')  # noqa
                    parse_cloudformation_template(cfn_template)
                except:  # noqa - Bare except fine in this context
                    print("Error while checking %s for valid "
                          "YAML/JSON output" % filepath)
                    raise