mirror of
https://github.com/wassname/simpeg.git
synced 2026-07-14 11:18:18 +08:00
Update the examples init.py to explicitly reference things.
You can run the main function to update the docs and imports.
This commit is contained in:
+47
-15
@@ -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)
|
||||
|
||||
+1
-1
@@ -3,6 +3,6 @@
|
||||
Testing SimPEG
|
||||
==============
|
||||
|
||||
.. automodule:: SimPEG.Tests.TestUtils
|
||||
.. automodule:: SimPEG.Tests
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
||||
Reference in New Issue
Block a user