diff --git a/oasis/NSCoupled.py b/oasis/NSCoupled.py index 468de910..f7e7fae5 100755 --- a/oasis/NSCoupled.py +++ b/oasis/NSCoupled.py @@ -25,16 +25,20 @@ commandline_kwargs = parse_command_line() +# Find the problem module default_problem = 'DrivenCavity' -#exec('from problems.NSCoupled.{} import *'.format(commandline_kwargs.get('problem', default_problem))) problemname = commandline_kwargs.get('problem', default_problem) -try: - problemmod = importlib.import_module('.'.join(('oasis.problems.NSCoupled', problemname))) -except ImportError: - problemmod = importlib.import_module(problemname) -except: +problemspec = importlib.util.find_spec('.'.join(('oasis.problems.NSCoupled', problemname))) +if problemspec is None: + problemspec = importlib.util.find_spec(problemname) +if problemspec is None: raise RuntimeError(problemname+' not found') +# Import the problem module +print('Importing problem module '+problemname+':\n'+problemspec.origin) +problemmod = importlib.util.module_from_spec(problemspec) +problemspec.loader.exec_module(problemmod) + vars().update(**vars(problemmod)) # Update problem spesific parameters diff --git a/oasis/NSfracStep.py b/oasis/NSfracStep.py index a8eb0349..800bbcf8 100755 --- a/oasis/NSfracStep.py +++ b/oasis/NSfracStep.py @@ -37,15 +37,20 @@ commandline_kwargs = parse_command_line() +# Find the problem module default_problem = 'DrivenCavity' problemname = commandline_kwargs.get('problem', default_problem) -try: - problemmod = importlib.import_module('.'.join(('oasis.problems.NSfracStep', problemname))) -except ImportError: - problemmod = importlib.import_module(problemname) -except: +problemspec = importlib.util.find_spec('.'.join(('oasis.problems.NSfracStep', problemname))) +if problemspec is None: + problemspec = importlib.util.find_spec(problemname) +if problemspec is None: raise RuntimeError(problemname+' not found') +# Import the problem module +print('Importing problem module '+problemname+':\n'+problemspec.origin) +problemmod = importlib.util.module_from_spec(problemspec) +problemspec.loader.exec_module(problemmod) + vars().update(**vars(problemmod)) # Update problem spesific parameters