Skip to content

Commit

Permalink
Getting collection version from single source
Browse files Browse the repository at this point in the history
Details:

* Added code in docs conf.py to parse the collection manifest file
  (galaxy.yml) using regular expressions (to avoid the dependency
  on the PyYAML package).

Signed-off-by: Andreas Maier <maiera@de.ibm.com>
  • Loading branch information
andy-maier committed Nov 9, 2020
1 parent 62583d9 commit 0e891cd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ else
ansible-doc-extractor $(module_rst_dir) $<
endif

$(doc_build_dir)/html/index.html: $(doc_rst_files)
$(doc_build_dir)/html/index.html: $(doc_rst_files) $(doc_source_dir)/conf.py
ifneq ($(doc_build),true)
@echo "makefile: Warning: Skipping docs build on Python $(python_m_n_version)"
else
Expand Down
26 changes: 25 additions & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,39 @@
# import sys
# sys.path.insert(0, os.path.abspath('.'))

import os
import re


def get_version(galaxy_file):
"""
Get the version from the collection manifest file (galaxy.yml).
In order to avoid the dependency to a yaml package, this is done by
parsing the file with a regular expression.
"""
with open(galaxy_file, 'r') as fp:
ftext = fp.read()
m = re.search(r"^version: *([0-9.a-z]+) *$", ftext, re.MULTILINE)
if not m:
raise ValueError("No version found in collection manifest file: {0}".
format(galaxy_file))
version = m.group(1)
return version


# -- Project information -----------------------------------------------------

project = 'ibm.zhmc Ansible modules'
copyright = '2016-2020, IBM'
author = 'IBM'

_version_file = '../../galaxy.yml' # relative to the dir of this file
_version_file = os.path.relpath(os.path.join(
os.path.dirname(__file__), _version_file))

# The full version, including alpha/beta/rc tags
release = '1.0.0'
release = get_version(_version_file)


# -- General configuration ---------------------------------------------------
Expand Down

0 comments on commit 0e891cd

Please sign in to comment.