Skip to content
Snippets Groups Projects
Commit 0d85deeb authored by Mads M. Pedersen's avatar Mads M. Pedersen
Browse files

add functions to update version and make new release

parent be0af2e0
No related branches found
Tags 2.0
No related merge requests found
Pipeline #66283 canceled
from py_wake.utils import git_utils
from py_wake.utils.git_utils import _run_git_cmd, git_path
MAJOR = 0
MINOR = 1
PATCH = 2
def get_tag(git_repo_path=None):
return _run_git_cmd(['git', 'describe', '--tags', '--abbrev=0'], git_repo_path)
def set_tag(tag, push, git_repo_path=None):
_run_git_cmd(["git", "tag", tag], git_repo_path)
if push:
_run_git_cmd(["git", "push"], git_repo_path)
_run_git_cmd(["git", "push", "--tags"], git_repo_path)
def new_release(level=MINOR):
"""Make new tagged release"""
if 'dirty' in git_utils.get_git_version(git_path):
raise Exception("Commit before making new release")
last_tag = get_tag(git_path)
def next_tag(tag):
return ".".join([str(int(n) + (0, 1)[i == level]) for i, n in enumerate(tag.split(".")[:2] + [0])])
new_tag = next_tag(last_tag)
print("Making tag:", new_tag)
set_tag(new_tag, push=True, git_repo_path=git_path)
print('Done', new_tag)
if __name__ == '__main__':
import sys
if len(sys.argv) == 2:
new_release(int(sys.argv[1]))
else:
new_release()
__version__ = '716d65a-dirty'
import os
import subprocess
import py_wake
git_path = os.path.dirname(py_wake.__file__) + "/../"
def _run_git_cmd(cmd, git_repo_path=None):
git_repo_path = git_repo_path or os.getcwd()
if not os.path.isdir(os.path.join(git_repo_path, ".git")):
raise Warning("'%s' does not appear to be a Git repository." % git_repo_path)
try:
process = subprocess.Popen(cmd,
stdout=subprocess.PIPE,
universal_newlines=True,
cwd=os.path.abspath(git_repo_path))
stdout = process.communicate()[0]
if process.returncode != 0:
raise EnvironmentError()
return stdout.strip()
except EnvironmentError as e:
raise Warning("Unable to run git\n%s" % str(e))
def get_git_version(git_repo_path=None):
cmd = ["git", "describe", "--tags", "--dirty", "--always"]
return _run_git_cmd(cmd, git_repo_path)
def update_git_version(module, git_repo_path=None):
"""Update <version_module>.__version__ to git version"""
version_str = get_git_version(git_repo_path)
assert os.path.isfile(module.__file__)
with open(module.__file__, "w") as fid:
fid.write("__version__ = '%s'\n" % version_str)
# ensure file is written, closed and ready
with open(module.__file__) as fid:
fid.read()
return version_str
def main():
"""Example of how to run (pytest-friendly)"""
if __name__ == '__main__':
update_git_version(py_wake, git_path)
main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment