| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
from __future__ import (absolute_import, division, print_function, |
| 6 |
unicode_literals) |
| 7 |
|
| 8 |
import glob |
| 9 |
import os |
| 10 |
import shlex |
| 11 |
import shutil |
| 12 |
import subprocess |
| 13 |
import sys |
| 14 |
|
| 15 |
os.chdir(os.path.dirname(os.path.abspath(__file__))) |
| 16 |
|
| 17 |
VERSION = open(os.path.join("mechanize", "_version.py")).\ |
| 18 |
readlines()[0].strip(' "\n') |
| 19 |
|
| 20 |
|
| 21 |
def red(text): |
| 22 |
return '\033[91;1m' + text + '\033[39;22m' |
| 23 |
|
| 24 |
|
| 25 |
def green(text): |
| 26 |
return '\033[92;1m' + text + '\033[39;22m' |
| 27 |
|
| 28 |
|
| 29 |
def run(*cmd): |
| 30 |
if len(cmd) == 1: |
| 31 |
cmd = shlex.split(cmd[0]) |
| 32 |
print(green(' '.join(cmd))) |
| 33 |
ret = subprocess.Popen(cmd).wait() |
| 34 |
if ret != 0: |
| 35 |
raise SystemExit(ret) |
| 36 |
|
| 37 |
|
| 38 |
def build_release(): |
| 39 |
for rem in 'dist build'.split(): |
| 40 |
os.path.exists(rem) and shutil.rmtree(rem) |
| 41 |
run(sys.executable, '-m', 'build') |
| 42 |
|
| 43 |
|
| 44 |
def tag_release(): |
| 45 |
run('git tag -s "v{0}" -m "version-{0}"'.format(VERSION)) |
| 46 |
run('git push origin "v{0}"'.format(VERSION)) |
| 47 |
|
| 48 |
|
| 49 |
def upload_release(): |
| 50 |
files = list(glob.glob('dist/*')) |
| 51 |
run('twine', 'upload', '--config-file', |
| 52 |
os.path.join(os.environ['PENV'], 'pypi'), *files) |
| 53 |
|
| 54 |
|
| 55 |
try: |
| 56 |
myinput = raw_input |
| 57 |
except NameError: |
| 58 |
myinput = input |
| 59 |
|
| 60 |
|
| 61 |
def has_executable(exe): |
| 62 |
for path in os.environ['PATH'].split(os.pathsep): |
| 63 |
if os.access(os.path.join(path, exe), os.X_OK): |
| 64 |
return True |
| 65 |
return False |
| 66 |
|
| 67 |
|
| 68 |
def main(): |
| 69 |
if not has_executable('twine'): |
| 70 |
raise SystemExit('Need to install twine to upload to PyPI') |
| 71 |
if myinput('Publish version {} [y/n]? '.format(red(VERSION))) != 'y': |
| 72 |
raise SystemExit(1) |
| 73 |
build_release() |
| 74 |
if myinput(red('Upload') + ' release [y/n]? ') != 'y': |
| 75 |
raise SystemExit(1) |
| 76 |
tag_release() |
| 77 |
upload_release() |
| 78 |
|
| 79 |
|
| 80 |
if __name__ == '__main__': |
| 81 |
main() |