From 0fd57e8fca0e7cab2c6437b8b868a02e662a0172 Mon Sep 17 00:00:00 2001 From: Satrajit Ghosh Date: Mon, 13 Aug 2012 22:27:05 -0400 Subject: [PATCH] fix: remove sphinx dependency for install --- Makefile | 12 +----- build_docs.py | 113 ++++++++++++++++++++++++++------------------------ 2 files changed, 60 insertions(+), 65 deletions(-) diff --git a/Makefile b/Makefile index c9f7c9652e..3c4c0e95ad 100644 --- a/Makefile +++ b/Makefile @@ -5,13 +5,8 @@ PYTHON ?= python NOSETESTS ?= nosetests -zipdoc: - @echo "Clean documentation directory." - python setup.py clean - @echo "Build documentation.zip..." - python setup.py build_sphinx - @echo "Clean documentation directory." - python setup.py clean +zipdoc: html + zip documentation.zip doc/_build/html sdist: zipdoc @echo "Building source distribution..." @@ -75,6 +70,3 @@ check-before-commit: trailing-spaces html test @echo "removed spaces" @echo "built docs" @echo "ran test" - - - diff --git a/build_docs.py b/build_docs.py index 7cc71e0051..a35467b63c 100644 --- a/build_docs.py +++ b/build_docs.py @@ -18,9 +18,6 @@ from distutils.cmd import Command from distutils.command.clean import clean -# Sphinx import. -from sphinx.setup_command import BuildDoc - _info_fname = pjoin(os.path.dirname(__file__), 'nipype', 'info.py') INFO_VARS = {} exec(open(_info_fname, 'rt').read(), {}, INFO_VARS) @@ -104,61 +101,67 @@ def relative_path(filename): ################################################################################ # Distutils Command class build the docs -class MyBuildDoc(BuildDoc): - """ Sub-class the standard sphinx documentation building system, to - add logics for API generation and matplotlib's plot directive. - """ - - def run(self): - self.run_command('api_docs') - # We need to be in the doc directory for to plot_directive - # and API generation to work - """ - os.chdir('doc') - try: - BuildDoc.run(self) - finally: - os.chdir('..') - """ - # It put's the build in a doc/doc/_build directory with the - # above?!?! I'm leaving the code above here but commented out - # in case I'm missing something? - BuildDoc.run(self) - self.zip_docs() - - def zip_docs(self): - if not os.path.exists(DOC_BUILD_DIR): - raise OSError, 'Doc directory does not exist.' - target_file = os.path.join('doc', 'documentation.zip') - # ZIP_DEFLATED actually compresses the archive. However, there - # will be a RuntimeError if zlib is not installed, so we check - # for it. ZIP_STORED produces an uncompressed zip, but does not - # require zlib. - try: - zf = zipfile.ZipFile(target_file, 'w', - compression=zipfile.ZIP_DEFLATED) - except RuntimeError: - warnings.warn('zlib not installed, storing the docs ' - 'without compression') - zf = zipfile.ZipFile(target_file, 'w', - compression=zipfile.ZIP_STORED) - - for root, dirs, files in os.walk(DOC_BUILD_DIR): - relative = relative_path(root) - if not relative.startswith('.doctrees'): - for f in files: - zf.write(os.path.join(root, f), - os.path.join(relative, 'html_docs', f)) - zf.close() - +# Sphinx import. +try: + from sphinx.setup_command import BuildDoc +except: - def finalize_options(self): - """ Override the default for the documentation build - directory. + class MyBuildDoc(BuildDoc): + """ Sub-class the standard sphinx documentation building system, to + add logics for API generation and matplotlib's plot directive. """ - self.build_dir = os.path.join(*DOC_BUILD_DIR.split(os.sep)[:-1]) - BuildDoc.finalize_options(self) + def run(self): + self.run_command('api_docs') + # We need to be in the doc directory for to plot_directive + # and API generation to work + """ + os.chdir('doc') + try: + BuildDoc.run(self) + finally: + os.chdir('..') + """ + # It put's the build in a doc/doc/_build directory with the + # above?!?! I'm leaving the code above here but commented out + # in case I'm missing something? + BuildDoc.run(self) + self.zip_docs() + + def zip_docs(self): + if not os.path.exists(DOC_BUILD_DIR): + raise OSError, 'Doc directory does not exist.' + target_file = os.path.join('doc', 'documentation.zip') + # ZIP_DEFLATED actually compresses the archive. However, there + # will be a RuntimeError if zlib is not installed, so we check + # for it. ZIP_STORED produces an uncompressed zip, but does not + # require zlib. + try: + zf = zipfile.ZipFile(target_file, 'w', + compression=zipfile.ZIP_DEFLATED) + except RuntimeError: + warnings.warn('zlib not installed, storing the docs ' + 'without compression') + zf = zipfile.ZipFile(target_file, 'w', + compression=zipfile.ZIP_STORED) + + for root, dirs, files in os.walk(DOC_BUILD_DIR): + relative = relative_path(root) + if not relative.startswith('.doctrees'): + for f in files: + zf.write(os.path.join(root, f), + os.path.join(relative, 'html_docs', f)) + zf.close() + + + def finalize_options(self): + """ Override the default for the documentation build + directory. + """ + self.build_dir = os.path.join(*DOC_BUILD_DIR.split(os.sep)[:-1]) + BuildDoc.finalize_options(self) +else: + MyBuildDoc = None ################################################################################ # Distutils Command class to clean