_narval/checkers/apycot/pypi.py
author David Douard <david.douard@logilab.fr>
Wed, 27 Sep 2017 12:39:06 +0200
changeset 1871 980e20892562
parent 1533 b0d9c98a09de
permissions -rw-r--r--
[checker/pypi] allow to configure the pypi repo to use and defaults to 'pypi'.

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from os.path import exists, join, abspath

import apycotlib

from checkers.apycot import BaseChecker
from preprocessors.apycot.distutils import pyversions

class PypiUploader(BaseChecker):
    id = 'pypi.upload'

    options_def = {
        'verbose': {
            'type': 'int', 'default': False,
            'help': 'set verbose mode'
            },
        'pypi.repository': {
            'default': 'pypi',
            'help': ('name of the pypi repository to use; must exists in '
                     'the .pypirc file of the narval built bot'),
            },
        }

    def do_check(self, test):
        """run the distutils 'setup.py register sdist upload' command

        The user running the narval bot must have a properly filled
        .pypirc file
        """
        path = test.project_path()
        if not exists(join(path, 'setup.py')):
            raise apycotlib.SetupException('No file %s' % abspath(join(path, 'setup.py')))
        python = pyversions(test)[0]
        repo = self.options.get('pypi.repository')

        cmdargs = [python, 'setup.py', 'register',]
        if repo:
            cmdargs += ['-r', repo]
        if self.options.get('verbose'):
            cmdargs.append('-v)
        cmdargs += ['sdist', 'upload']
        if repo:
            cmdargs += ['-r', repo]
        if self.options.get('verbose'):
            cmdargs.append('-v)

        cmd = apycotlib.Command(self.writer, cmdargs, raises=True, cwd=path)
        cmdstatus = cmd.run()
        if cmdstatus == apycotlib.SUCCESS:
            self.writer.info('uploaded tarball to pypi')
        return cmdstatus

apycotlib.register('checker', PypiUploader)