Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@

from __future__ import print_function

import ast
import os
import sys

from pkg_resources import get_distribution

_html_theme = "sphinx_rtd_theme"
_html_theme_path = []
try:
Expand All @@ -37,6 +37,23 @@
print("Template {0} not found, pip install it", file=sys.stderr)
_html_theme = "default"


def _read_version():
"""Read the generated package version without packaging helpers."""
version_path = os.path.join(
os.path.dirname(__file__), '..', 'dictdiffer', 'version.py'
)
with open(version_path, encoding='utf-8') as version_file:
module = ast.parse(version_file.read(), filename=version_path)

for node in module.body:
if isinstance(node, ast.Assign):
for target in node.targets:
if isinstance(target, ast.Name) and target.id == '__version__':
return ast.literal_eval(node.value)

raise RuntimeError('Unable to read dictdiffer version')

# 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.
Expand Down Expand Up @@ -81,7 +98,7 @@
# built documents.
#
# The short X.Y version.
version = get_distribution('dictdiffer').version
version = _read_version()

# The full version, including alpha/beta/rc tags.
release = version
Expand Down