Exemple #1
0
    def get_image_name(self, files):
        """Run container command to install eslint plugins
        """
        if not self.options.get('install_plugins', False):
            return 'eslint'

        container_name = docker.generate_container_name('eslint', files)
        if self.custom_image is None:
            log.info('Installing eslint plugins into %s', container_name)
            output = docker.run(
                'eslint',
                ['eslint-install'],
                source_dir=self.base_path,
                name=container_name)

            docker.commit(container_name)
            docker.rm_container(container_name)
            self.custom_image = container_name

            installed = [
                line.strip('add:')
                for line in output.splitlines()
                if line.startswith('add:')
            ]
            log.info('Installed eslint plugins %s', installed)
        return container_name
Exemple #2
0
    def process_fixer(self, files):
        """
        Autofixing typing errors requires generating type
        stubs and then applying them individually.
        """
        command = self._apply_options(['pytype'])
        command += files

        container_name = self._container_name(files)

        # run in a container that sticks around so we can
        # run merge-pyi on the output files.
        docker.run('pytype',
                   command,
                   source_dir=self.base_path,
                   name=container_name)

        buildlog.info('Creating cusotm image for pytype')
        docker.commit(container_name)
        docker.rm_container(container_name)

        update_command = ['merge-pyi-wrapper']
        update_command += files

        # Apply merge-pyi
        try:
            out = docker.run(container_name,
                             update_command,
                             source_dir=self.base_path)
        except Exception as e:
            buildlog.warning('Pytype merging failed. error=%s output=%s', e,
                             out)
        finally:
            buildlog.info('Removing custom pytype image')
            docker.rm_image(container_name)
Exemple #3
0
    def test_run__named_container(self):
        cmd = ['echo', "things"]
        docker.run('python2', cmd, test_dir, name='test_container')
        containers = docker.containers(include_stopped=True)
        self.assertIn('test_container', containers)
        docker.rm_container('test_container')

        containers = docker.containers(include_stopped=True)
        assert 'test_conainer' not in containers
Exemple #4
0
    def test_run__named_container(self):
        cmd = ['echo', "things"]
        docker.run('python2', cmd, test_dir, name='test_container')
        containers = docker.containers(include_stopped=True)
        self.assertIn('test_container', containers)
        docker.rm_container('test_container')

        containers = docker.containers(include_stopped=True)
        assert 'test_conainer' not in containers
Exemple #5
0
    def install_plugins(self, container_name):
        """Run container command to install eslint plugins
        """
        if not self.options.get('install_plugins', False):
            return

        if self.installed_plugins is False:
            log.info('Installing eslint plugins into %s', container_name)
            docker.run('eslint', ['eslint-install'],
                       source_dir=self.base_path,
                       name=container_name)

            docker.commit(container_name)
            docker.rm_container(container_name)
            self.installed_plugins = True
Exemple #6
0
    def get_image_name(self, files):
        """Get the image name based on options

        If the `plugin` option is used a custom image will
        be created.
        """
        image = python_image(self.options)
        plugins = self.options.get('plugins', None)
        if not plugins:
            return image
        if not isinstance(plugins, list):
            plugin_type = plugins.__class__.__name__
            error = IssueComment(
                u'The `flake8.plugins` option must be a list got `{}` instead.'.format(
                    plugin_type
                )
            )
            self.problems.add(error)
            return image

        invalid_plugins = [
            p for p in plugins
            if p not in self.ALLOWED_PLUGINS]
        if invalid_plugins:
            error = IssueComment(
                u'The `flake8.plugins` option contained unsupported plugins {}'.format(
                    u', '.join(invalid_plugins)
                )
            )
            self.problems.add(error)
            return image

        container_name = docker.generate_container_name('flake8', files)
        if self.custom_image is None:
            buildlog.info('Installing flake8 plugins')

            docker.run(
                image,
                ['flake8-install', u','.join(plugins)],
                source_dir=self.base_path,
                name=container_name
            )
            docker.commit(container_name)
            docker.rm_container(container_name)
            self.custom_image = container_name
            buildlog.info('Installed flake8 plugins %s', plugins)

        return container_name
Exemple #7
0
    def install_plugins(self, container_name):
        """Run container command to install eslint plugins
        """
        if not self.options.get('install_plugins', False):
            return

        if self.installed_plugins is False:
            log.info('Installing eslint plugins into %s', container_name)
            docker.run(
                'eslint',
                ['eslint-install'],
                source_dir=self.base_path,
                name=container_name)

            docker.commit(container_name)
            docker.rm_container(container_name)
            self.installed_plugins = True
Exemple #8
0
    def install_plugins(self, container_name):
        """Run container command to install eslint plugins
        """
        if not self.options.get('install_plugins', False):
            return

        if self.installed_plugins is False:
            log.info('Installing eslint plugins into %s', container_name)
            output = docker.run('eslint', ['eslint-install'],
                                source_dir=self.base_path,
                                name=container_name)

            docker.commit(container_name)
            docker.rm_container(container_name)
            self.installed_plugins = True
            installed = [
                line.strip('add:') for line in output.splitlines()
                if line.startswith('add:')
            ]
            log.info('Installed eslint plugins %s', installed)
Exemple #9
0
    def process_fixer(self, files):
        """
        Autofixing typing errors requires generating type
        stubs and then applying them individually.
        """
        command = self._apply_options(['pytype'])
        command += files

        container_name = self._container_name(files)

        # run in a container that sticks around so we can
        # run merge-pyi on the output files.
        docker.run(
            'python3',
            command,
            source_dir=self.base_path,
            name=container_name)

        log.info('Creating temporary image for %s', container_name)
        docker.commit(container_name)
        docker.rm_container(container_name)

        update_command = ['merge-pyi-wrapper']
        update_command += files

        # Apply merge-pyi
        try:
            out = docker.run(
                container_name,
                update_command,
                source_dir=self.base_path
            )
        except Exception as e:
            log.warning('Pytype merging failed. error=%s output=%s', e, out)
        finally:
            log.info('Removing temporary image for %s', container_name)
            docker.rm_image(container_name)
Exemple #10
0
    def get_image_name(self, files):
        """Get the image name based on options

        If the `standard` option that is an optional package
        the a custom image will be created.
        """
        image = 'php'

        standard = self.options.get('standard', None)
        if not standard or standard not in OPTIONAL_PACKAGES:
            return image

        if not isinstance(standard, str):
            error = IssueComment(
                u'The `phpcs.standard` option must be a string got `{}` instead.'.format(
                    standard.__class__.__name__
                )
            )
            self.problems.add(error)
            return image

        container_name = docker.generate_container_name('phpcs-', files)
        if self.custom_image is None:
            buildlog.info('Installing phpcs package')

            docker.run(
                image,
                ['phpcs-install', OPTIONAL_PACKAGES[standard].package],
                source_dir=self.base_path,
                name=container_name
            )
            docker.commit(container_name)
            docker.rm_container(container_name)
            self.custom_image = container_name
            buildlog.info('Installed phpcs package %s', standard)

        return container_name