Ejemplo n.º 1
0
    def checkstyle(self, interpreter, sources):
        """Iterate over sources and run checker on each file.

        Files can be suppressed with a --suppress option which takes an xml file containing
        file paths that have exceptions and the plugins they need to ignore.

        :param sources: iterable containing source file names.
        :return: (int) number of failures
        """
        checker = self.checker_pex(interpreter)

        args = [
            "--root-dir={}".format(get_buildroot()),
            "--severity={}".format(self.get_options().severity),
        ]
        if self.get_options().suppress:
            args.append("--suppress={}".format(self.get_options().suppress))
        if self.get_options().strict:
            args.append("--strict")

        with temporary_file(binary_mode=False) as argfile:
            for plugin_subsystem in self.plugin_subsystems:
                options_blob = plugin_subsystem.global_instance().options_blob(
                )
                if options_blob:
                    argfile.write("--{}-options={}\n".format(
                        plugin_subsystem.plugin_type().name(), options_blob))
            argfile.write("\n".join(sources))
            argfile.close()

            args.append("@{}".format(argfile.name))

            with self.context.new_workunit(
                    name="pythonstyle",
                    labels=[WorkUnitLabel.TOOL, WorkUnitLabel.LINT],
                    cmd=" ".join(checker.cmdline(args)),
            ) as workunit:
                return checker.run(args=args,
                                   stdout=workunit.output("stdout"),
                                   stderr=workunit.output("stderr"))
Ejemplo n.º 2
0
  def checkstyle(self, interpreter, sources):
    """Iterate over sources and run checker on each file.

    Files can be suppressed with a --suppress option which takes an xml file containing
    file paths that have exceptions and the plugins they need to ignore.

    :param sources: iterable containing source file names.
    :return: (int) number of failures
    """
    checker = self.checker_pex(interpreter)

    args = [
      '--root-dir={}'.format(get_buildroot()),
      '--severity={}'.format(self.get_options().severity),
    ]
    if self.get_options().suppress:
      args.append('--suppress={}'.format(self.get_options().suppress))
    if self.get_options().strict:
      args.append('--strict')

    with temporary_file(binary_mode=False) as argfile:
      for plugin_subsystem in self.plugin_subsystems:
        options_blob = plugin_subsystem.global_instance().options_blob()
        if options_blob:
          argfile.write('--{}-options={}\n'.format(plugin_subsystem.plugin_type().name(),
                                                   options_blob))
      argfile.write('\n'.join(sources))
      argfile.close()

      args.append('@{}'.format(argfile.name))

      with self.context.new_workunit(name='pythonstyle',
                                     labels=[WorkUnitLabel.TOOL, WorkUnitLabel.LINT],
                                     cmd=' '.join(checker.cmdline(args))) as workunit:
        return checker.run(args=args,
                                    stdout=workunit.output('stdout'),
                                    stderr=workunit.output('stderr'))