-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild_version.py
executable file
·66 lines (57 loc) · 2.53 KB
/
build_version.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
#!/usr/bin/env python3
# To build a new VERSION of this library for PyPI, do the following:
import os
from os import path
import subprocess
import sys
import re
path_repo = path.dirname(path.abspath(__file__))
sys.path.append(path_repo)
from config import PATH
# helpers
# input = raw_input # if using python2
def run(cmd_list):
assert isinstance(cmd_list, list)
# use 'check_output' instead of 'run' if using python2
subprocess.run(cmd_list, check=True)
# Warning message to the script user
PATH['cwd'] = os.getcwd()
if PATH['cwd'] != PATH['repo']:
raise SystemExit('This script MUST be executed from the root of the repository.\nrepo root: {}\nyour cwd : {}'.format(PATH['repo'], PATH['cwd']))
proceed = input('This script will (among other things) perform a git commit, pull, and push. You should be on the master branch and confident. Do you wish to proceed?\n').strip()
if proceed != 'yes':
raise SystemExit('User aborted version builder. No action was taken.')
# Change version number in `VERSION` file.
version_old = open(PATH['version']).read().strip()
version_new = input('The current version number is {}. What should the new version number be?\n'.format(version_old)).strip()
if version_new == version_old:
raise SystemExit('That is the same as the previous version number. You must increment the version number.')
# update VERSION with new version number
print('updating VERSION file...')
with open(PATH['version'], 'w') as file:
file.write(version_new)
# update setup.py with new version number
print('updating setup.py...')
with open(PATH['setup'], 'r') as file:
code = file.read()
line_new = "version = '{}'".format(version_new)
code_new = re.sub(r"""version = ['"].*['"]""", line_new, code)
with open(PATH['setup'], 'w') as file:
file.write(code_new)
# Commit all changes and push to master.
print('git committing and pushing to GitHub...')
run(['git', 'add', PATH['version']])
run(['git', 'add', PATH['setup']])
run(['git', 'commit', '-m', version_new])
run(['git', 'pull'])
run(['git', 'push'])
# git tag with version number and push to github
run(['git', 'tag', version_new])
run(['git', 'push', '--tags', 'origin', 'master'])
# create a distribution for PyPI and upload to PyPI
# detailed instructions here: https://packaging.python.org/tutorials/packaging-projects/
print('uploading version to PyPI...')
run(['python', PATH['setup'], 'sdist'])
PATH['dist_version'] = path.join(PATH['dist'], 'k_combinat_for_sage-{}.tar.gz'.format(version_new))
run(['twine', 'upload', PATH['dist_version']])
print('Version building script completed successfully!')