From 36b4d9776976410a47faceff179cbfb9548266f5 Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Sun, 25 Oct 2009 06:23:08 +0200 Subject: [PATCH] Generate new API only when the current version of the library is installed, otherwise revert to pre-generated files. [Patch by Helge Reikeras] --- CONTRIBUTORS.txt | 5 +++- doc/tools/build_modref_templates.py | 39 ++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index 45836e7f..d09931e3 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -17,5 +17,8 @@ OpenCV functions and better OSX library loader - Ralf Gommers - Image IO, color spaces and plots in documentation + Image IO, color spaces, plots in documentation, cleaner API docs + +- Helge Reikeras + Logic around API docs generation diff --git a/doc/tools/build_modref_templates.py b/doc/tools/build_modref_templates.py index ffd0d933..cf24da63 100644 --- a/doc/tools/build_modref_templates.py +++ b/doc/tools/build_modref_templates.py @@ -2,14 +2,51 @@ """Script to auto-generate our API docs. """ # stdlib imports -import os +import os, sys # local imports from apigen import ApiDocWriter +# version comparison +from distutils.version import LooseVersion as V + #***************************************************************************** + +def abort(error): + print '*WARNING* API documentation not generated: %s'%error + exit() + if __name__ == '__main__': package = 'scikits.image' + + # Check that the 'image' package is available. If not, the API + # documentation is not (re)generated and existing API documentation + # sources will be used. + + try: + __import__(package) + except ImportError, e: + abort("Can not import scikits.image") + + module = sys.modules[package] + + # Check that the source version is equal to the installed + # version. If the versions mismatch the API documentation sources + # are not (re)generated. This avoids automatic generation of documentation + # for older or newer versions if such versions are installed on the system. + + installed_version = V(module.version.version) + + setup_lines = open('../setup.py').readlines() + version = 'vUndefined' + for l in setup_lines: + if l.startswith('VERSION'): + source_version = V(l.split("'")[1]) + break + + if source_version != installed_version: + abort("Installed version does not match source version") + outdir = 'source/api' docwriter = ApiDocWriter(package) docwriter.package_skip_patterns += [r'\.fixes$',