Skip to content

Commit fd9bec9

Browse files
committed
Use version for git in documentation
1 parent e2e5e93 commit fd9bec9

1 file changed

Lines changed: 21 additions & 4 deletions

File tree

docs/conf.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,31 @@
4343
project = u'python-bioformats'
4444
copyright = u'2014, Broad Institute of MIT and Harvard'
4545

46+
def get_version():
47+
version_file = os.path.join(os.path.dirname(__file__), '..', 'bioformats',
48+
'_version.py')
49+
if os.path.exists(version_file):
50+
with open(version_file) as f:
51+
cached_version_line = f.read().strip()
52+
try:
53+
import re
54+
# From http://stackoverflow.com/a/3619714/17498
55+
cached_version = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]",
56+
cached_version_line, re.M).group(1)
57+
except:
58+
raise RuntimeError("Unable to find version in %s" % version_file)
59+
split_version = cached_version.split('.')
60+
return '.'.join(split_version[:2]), cached_version
61+
else:
62+
return '0.0', '0.0.0'
63+
4664
# The version info for the project you're documenting, acts as replacement for
4765
# |version| and |release|, also used in various other places throughout the
4866
# built documents.
4967
#
50-
# The short X.Y version.
51-
version = '1.0'
52-
# The full version, including alpha/beta/rc tags.
53-
release = '1.0.0pr3'
68+
# version: The short X.Y version.
69+
# release: The full version, including alpha/beta/rc tags.
70+
version, release = get_version()
5471

5572
# The language for content autogenerated by Sphinx. Refer to documentation
5673
# for a list of supported languages.

0 commit comments

Comments
 (0)