From 9fa7edb74b82e7a3e101e17fecbfad508449550a Mon Sep 17 00:00:00 2001 From: Martin Zimmermann Date: Sun, 6 Jul 2014 18:52:20 +0200 Subject: [PATCH] add version fallback, closes #102 --- docs/conf.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 0437457..7e8c833 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -12,14 +12,27 @@ # All configuration values have a default; values that are commented out # serve to show the default. -import pkg_resources -dist = pkg_resources.get_distribution("isso") - import sys +import io +import re +import pkg_resources from os.path import join, dirname sys.path.insert(0, join(dirname(__file__), "_isso/")) +try: + dist = pkg_resources.get_distribution("isso") +except pkg_resources.DistributionNotFound: + dist = type("I'm a Version", (object, ), {}) + with io.open(join(dirname(__file__), "../setup.py")) as fp: + for line in fp: + m = re.match("\s*version='([^']+)'\s*", line) + if m: + dist.version = m.group(1) + break + else: + dist.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.