Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# Check for the OOMMFTCL environment variable pointing to oommf.tcl.
oommf_tcl = os.environ.get(envvar, None)
if oommf_tcl is not None:
cmd = ['tclsh', oommf_tcl, 'boxsi',
'+fg', '+version', '-exitondone', '1']
try:
res = sp.run(cmd, stdout=sp.PIPE, stderr=sp.PIPE)
except FileNotFoundError:
log.warning('oommf.tcl was not found.')
else:
if res.returncode:
log.warning('OOMMFTCL is set, but OOMMF could not be run.\n'
f'stdout:\n{res.stdout}\n'
f'stderr:\n{res.stderr}')
else:
_cached_oommf_runner = TclOOMMFRunner(oommf_tcl)
return _cached_oommf_runner
# OOMMF is installed via conda and oommf.tcl is in opt/oommf (Windows).
# This would probably also work on MacOS/Linux, but on these operating
# systems, when installed via conda, we use 'oommf' executable.
if sys.platform == 'win32' and \
os.path.isdir(os.path.join(sys.prefix, 'conda-meta')):
oommf_tcl = os.path.join(sys.prefix, 'opt', 'oommf', 'oommf.tcl')
if os.path.isfile(oommf_tcl):
_cached_oommf_runner = TclOOMMFRunner(oommf_tcl)
return _cached_oommf_runner
# OOMMF available as an executable - in a conda env on Mac/Linux, or oommf
# installed separately.
oommf_exe = shutil.which(oommf_exe)
if oommf_exe:
if res.returncode:
log.warning('OOMMFTCL is set, but OOMMF could not be run.\n'
f'stdout:\n{res.stdout}\n'
f'stderr:\n{res.stderr}')
else:
_cached_oommf_runner = TclOOMMFRunner(oommf_tcl)
return _cached_oommf_runner
# OOMMF is installed via conda and oommf.tcl is in opt/oommf (Windows).
# This would probably also work on MacOS/Linux, but on these operating
# systems, when installed via conda, we use 'oommf' executable.
if sys.platform == 'win32' and \
os.path.isdir(os.path.join(sys.prefix, 'conda-meta')):
oommf_tcl = os.path.join(sys.prefix, 'opt', 'oommf', 'oommf.tcl')
if os.path.isfile(oommf_tcl):
_cached_oommf_runner = TclOOMMFRunner(oommf_tcl)
return _cached_oommf_runner
# OOMMF available as an executable - in a conda env on Mac/Linux, or oommf
# installed separately.
oommf_exe = shutil.which(oommf_exe)
if oommf_exe:
_cached_oommf_runner = ExeOOMMFRunner(oommf_exe)
return _cached_oommf_runner
# Check for docker to run OOMMF in a docker image.
cmd = [docker_exe, 'images']
try:
res = sp.run(cmd, stdout=sp.PIPE, stderr=sp.PIPE)
except FileNotFoundError:
log.warning('Docker was not found.')
else: