Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 33 additions & 31 deletions tofu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,37 +69,39 @@
import tofu.data as data


try:
import tofu.imas2tofu as imas2tofu
okimas2tofu = True
except Exception as err:
warnings.warn(str(err))
okimas2tofu = False

try:
import tofu.mag as mag
okmag = True
except Exception as err:
warnings.warn(str(err))
okmag = False

#import tofu.dust as dust

# -------------------------------------
# Try importing optional subpackages
# -------------------------------------

msg = None
dsub = dict.fromkeys(['imas2tofu', 'mag'])
for sub in dsub.keys():
try:
exec('import tofu.{0} as {0}'.format(sub))
dsub[sub] = True
except Exception as err:
dsub[sub] = str(err)

# -------------------------------------
# If any error, populate warning and store error message
# -------------------------------------

lsubout = [sub for sub in dsub.keys() if dsub[sub] is not True]
if len(lsubout) > 0:
lsubout = ['tofu.{0}'.format(ss) for ss in lsubout]
msg = "\nThe following subpackages are not available:"
msg += "\n - " + "\n - ".join(lsubout)
msg += "\n => see tofu.dsub[<subpackage>] for details on error messages"
warnings.warn(msg)

# -------------------------------------
# Add optional subpackages to __all__
# -------------------------------------

__all__ = ['pathfile','utils','_plot','geom','data']
if okimas2tofu:
__all__.append('imas2tofu')
if okmag:
__all__.append('mag')


del sys, warnings, okimas2tofu, okmag

#__all__.extend(['geom', 'mesh', 'matcomp', 'data', 'inv'])
for sub in dsub.keys():
if dsub[sub] is True:
__all__.append(sub)

#__name__ = ""
#__date__ = "$Mar 05, 2014$"
#__copyright__ = ""
#__license__ = ""
#__url__ = ""
#__path__ =
# clean-up the mess
del sys, warnings, lsubout, sub, msg
5 changes: 2 additions & 3 deletions tofu/imas2tofu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@
msg += "\n\nIMAS python API issue\n"
msg += "imas could not be imported into tofu ('import imas' failed):\n"
msg += " - it may not be installed (optional dependency)\n"
msg += " - or you not have loaded the good working environment\n\n"
msg += " - or you have loaded the wrong working environment\n\n"
msg += " => the optional sub-package tofu.imas2tofu is not usable\n"
else:
msg = str(traceback.format_exc())
msg += "\n\n => the optional sub-package tofu.imas2tofu is not usable\n"
warnings.warn(msg)
del msg, err
raise Exception(msg)

__all__ = ['MultiIDSLoader', 'load_Config', 'load_Plasma2D',
'load_Cam', 'load_Data']
27 changes: 20 additions & 7 deletions tofu/mag/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@
import warnings
import traceback

msg, err = None, None
try:
import imas
try:
from tofu.mag.magFieldLines import *
except Exception:
from .magFieldLines import *
del warnings, traceback, magFieldLines, mag_ripple
except Exception as err:
if str(err) == 'imas not available':
msg = ""
Expand All @@ -25,7 +21,24 @@
else:
msg = str(traceback.format_exc())
msg += "\n\n => the optional sub-package tofu.mag is not usable\n"
warnings.warn(msg)
del msg, err
raise Exception(msg)

try:
import pywed
except Exception:
msg = "pywed not available => no tofu.mag"
raise Exception(msg)

try:
from tofu.mag.magFieldLines import *
except Exception:
try:
from .magFieldLines import *
except Exception:
msg = "Could not import"
raise Exception(msg)

del warnings, traceback, magFieldLines, mag_ripple, pywed, imas
del msg, err

__all__ = ['MagFieldLines']