From f0f3f6c06a0640bc5ded5359b6f5424404e1421d Mon Sep 17 00:00:00 2001 From: Rowan Cockett Date: Sat, 2 Jan 2016 18:06:49 -0800 Subject: [PATCH] Update the examples init.py to explicitly reference things. You can run the main function to update the docs and imports. --- SimPEG/Examples/__init__.py | 62 ++++++++++++++++++++++++++++--------- docs/api_Tests.rst | 2 +- 2 files changed, 48 insertions(+), 16 deletions(-) diff --git a/SimPEG/Examples/__init__.py b/SimPEG/Examples/__init__.py index ac219a7f..191664bb 100644 --- a/SimPEG/Examples/__init__.py +++ b/SimPEG/Examples/__init__.py @@ -1,24 +1,60 @@ -# This will import everything in the directory into this file -from os import path as p -from glob import glob -__all__ = [] -for x in glob(p.join(p.dirname(__file__), '*.py')): - if not p.basename(x).startswith('__'): - __import__(p.basename(x)[:-3], globals(), locals()) - __all__ += [p.basename(x)[:-3]] -del glob, p, x +# Run this file to add imports. + +##### AUTOIMPORTS ##### +import EM_FDEM_1D_Inversion +import FLOW_Richards_1D_Celia1990 +import Forward_BasicDirectCurrent +import Inversion_Linear +import Mesh_Basic_PlotImage +import Mesh_Basic_Types +import Mesh_Operators_CahnHilliard +import Mesh_QuadTree_Creation +import Mesh_QuadTree_FaceDiv +import Mesh_QuadTree_HangingNodes +import Mesh_Tensor_Creation +##### AUTOIMPORTS ##### if __name__ == '__main__': """ - Run the following to create the examples documentation. + Run the following to create the examples documentation and add to the imports at the top. """ import shutil, os from SimPEG import Examples + # Create the examples dir in the docs folder. + docExamplesDir = os.path.sep.join(os.path.realpath(__file__).split(os.path.sep)[:-3] + ['docs', 'examples']) + shutil.rmtree(docExamplesDir) + os.makedirs(docExamplesDir) + + # Get all the python examples in this folder + thispath = os.path.sep.join(__file__.split(os.path.sep)[:-1]) + onlyfiles = [f[:-3] for f in os.listdir(thispath) if os.path.isfile(os.path.join(thispath, f)) and f.endswith('.py') and not f.startswith('_')] + + # Add the imports to the top in the AUTOIMPORTS section + f = file(__file__, 'r') + inimports = False + out = '' + for line in f: + if not inimports: + out += line + + if line == "##### AUTOIMPORTS #####\n": + inimports = not inimports + if inimports: + out += '\n'.join(["import %s"%_ for _ in onlyfiles]) + out += '\n##### AUTOIMPORTS #####\n' + f.close() + + f = file(__file__, 'w') + f.write(out) + f.close() + + def _makeExample(filePath, runFunction): + """Makes the example given a path of the file and the run function.""" filePath = os.path.realpath(filePath) name = filePath.split(os.path.sep)[-1].rstrip('.pyc').rstrip('.py') @@ -52,15 +88,11 @@ if __name__ == '__main__': rst = os.path.sep.join((filePath.split(os.path.sep)[:-3] + ['docs', 'examples', name + '.rst'])) + print 'Creating: %s.rst'%name f = open(rst, 'w') f.write(out) f.close() - - docExamplesDir = os.path.sep.join(os.path.realpath(__file__).split(os.path.sep)[:-3] + ['docs', 'examples']) - shutil.rmtree(docExamplesDir) - os.makedirs(docExamplesDir) - for ex in dir(Examples): if ex.startswith('_'): continue E = getattr(Examples,ex) diff --git a/docs/api_Tests.rst b/docs/api_Tests.rst index 614d8747..b0b2fbd0 100644 --- a/docs/api_Tests.rst +++ b/docs/api_Tests.rst @@ -3,6 +3,6 @@ Testing SimPEG ============== -.. automodule:: SimPEG.Tests.TestUtils +.. automodule:: SimPEG.Tests :members: :undoc-members: