Example #1
0
  def attempt(self, explain):
    """Attempts to execute the goal's tasks in installed order.

    :param bool explain: If ``True`` then the goal plan will be explained instead of being
                         executed.
    """
    goal_workdir = os.path.join(self._context.options.for_global_scope().pants_workdir,
                                self._goal.name)
    with self._context.new_workunit(name=self._goal.name, labels=[WorkUnitLabel.GOAL]):
      for name, task_type in reversed(self._tasktypes_by_name.items()):
        task_workdir = os.path.join(goal_workdir, name)
        task = task_type(self._context, task_workdir)
        log_config = WorkUnit.LogConfig(level=task.get_options().level, colors=task.get_options().colors)
        with self._context.new_workunit(name=name, labels=[WorkUnitLabel.TASK], log_config=log_config):
          if explain:
            self._context.log.debug('Skipping execution of {} in explain mode'.format(name))
          elif task.skip_execution:
            self._context.log.info('Skipping {}'.format(name))
          else:
            task.execute()

      if explain:
        reversed_tasktypes_by_name = reversed(self._tasktypes_by_name.items())
        goal_to_task = ', '.join(
            '{}->{}'.format(name, task_type.__name__) for name, task_type in reversed_tasktypes_by_name)
        print('{goal} [{goal_to_task}]'.format(goal=self._goal.name, goal_to_task=goal_to_task))
Example #2
0
 def docker_workunit(self, name, cmd):
     return self.context.new_workunit(
         name=name,
         labels=[WorkUnitLabel.TOOL, WorkUnitLabel.RUN],
         log_config=WorkUnit.LogConfig(level=self.get_options().level,
                                       colors=self.get_options().colors),
         cmd=' '.join(cmd))
Example #3
0
 def workunit_for(group_member, desc):
     log_config = WorkUnit.LogConfig(
         level=group_member.get_options().level,
         colors=group_member.get_options().colors)
     with self.context.new_workunit(name='{}-{}'.format(
             group_member.name(), desc),
                                    log_config=log_config) as workunit:
         yield workunit
Example #4
0
    def execute(self):
        mypy_interpreter = self.find_mypy_interpreter()
        if not mypy_interpreter:
            raise TaskError(
                'Unable to find a Python {} interpreter (required for mypy).'.
                format(self._MYPY_COMPATIBLE_INTERPETER_CONSTRAINT))

        sources = self._calculate_python_sources(self.context.target_roots)
        if not sources:
            self.context.log.debug('No Python sources to check.')
            return

        # Determine interpreter used by the sources so we can tell mypy.
        interpreter_for_targets = self._interpreter_cache.select_interpreter_for_targets(
            self.context.target_roots)
        if not interpreter_for_targets:
            raise TaskError(
                'No Python interpreter compatible with specified sources.')

        with temporary_file_path() as sources_list_path:
            with open(sources_list_path, 'w') as f:
                for source in sources:
                    f.write('{}\n'.format(source))

            # Construct the mypy command line.
            cmd = [
                '--python-version={}'.format(
                    interpreter_for_targets.identity.python)
            ]
            if self.get_options().config_file:
                cmd.append('--config-file={}'.format(
                    os.path.join(get_buildroot(),
                                 self.get_options().config_file)))
            cmd.extend(self.get_passthru_args())
            cmd.append('@{}'.format(sources_list_path))
            self.context.log.debug('mypy command: {}'.format(' '.join(cmd)))

            # Collect source roots for the targets being checked.
            source_roots = self._collect_source_roots()

            mypy_path = os.pathsep.join(
                [os.path.join(get_buildroot(), root) for root in source_roots])

            # Execute mypy.
            with self.context.new_workunit(
                    name='check',
                    labels=[WorkUnitLabel.TOOL, WorkUnitLabel.RUN],
                    log_config=WorkUnit.LogConfig(
                        level=self.get_options().level,
                        colors=self.get_options().colors),
                    cmd=' '.join(cmd)) as workunit:
                returncode = self._run_mypy(mypy_interpreter,
                                            cmd,
                                            env={'MYPYPATH': mypy_path},
                                            stdout=workunit.output('stdout'),
                                            stderr=subprocess.STDOUT)
                if returncode != 0:
                    raise TaskError('mypy failed: code={}'.format(returncode))
Example #5
0
    def execute(self):
        # type: () -> None

        py3_interpreter = self.get_options().py3_path
        if not os.path.isfile(py3_interpreter):
            raise TaskError(
                'Unable to find a Python 3.x interpreter (required for MyPy).')

        sources = self._calculate_python_sources(self.context.target_roots)
        if not sources:
            self.context.log.debug('No Python sources to check.')
            return

        # Determine interpreter used by the sources so we can tell MyPy.
        interpreter_for_targets = self._interpreter_cache.select_interpreter_for_targets(
            self.context.target_roots)
        target_python_version = interpreter_for_targets.identity.python
        if not interpreter_for_targets:
            raise TaskError(
                'No Python interpreter compatible with specified sources.')

        mypy_options = [
            '--python-version={}'.format(target_python_version),
        ]

        if self.get_options().config_file:
            mypy_options.append('--config-file={}'.format(
                self.get_options().config_file))

        if self.get_options().ignore_missing_imports:
            mypy_options.append('--ignore-missing-imports')

        cmd = [py3_interpreter, '-m', 'mypy'
               ] + mypy_options + self.get_passthru_args() + sources
        self.context.log.debug('mypy command: {}'.format(' '.join(cmd)))

        with self.context.new_workunit(
                name='check',
                labels=[WorkUnitLabel.TOOL, WorkUnitLabel.RUN],
                log_config=WorkUnit.LogConfig(
                    level=self.get_options().level,
                    colors=self.get_options().colors),
                cmd=' '.join(cmd)) as workunit:
            proc = subprocess.Popen(cmd,
                                    stdout=workunit.output('stdout'),
                                    stderr=subprocess.STDOUT)
            return_code = proc.wait()
            if not self.get_options().warning_only and return_code != 0:
                raise TaskError('mypy failed: code={}'.format(return_code))
Example #6
0
    def execute(self):
        # type: () -> None
        opts = self.get_options()
        tag = opts.only

        sources = self._calculate_python_sources(self.context.target_roots,
                                                 tag)
        if not sources:
            self.context.log.debug('No Python sources to check.')
            return

        futurize_opts = ['-j8']

        if opts.stage == 1:
            futurize_opts.append('-1')
        elif opts.stage == 2:
            futurize_opts.append('-2')
        else:
            raise TaskError(
                '--stage can only have a value of 1 or 2, not {}'.format(
                    opts.stage))

        if not opts.check:
            futurize_opts.extend(['-w', '-n', '--no-diff'])

        cmd = ['.pvenvs/fs/bin/futurize'
               ] + futurize_opts + self.get_passthru_args() + sources
        self.context.log.debug('futurize command: {}'.format(' '.join(cmd)))

        with self.context.new_workunit(
                name='check',
                labels=[WorkUnitLabel.TOOL, WorkUnitLabel.RUN],
                log_config=WorkUnit.LogConfig(
                    level=self.get_options().level,
                    colors=self.get_options().colors),
                cmd=' '.join(cmd)) as workunit:
            proc = subprocess.Popen(cmd,
                                    stdout=workunit.output('stdout'),
                                    stderr=subprocess.STDOUT)
            return_code = proc.wait()

            if return_code != 0:
                raise TaskError('futurize failed: code={}'.format(return_code))
Example #7
0
    def execute(self):
        sources = self._calculate_python_sources(self.context.target_roots)
        if not sources:
            self.context.log.debug('No Python sources to check.')
            return

        cmd = [self.get_options().py3_path, '-m', 'mypy', '-2'
               ] + self.get_passthru_args() + sources
        self.context.log.debug('mypy command: {}'.format(' '.join(cmd)))

        with self.context.new_workunit(
                name='check',
                labels=[WorkUnitLabel.TOOL, WorkUnitLabel.RUN],
                log_config=WorkUnit.LogConfig(
                    level=self.get_options().level,
                    colors=self.get_options().colors),
                cmd=' '.join(cmd)) as workunit:
            proc = subprocess.Popen(cmd,
                                    stdout=workunit.output('stdout'),
                                    stderr=subprocess.STDOUT)
            returncode = proc.wait()
            if returncode != 0:
                raise TaskError('mypy failed: code={}'.format(returncode))