Skip to content

Commit

Permalink
[Release Script] nightly check in
Browse files Browse the repository at this point in the history
  • Loading branch information
MinchinWeb committed Aug 30, 2015
1 parent 2e2b69b commit 9043a1d
Showing 1 changed file with 76 additions and 14 deletions.
90 changes: 76 additions & 14 deletions make_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,55 +8,97 @@
import colorama
from colorama import Fore, Style
from minchin import text
from pathlib import Path
import os
import semantic_version

# also requires:
# isort
# git on commandline

__version__ = "0.1.0"

version_re = re.compile(r"__version__ = [\"\']{1,3}(?P<major>\d+)\.(?P<minor>\d+)(.(?P<bug>\d+))?[-\.\w\s]*[\"\']{1,3}")
version_re = re.compile(r"__version__ = [\"\']{1,3}(?P<major>\d+)\.(?P<minor>\d+).(?P<patch>\d+)(?:-(?P<prerelease>[0-9A-Za-z\.]+))?(?:\+[0-9A-Za-z-\.]+)?[\"\']{1,3}")
bare_version_re = re.compile(r"__version__ = [\"\']{1,3}([\.\dA-Za-z+-]*)[\"\']{1,3}")


def here_directory():
return(Path(os.getcwd()))


def source_directory():
return("colourettu")
return(here_directory() / "colourettu")


def test_directory():
return('tests')
return(here_directory() / 'tests')


def version_file():
return(source_directory() + "\\__init__.py")

return(source_directory() / "__init__.py")

def main():
colorama.init()
text.title("Minchin Make Release v{}".format(__version__))

def git_check():
"""Check for uncomitted changes"""
git_status = subprocess.check_output(['git', 'status', '--porcelain'])
if len(git_status) is 0:
print(Fore.GREEN + 'All changes committed' + Style.RESET_ALL)
else:
exit(Fore.RED + 'Please commit all files to continue')


def sort_imports(my_dir):
"""Sort Imports"""
import_status = subprocess.check_output(['isort', '-rc', source_directory()])

import_status = subprocess.check_output(['isort', '-rc', my_dir])
print('{}{}'.format(" "*4, import_status.decode('ascii')))


def run_tests():
"""Run tests"""
test_status = subprocess.check_call(['green', test_directory(), '-vv'])
text.clock_on_right('Run tests')
test_status = subprocess.check_call(['green', str(test_directory()), '-vv'])
if test_status is not 0:
exit(Fore.RED + 'Please make all tests pass to continue')


def update_version_number(update_level='patch'):
"""Update version number"""
text.clock_on_right('Update version number')

"""Find current version"""
with open(str(version_file()), 'r') as f:
for line in f:
version_matches = bare_version_re.match(line)
if version_matches:
bare_version_str = version_matches.groups(0)[0]
if semantic_version.validate(bare_version_str):
current_version = semantic_version.Version(bare_version_str)
print("{}Current version is {}".format(" "*4, current_version))
else:
current_version = semantic_version.Version.coerce(bare_version_str)
if not text.query_yes_quit("{}I think the version is {}. Use it?".format(" "*4, current_version), default="yes"):
exit(Fore.RED + 'Please set an initial version number to continue')

"""Determine new version number"""
if update_level is 'major':
current_version = current_version.next_major()
elif update_level is 'minor':
current_version = current_version.next_minor()
elif update_level is 'patch':
current_version = current_version.next_patch()
elif update_level is 'prerelease':
if not current_version.prerelease:
current_version.prerelease = ('dev', )
else:
exit(Fore.RED + 'Cannot update version in {} mode'.format(update_level))

print("{}New version is {}".format(" "*4, current_version))

"""Update version number"""
with open(version_file(), 'r') as f:
print(f)
current_version = ''

print('Update version number in __init__.py') # use `bumpversion` ?? -- https://pypi.python.org/pypi/bumpversion

def print_all_steps():
print('Update documenation')
print(' cd docs')
print(' make html')
Expand Down Expand Up @@ -90,5 +132,25 @@ def main():
# swtich to twine https://pypi.python.org/pypi/twine/
# twine upload dist/*


def main():
colorama.init()
text.title("Minchin 'Make Release' for Python v{}".format(__version__))
print("base dir -> {}".format(here_directory()))
print("source -> .\{}\\".format(source_directory().relative_to(here_directory())))
print("test dir -> .\{}\\".format(test_directory().relative_to(here_directory())))
print("version file -> .\{}".format(version_file().relative_to(here_directory())))
print()

# git_check()
# text.clock_on_right('Sort import statements')
# sort_imports(str(source_directory()))
# sort_imports(str(test_directory()))
# run_tests()
update_version_number('patch')

# after everything is done
update_version_number('prerelease')

if __name__ == '__main__':
main()

0 comments on commit 9043a1d

Please sign in to comment.