Skip to content

Commit b09adbc

Browse files
authored
Merge pull request #3557 from minijackson/sphinx-version
docs: set version and release from the pom.xml
2 parents 3621cae + 90bb30c commit b09adbc

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

docs/source/conf.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
# All configuration values have a default; values that are commented out
1212
# serve to show the default.
1313

14-
import sys, os
14+
import xml.etree.ElementTree as ET
15+
16+
from sphinx.util import logging
17+
logger = logging.getLogger(__name__)
1518

1619
# If extensions (or modules to document with autodoc) are in another directory,
1720
# add these directories to sys.path here. If the directory is relative to the
@@ -40,17 +43,27 @@
4043
master_doc = 'index'
4144

4245
# General information about the project.
43-
project = u'Phoebus'
44-
copyright = u'2017, Phoebus Developers'
46+
project = 'Phoebus'
47+
copyright = '2017-%Y, Phoebus Developers'
48+
49+
def find_phoebus_version() -> str:
50+
try:
51+
pom = ET.parse("../../pom.xml")
52+
version_el = pom.find("./{http://maven.apache.org/POM/4.0.0}version")
53+
54+
if version_el is not None and version_el.text is not None:
55+
return version_el.text
56+
else:
57+
raise RuntimeError("Couldn't find a valid <version> in pom.xml")
58+
except Exception:
59+
logger.exception("Couldn't find Phoebus version, using a default value")
60+
return "1.0"
4561

4662
# The version info for the project you're documenting, acts as replacement for
4763
# |version| and |release|, also used in various other places throughout the
4864
# built documents.
49-
#
50-
# The short X.Y version.
51-
version = '1.0'
52-
# The full version, including alpha/beta/rc tags.
53-
release = '1.0'
65+
version = find_phoebus_version()
66+
release = version
5467

5568
# The language for content autogenerated by Sphinx. Refer to documentation
5669
# for a list of supported languages.
@@ -248,6 +261,7 @@
248261
# Create applications.rst, services.rst
249262
# by listing links to all app/**/index.rst
250263

264+
import os
251265
from os import walk, path
252266
import subprocess, shutil
253267
import sys, traceback

0 commit comments

Comments
 (0)