|
18 | 18 | from distutils.cmd import Command
|
19 | 19 | from distutils.command.clean import clean
|
20 | 20 |
|
21 |
| -# Sphinx import. |
22 |
| -from sphinx.setup_command import BuildDoc |
23 |
| - |
24 | 21 | _info_fname = pjoin(os.path.dirname(__file__), 'nipype', 'info.py')
|
25 | 22 | INFO_VARS = {}
|
26 | 23 | exec(open(_info_fname, 'rt').read(), {}, INFO_VARS)
|
@@ -104,61 +101,66 @@ def relative_path(filename):
|
104 | 101 |
|
105 | 102 | ################################################################################
|
106 | 103 | # Distutils Command class build the docs
|
107 |
| -class MyBuildDoc(BuildDoc): |
108 |
| - """ Sub-class the standard sphinx documentation building system, to |
109 |
| - add logics for API generation and matplotlib's plot directive. |
110 |
| - """ |
111 |
| - |
112 |
| - def run(self): |
113 |
| - self.run_command('api_docs') |
114 |
| - # We need to be in the doc directory for to plot_directive |
115 |
| - # and API generation to work |
116 |
| - """ |
117 |
| - os.chdir('doc') |
118 |
| - try: |
119 |
| - BuildDoc.run(self) |
120 |
| - finally: |
121 |
| - os.chdir('..') |
122 |
| - """ |
123 |
| - # It put's the build in a doc/doc/_build directory with the |
124 |
| - # above?!?! I'm leaving the code above here but commented out |
125 |
| - # in case I'm missing something? |
126 |
| - BuildDoc.run(self) |
127 |
| - self.zip_docs() |
128 |
| - |
129 |
| - def zip_docs(self): |
130 |
| - if not os.path.exists(DOC_BUILD_DIR): |
131 |
| - raise OSError, 'Doc directory does not exist.' |
132 |
| - target_file = os.path.join('doc', 'documentation.zip') |
133 |
| - # ZIP_DEFLATED actually compresses the archive. However, there |
134 |
| - # will be a RuntimeError if zlib is not installed, so we check |
135 |
| - # for it. ZIP_STORED produces an uncompressed zip, but does not |
136 |
| - # require zlib. |
137 |
| - try: |
138 |
| - zf = zipfile.ZipFile(target_file, 'w', |
139 |
| - compression=zipfile.ZIP_DEFLATED) |
140 |
| - except RuntimeError: |
141 |
| - warnings.warn('zlib not installed, storing the docs ' |
142 |
| - 'without compression') |
143 |
| - zf = zipfile.ZipFile(target_file, 'w', |
144 |
| - compression=zipfile.ZIP_STORED) |
145 |
| - |
146 |
| - for root, dirs, files in os.walk(DOC_BUILD_DIR): |
147 |
| - relative = relative_path(root) |
148 |
| - if not relative.startswith('.doctrees'): |
149 |
| - for f in files: |
150 |
| - zf.write(os.path.join(root, f), |
151 |
| - os.path.join(relative, 'html_docs', f)) |
152 |
| - zf.close() |
153 |
| - |
154 |
| - |
155 |
| - def finalize_options(self): |
156 |
| - """ Override the default for the documentation build |
157 |
| - directory. |
| 104 | +# Sphinx import. |
| 105 | +try: |
| 106 | + from sphinx.setup_command import BuildDoc |
| 107 | +except: |
| 108 | + MyBuildDoc = None |
| 109 | +else: |
| 110 | + class MyBuildDoc(BuildDoc): |
| 111 | + """ Sub-class the standard sphinx documentation building system, to |
| 112 | + add logics for API generation and matplotlib's plot directive. |
158 | 113 | """
|
159 |
| - self.build_dir = os.path.join(*DOC_BUILD_DIR.split(os.sep)[:-1]) |
160 |
| - BuildDoc.finalize_options(self) |
161 | 114 |
|
| 115 | + def run(self): |
| 116 | + self.run_command('api_docs') |
| 117 | + # We need to be in the doc directory for to plot_directive |
| 118 | + # and API generation to work |
| 119 | + """ |
| 120 | + os.chdir('doc') |
| 121 | + try: |
| 122 | + BuildDoc.run(self) |
| 123 | + finally: |
| 124 | + os.chdir('..') |
| 125 | + """ |
| 126 | + # It put's the build in a doc/doc/_build directory with the |
| 127 | + # above?!?! I'm leaving the code above here but commented out |
| 128 | + # in case I'm missing something? |
| 129 | + BuildDoc.run(self) |
| 130 | + self.zip_docs() |
| 131 | + |
| 132 | + def zip_docs(self): |
| 133 | + if not os.path.exists(DOC_BUILD_DIR): |
| 134 | + raise OSError, 'Doc directory does not exist.' |
| 135 | + target_file = os.path.join('doc', 'documentation.zip') |
| 136 | + # ZIP_DEFLATED actually compresses the archive. However, there |
| 137 | + # will be a RuntimeError if zlib is not installed, so we check |
| 138 | + # for it. ZIP_STORED produces an uncompressed zip, but does not |
| 139 | + # require zlib. |
| 140 | + try: |
| 141 | + zf = zipfile.ZipFile(target_file, 'w', |
| 142 | + compression=zipfile.ZIP_DEFLATED) |
| 143 | + except RuntimeError: |
| 144 | + warnings.warn('zlib not installed, storing the docs ' |
| 145 | + 'without compression') |
| 146 | + zf = zipfile.ZipFile(target_file, 'w', |
| 147 | + compression=zipfile.ZIP_STORED) |
| 148 | + |
| 149 | + for root, dirs, files in os.walk(DOC_BUILD_DIR): |
| 150 | + relative = relative_path(root) |
| 151 | + if not relative.startswith('.doctrees'): |
| 152 | + for f in files: |
| 153 | + zf.write(os.path.join(root, f), |
| 154 | + os.path.join(relative, 'html_docs', f)) |
| 155 | + zf.close() |
| 156 | + |
| 157 | + |
| 158 | + def finalize_options(self): |
| 159 | + """ Override the default for the documentation build |
| 160 | + directory. |
| 161 | + """ |
| 162 | + self.build_dir = os.path.join(*DOC_BUILD_DIR.split(os.sep)[:-1]) |
| 163 | + BuildDoc.finalize_options(self) |
162 | 164 |
|
163 | 165 | ################################################################################
|
164 | 166 | # Distutils Command class to clean
|
|
0 commit comments