[narval] add a pypi.upload checker
authorDavid Douard <david.douard@logilab.fr>
Wed, 14 May 2014 15:07:42 +0200
changeset 1517 b7c29a8b16ec
parent 1516 cb61ef3751db
child 1518 fd0a087f6117
[narval] add a pypi.upload checker cen be used to upload a tarball on pypi
_narval/checkers/apycot/pypi.py
recipes.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/_narval/checkers/apycot/pypi.py	Wed May 14 15:07:42 2014 +0200
@@ -0,0 +1,43 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import os
+import subprocess
+import sys
+
+from apycotlib import Command
+
+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'
+            },
+        }
+
+    def run(self, test, path=None):
+        """run the distutils 'setup.py register sdist upload' command
+
+        The user running the narval bot must have a properly filled
+        .pypirc file
+        """
+        if path is None:
+            path = test.project_path()
+        if not exists(join(path, 'setup.py')):
+            raise SetupException('No file %s' % abspath(join(path, 'setup.py')))
+        python = pyversions(test)[0]
+        cmdargs = [python, 'setup.py', 'register', 'sdist', 'upload']
+        if not self.options.get('verbose'):
+            cmdargs.append('--quiet')
+        cmd = 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)
--- a/recipes.py	Wed May 14 12:34:52 2014 +0200
+++ b/recipes.py	Wed May 14 15:07:42 2014 +0200
@@ -66,3 +66,16 @@
                                  script=scenario_runner_script)
 
 
+pypi_script = u'''
+# A simple recipe that uploads a project on pypi (if unit tests are OK)
+
+from checkers.apycot import pypi # must be first (trigger registration)
+from apycotlib import narvalactions as na
+# `plan`
+
+with na.apycot_environment(plan) as test:
+    test.checkout(plan)
+    checker, status = test.run_checker('pyunit')
+    if status > ERROR:
+        checker, status = test.run_checker('pypi.upload')
+'''