blob: a854196b0e4a9f72762f7824e884e8192c10ef4b [file] [log] [blame]
wbond0a94e282016-03-17 11:54:44 -04001# coding: utf-8
2from __future__ import unicode_literals, division, absolute_import, print_function
3
wbond0a94e282016-03-17 11:54:44 -04004import subprocess
5import sys
6
wbond0a94e282016-03-17 11:54:44 -04007import twine.cli
8
wbondbba5d622019-09-09 01:53:00 -04009from . import package_name, package_root, has_tests_package
10from .build import run as build
wbond0a94e282016-03-17 11:54:44 -040011
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,
wbond31b66752018-04-20 11:02:59 -040026 cwd=package_root
wbond0a94e282016-03-17 11:54:44 -040027 )
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,
wbond31b66752018-04-20 11:02:59 -040039 cwd=package_root
wbond0a94e282016-03-17 11:54:44 -040040 )
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
wbondfd2b7cb2016-03-18 14:25:48 -040052 tag = tag.decode('ascii').strip()
wbond0a94e282016-03-17 11:54:44 -040053
wbondbba5d622019-09-09 01:53:00 -040054 build()
wbond99459d32016-03-17 11:58:20 -040055
wbond31b66752018-04-20 11:02:59 -040056 twine.cli.dispatch(['upload', 'dist/%s-%s*' % (package_name, tag)])
wbondbba5d622019-09-09 01:53:00 -040057 if has_tests_package:
58 twine.cli.dispatch(['upload', 'dist/%s_tests-%s*' % (package_name, tag)])
wbond99459d32016-03-17 11:58:20 -040059
wbondbba5d622019-09-09 01:53:00 -040060 return True