• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# coding: utf-8
2from __future__ import unicode_literals, division, absolute_import, print_function
3
4import subprocess
5import sys
6
7import twine.cli
8
9from . import package_name, package_root, has_tests_package
10from .build import run as build
11
12
13def run():
14    """
15    Creates a sdist .tar.gz and a bdist_wheel --univeral .whl and uploads
16    them to pypi
17
18    :return:
19        A bool - if the packaging and upload process was successful
20    """
21
22    git_wc_proc = subprocess.Popen(
23        ['git', 'status', '--porcelain', '-uno'],
24        stdout=subprocess.PIPE,
25        stderr=subprocess.STDOUT,
26        cwd=package_root
27    )
28    git_wc_status, _ = git_wc_proc.communicate()
29
30    if len(git_wc_status) > 0:
31        print(git_wc_status.decode('utf-8').rstrip(), file=sys.stderr)
32        print('Unable to perform release since working copy is not clean', file=sys.stderr)
33        return False
34
35    git_tag_proc = subprocess.Popen(
36        ['git', 'tag', '-l', '--contains', 'HEAD'],
37        stdout=subprocess.PIPE,
38        stderr=subprocess.PIPE,
39        cwd=package_root
40    )
41    tag, tag_error = git_tag_proc.communicate()
42
43    if len(tag_error) > 0:
44        print(tag_error.decode('utf-8').rstrip(), file=sys.stderr)
45        print('Error looking for current git tag', file=sys.stderr)
46        return False
47
48    if len(tag) == 0:
49        print('No git tag found on HEAD', file=sys.stderr)
50        return False
51
52    tag = tag.decode('ascii').strip()
53
54    build()
55
56    twine.cli.dispatch(['upload', 'dist/%s-%s*' % (package_name, tag)])
57    if has_tests_package:
58        twine.cli.dispatch(['upload', 'dist/%s_tests-%s*' % (package_name, tag)])
59
60    return True
61