_narval/checkers/apycot/pypi.py
author David Douard <david.douard@logilab.fr>
Fri, 21 Nov 2014 20:07:15 +0100
changeset 1782 69394bafe4bd
parent 1780 d47dfaf9f065
permissions -rw-r--r--
[narval] the lgp_suffix option of lgp.build checker is now used as is it is now the responsibility of the caller to build the desired suffix instead of a hardcoded ~rev<csid>.

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

from os.path import exists, join, abspath

import apycotlib

from checkers.apycot import BaseChecker

class DistutilsBuilder(BaseChecker):
    id = 'distutils.build'

    options_def = {
        'verbose': {
            'type': 'int', 'default': False,
            'help': 'set verbose mode'
            },
        'pypi_repository': {
            'help': ('pypi repository to upload to (URL); make sure this '
                     'repositoy is listed in the .pypirc file; is unset, '
                     'package will NOT be uploaded'),
            'default': '',
            },
        }

    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 = apycotlib.pyversions(test)[0]
        if self.options.get('pypi_repository'):
            repo = str(self.options.get('pypi_repository'))
            cmdargs = [python, 'setup.py', # wonderful setuptools
                       'register', '--repository', repo,
                       'sdist',
                       'upload', '--repository', repo]
        else:
            cmdargs = [python, 'setup.py', 'sdist']
        if not self.options.get('verbose'):
            cmdargs.append('--quiet')
        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', DistutilsBuilder)