-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathdeploy.py
67 lines (55 loc) · 1.9 KB
/
deploy.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
67
from shutil import rmtree
import subprocess
from os import path
from sys import exit
from sh import git
def make_dist():
subprocess.call(['python3', 'setup.py', 'sdist', 'bdist_wheel', 'bdist_egg'])
def twine_upload():
subprocess.call(['twine', 'upload', 'dist/*'])
def clean():
if path.exists('dist'):
rmtree('dist')
vers = input('Did you change the version? (y/n) ')
if vers != 'y' and vers != 'n':
print('Expected "y" or "n", instead found {}. Exiting.'.format(vers))
exit(1)
if vers == 'n':
exit(0)
status = git.status()
branch = git.branch()
if 'master' not in branch:
print('Must be on branch "master". Exiting.')
exit(1)
if 'Changes not staged for commit' in status or 'Untracked files' in status or 'Changes to be committed' in status:
# get user input for if they want to commit all current changes
# and continue with the deploy script
# exit if no
commit = input('Changes were detected, would you like to commit all current changes? (y/n) ')
if commit != 'y' and commit != 'n':
print('Expected "y" or "n", instead found {}. Exiting.'.format(commit))
exit(1)
elif commit == 'n':
print('Not committing changes; please commit all changes and try again. Exiting.')
print(status)
exit(2)
commit_msg = input('Committing, please provide a commit message: ')
git.add('.')
git.commit('-am', commit_msg)
push_result = git.push()
print(push_result)
if 'Your branch is ahead of' in status:
print('Found unpushed commits. Pushing...')
push_result = git.push()
print(push_result)
clean()
make_dist()
upld = input('About to upload to PyPi, are you sure you want to do this? (y/n) ')
if upld != 'y' and upld != 'n':
print('Expected "y" or "n", instead found {}. Exiting.'.format(upld))
exit(1)
if upld == 'n':
print('Not uploading. Exiting.')
exit(1)
print('Uploading...')
twine_upload()