Parse the version and release from the NEWS file. This looks a bit
hacky, but the NEWS file is generally well formatted and should be
reliable enough for our purposes.

Signed-off-by: Stephen Finucane <[email protected]>
Cc: Russell Bryant <[email protected]>
---
I took a look through the 'git history' of NEWS and could spot no other
formatting types for headers. Lemme know if I got this wrong though.
---
 Documentation/conf.py        | 20 +++++++++++---------
 Documentation/ovs_version.py | 38 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+), 9 deletions(-)
 create mode 100644 Documentation/ovs_version.py

diff --git a/Documentation/conf.py b/Documentation/conf.py
index 6a924b3..42ebdac 100644
--- a/Documentation/conf.py
+++ b/Documentation/conf.py
@@ -15,10 +15,13 @@
 # If extensions (or modules to document with autodoc) are in another directory,
 # add these directories to sys.path here. If the directory is relative to the
 # documentation root, use os.path.abspath to make it absolute, like shown here.
-#
-# import os
-# import sys
-# sys.path.insert(0, os.path.abspath('.'))
+
+import os
+import sys
+sys.path.insert(0, os.path.abspath('.'))
+
+import ovs_version
+
 try:
     import ovs_sphinx_theme
     use_ovs_theme = True
@@ -61,11 +64,10 @@ author = u'The Open vSwitch Development Community'
 # The version info for the project you're documenting, acts as replacement for
 # |version| and |release|, also used in various other places throughout the
 # built documents.
-#
-# The short X.Y version.
-version = u'2.6'
-# The full version, including alpha/beta/rc tags.
-release = u'2.6.0'
+
+# version is the short X.Y version, while release is the full version,
+# including alpha/beta/rc tags.
+version, release = ovs_version.get_release_info()
 
 # The language for content autogenerated by Sphinx. Refer to documentation
 # for a list of supported languages.
diff --git a/Documentation/ovs_version.py b/Documentation/ovs_version.py
new file mode 100644
index 0000000..3d250e9
--- /dev/null
+++ b/Documentation/ovs_version.py
@@ -0,0 +1,38 @@
+#!/usr/bin/env python
+
+import os
+import re
+
+ROOT_DIR = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
+NEWS_FILE = os.path.join(ROOT_DIR, 'NEWS')
+RELEASE_VERSION_RE = r'(?:Post-)?v(?P<release>(?P<version>\d+.\d+).\d+)'
+
+
+def get_release_info():
+    """Parse the latest release version from NEWS.
+
+    This relies on some assumptions about the format of the NEWS file - mainly
+    that the first line will always contain the latest version and an optional
+    date.
+
+    Returns:
+        A tuple of (version, release), where version corresponds to the short
+        MAJOR.MINOR version and release corresponds to the MAJOR.MINOR.PATCH
+        version.
+    """
+    with open(NEWS_FILE, 'r') as news:
+        version_header = news.readline()
+
+        try:
+            # we don't care about the date of the release
+            release, _ = version_header.split(' - ')
+        except ValueError:
+            release = version_header
+
+        release = re.search(RELEASE_VERSION_RE, release)
+
+        return release.group('version'), release.group('release')
+
+
+if __name__ == '__main__':
+    print(get_latest_release())
-- 
2.9.3

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to