forked from softlayer/softlayer-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py
67 lines (50 loc) · 1.78 KB
/
fabfile.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
import click
import os.path
import shutil
import subprocess
import sys
from pprint import pprint as pp
def make_html():
"""Build HTML docs"""
click.secho("Building HTML")
subprocess.run('make html', cwd='docs', shell=True)
def upload():
"""Upload distribution to PyPi"""
cmd_setup = 'python setup.py sdist bdist_wheel'
click.secho("\tRunning %s" % cmd_setup, fg='yellow')
subprocess.run(cmd_setup, shell=True)
cmd_twine = 'twine upload dist/*'
click.secho("\tRunning %s" % cmd_twine, fg='yellow')
subprocess.run(cmd_twine, shell=True)
def clean():
click.secho("* Cleaning Repo")
directories = ['.tox', 'SoftLayer.egg-info', 'build', 'dist']
for directory in directories:
if os.path.exists(directory) and os.path.isdir(directory):
shutil.rmtree(directory)
@click.command()
@click.argument('version')
@click.option('--force', default=False, is_flag=True, help="Force upload")
def release(version, force):
"""Perform a release. Example:
$ python fabfile.py 1.2.3
"""
if version.startswith("v"):
exit("Version should not start with 'v'")
version_str = "v%s" % version
clean()
subprocess.run("pip install wheel", shell=True)
print(" * Uploading to PyPI")
upload()
make_html()
force_option = 'f' if force else ''
cmd_tag = "git tag -%sam \"%s\" %s" % (force_option, version_str, version_str)
click.secho(" * Tagging Version %s" % version_str)
click.secho("\tRunning %s" % cmd_tag, fg='yellow')
subprocess.run(cmd_tag, shell=True)
cmd_push = "git push upstream %s" % version_str
click.secho(" * Pushing Tag to upstream")
click.secho("\tRunning %s" % cmd_push, fg='yellow')
subprocess.run(cmd_push, shell=True)
if __name__ == '__main__':
release()