forked from pvcraven/pygame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.travis_osx_upload_whl.py
66 lines (55 loc) · 1.61 KB
/
.travis_osx_upload_whl.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
""" Uploads wheels to pypi from travisci.
The commit requires an UPLOAD line.
"""
import glob
import os
import subprocess
import sys
def write_config():
"""
# Set these inside travis. Note, it is on a per repo basis.
# https://docs.travis-ci.com/user/environment-variables/#Encrypting-Variables-Using-a-Public-Key
# travis encrypt PYPI_USERNAME=super_secret --add
# travis encrypt PYPI_PASSWD=super_secret --add
"""
if not os.environ.get('PYPI_USERNAME', None):
return
username = os.environ['PYPI_USERNAME']
password = os.environ['PYPI_PASSWD']
pypirc_template = """\
[distutils]
index-servers =
pypi
[pypi]
repository: https://upload.pypi.io/legacy/
username: {username}
password: {password}
""".format(username=username, password=password)
with open('pypirc', 'w') as afile:
afile.write(pypirc_template)
if '--write-config' in sys.argv:
write_config()
sys.exit(0)
else:
if '--no-config' not in sys.argv:
write_config()
# if --no-git we do not check with git if an upload is needed.
do_git_check = '--no-git' not in sys.argv
if do_git_check:
commit = subprocess.check_output(['git', 'log', '-1'])
print(commit)
if b'UPLOAD' not in commit:
print('Not uploading')
sys.exit(0)
# There should be exactly one .whl
filenames = glob.glob('dist/*.whl')
print('Calling twine to upload...')
try:
for filename in filenames:
cmd = ['twine', 'upload', '--config-file', 'pypirc', filename]
print(' '.join(cmd))
subprocess.check_call(cmd)
except:
print('is twine installed?')
finally:
os.unlink('pypirc')