Skip to content

Commit

Permalink
Manually listed all classes and functions in __init__.py and added a …
Browse files Browse the repository at this point in the history
…script to generate the list (print_all.py)
  • Loading branch information
kinnala committed Apr 13, 2018
1 parent 8c1fc8d commit 79d3f60
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 32 deletions.
100 changes: 68 additions & 32 deletions skfem/__init__.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,69 @@
# partly from https://stackoverflow.com/questions/14426574/how-to-import-members-of-modules-within-a-package/14428820#14428820

def _import_all_modules():
"""dynamically imports all modules in the package"""
import traceback
import os
global __all__
__all__ = []
globals_, locals_ = globals(), locals()

# dynamically import all the package modules
for filename in os.listdir(__name__):
# process all python files in directory that don't start with underscore
# (which also keeps this module from importing itself)
if filename == 'assembly.py' \
or filename == 'mesh.py' \
or filename == 'utils.py' \
or filename == 'element.py' \
or filename == 'mapping.py':
modulename = filename.split('.')[0] # filename without extension
package_module = '.'.join([__name__, modulename])
try:
module = __import__(package_module, globals_, locals_, [modulename])
except:
traceback.print_exc()
raise
for name in module.__dict__:
if not name.startswith('_'):
globals_[name] = module.__dict__[name]
__all__.append(name)

_import_all_modules()
from skfem.mesh import *
from skfem.assembly import *
from skfem.mapping import *
from skfem.element import *
from skfem.utils import *
from skfem.mesh_importers import *

__all__ = ['InterfaceMesh1D',
'Mesh',
'Mesh2D',
'Mesh3D',
'MeshHex',
'MeshLine',
'MeshQuad',
'MeshTet',
'MeshTri',
'coo_matrix',
'Dofnum',
'FacetBasis',
'GlobalBasis',
'InteriorBasis',
'asm',
'coo_matrix',
'get_quadrature',
'MappingAffine',
'MappingIsoparametric',
'adaptive_theta',
'bilinear_form',
'build_ilu_pc',
'cg',
'condense',
'initialize',
'linear_form',
'nonlinear_form',
'rcm',
'rcm_reordering',
'smoothplot',
'solve',
'solver_direct_cholmod',
'solver_direct_scipy',
'Element',
'ElementArgyris',
'ElementH1',
'ElementH2',
'ElementHcurl',
'ElementHdiv',
'ElementHex1',
'ElementMorley',
'ElementQ1',
'ElementQ2',
'ElementTetN0',
'ElementTetP0',
'ElementTetP1',
'ElementTetP2',
'ElementTetRT0',
'ElementTriDG',
'ElementTriP0',
'ElementTriP1',
'ElementTriRT0',
'ElementVectorH1',
'MeshQuad',
'MeshTet',
'MeshTri',
'read_array',
'assert_',
'read_comsol',
'read_gmsh',
'read_token',
'skip_read_line']
17 changes: 17 additions & 0 deletions skfem/print_all.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import importlib
import types

class C: pass

for fname in ['mesh',
'assembly',
'mapping',
'utils',
'element',
'mesh_importers']:
mod = importlib.import_module(fname, 'skfem')
for x in dir(mod):
if isinstance(getattr(mod, x), types.FunctionType):
print(" '"+x+"',")
elif isinstance(getattr(mod, x), type(C)):
print(" '"+x+"',")

0 comments on commit 79d3f60

Please sign in to comment.