wbond | 0a94e28 | 2016-03-17 11:54:44 -0400 | [diff] [blame] | 1 | # coding: utf-8 |
| 2 | from __future__ import unicode_literals, division, absolute_import, print_function |
| 3 | |
wbond | 0a94e28 | 2016-03-17 11:54:44 -0400 | [diff] [blame] | 4 | import subprocess |
| 5 | import sys |
| 6 | |
wbond | 0a94e28 | 2016-03-17 11:54:44 -0400 | [diff] [blame] | 7 | import twine.cli |
| 8 | |
wbond | bba5d62 | 2019-09-09 01:53:00 -0400 | [diff] [blame] | 9 | from . import package_name, package_root, has_tests_package |
| 10 | from .build import run as build |
wbond | 0a94e28 | 2016-03-17 11:54:44 -0400 | [diff] [blame] | 11 | |
| 12 | |
| 13 | def 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, |
wbond | 31b6675 | 2018-04-20 11:02:59 -0400 | [diff] [blame] | 26 | cwd=package_root |
wbond | 0a94e28 | 2016-03-17 11:54:44 -0400 | [diff] [blame] | 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, |
wbond | 31b6675 | 2018-04-20 11:02:59 -0400 | [diff] [blame] | 39 | cwd=package_root |
wbond | 0a94e28 | 2016-03-17 11:54:44 -0400 | [diff] [blame] | 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 | |
wbond | fd2b7cb | 2016-03-18 14:25:48 -0400 | [diff] [blame] | 52 | tag = tag.decode('ascii').strip() |
wbond | 0a94e28 | 2016-03-17 11:54:44 -0400 | [diff] [blame] | 53 | |
wbond | bba5d62 | 2019-09-09 01:53:00 -0400 | [diff] [blame] | 54 | build() |
wbond | 99459d3 | 2016-03-17 11:58:20 -0400 | [diff] [blame] | 55 | |
wbond | 31b6675 | 2018-04-20 11:02:59 -0400 | [diff] [blame] | 56 | twine.cli.dispatch(['upload', 'dist/%s-%s*' % (package_name, tag)]) |
wbond | bba5d62 | 2019-09-09 01:53:00 -0400 | [diff] [blame] | 57 | if has_tests_package: |
| 58 | twine.cli.dispatch(['upload', 'dist/%s_tests-%s*' % (package_name, tag)]) |
wbond | 99459d3 | 2016-03-17 11:58:20 -0400 | [diff] [blame] | 59 | |
wbond | bba5d62 | 2019-09-09 01:53:00 -0400 | [diff] [blame] | 60 | return True |