Skip to content

Commit

Permalink
Updated version updater to also update version in doc
Browse files Browse the repository at this point in the history
  • Loading branch information
Espen Flage-Larsen committed Feb 21, 2019
1 parent 94c1592 commit 9d84a4f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@
# built documents.
#
# The short X.Y version.
version = '1.1'
version = 1.1
# The full version, including alpha/beta/rc tags.
release = '1.1.0'
release = 1.1.0

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
29 changes: 29 additions & 0 deletions ops/update_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,24 @@ def __init__(self):
self.top_level_init = py_path.local(
subpath('src', 't4me', '__init__.py'))
self.setup_json = py_path.local(subpath('setup.json'))
self.conf_file = py_path.local(subpath('docs', 'conf.py'))
self.version = self.get_version()

def write_to_doc(self):
"""Write version to the docs."""
with open(self.conf_file.strpath, 'r') as conf_fo:
lines = conf_fo.readlines()

for index, line in enumerate(lines):
if 'version = ' in line:
lines[index] = 'version = ' + str(self.version).rsplit(
'.', 1)[0] + '\n'
if 'release = ' in line:
lines[index] = 'release = ' + str(self.version) + '\n'

with open(self.conf_file.strpath, 'w') as conf_fo:
conf_fo.writelines(lines)

def write_to_init(self):
"""Write version to init."""
init_content = self.top_level_init.read()
Expand All @@ -70,6 +86,16 @@ def setup_version(self):
"""Fetch version from setup.json."""
return version.parse(json.load(self.setup_json)['version'])

@property
def doc_version(self):
"""Fetch version from docs."""
with open(self.conf_file.strpath, 'r') as conf_fo:
for line in conf_fo:
if 'release = ' in line:
version_string = line.split('=')[1].strip()

return version.parse(version_string)

@property
def init_version(self):
"""Fetch version from the init file."""
Expand Down Expand Up @@ -98,6 +124,9 @@ def get_version(self):
return max(self.setup_version, self.init_version, self.tag_version)

def sync(self):
"""Update respective versions."""
if self.version > self.doc_version:
self.write_to_doc()
if self.version > self.init_version:
self.write_to_init()
if self.version > self.setup_version:
Expand Down

0 comments on commit 9d84a4f

Please sign in to comment.