Skip to content
Snippets Groups Projects
Commit 443a9ae4 authored by Franck Pérignon's avatar Franck Pérignon
Browse files

Fix bug in set default path due to diff between python and ipython behavior

parent 04ba2dd3
No related branches found
No related tags found
No related merge requests found
......@@ -5,8 +5,10 @@ Tools related to i/o in parmes.
import os
import scitools.filetable as ft
import parmepy.tools.numpywrappers as npw
import inspect
from inspect import getouterframes, currentframe
import parmepy.mpi as mpi
from parmepy.tools.sys_utils import SysUtils as su
from re import findall, IGNORECASE
class io(object):
......@@ -27,7 +29,33 @@ class io(object):
# Memo for getouterframe usage:
# frame, filename, line_number, function_name, lines, index =\
# inspect.getouterframes(inspect.currentframe())[-1]
a = inspect.getouterframes(inspect.currentframe())[-1]
# Warning FP : the behavior of python and ipython is different for
# this command.
a = getouterframes(currentframe())
ind = -1
# --- ipython ---
if su.in_ipython():
sublist = [i[1] for i in a]
for val in sublist:
ll = findall('ipython', val, IGNORECASE)
if len(ll) > 0:
ind = sublist.index(val) - 1
break
if ind > -1:
# -- interactive ipython but call with execfile--
if len(findall('io_utils', a[ind][1])) > 0:
return './interactive/p' + str(mpi.main_size)
a = a[ind]
else:
# -- interactive ipython without execfile call --
return './interactive/p' + str(mpi.main_size)
else:
# -- python --
a = a[-1]
if a[-1] is None:
# interactive python
return './interactive/p' + str(mpi.main_size)
return os.path.join(a[1].split('.')[0], 'p' + str(mpi.main_size))
@staticmethod
......
"""
@file sys_utils.py
Tools related to global config.
"""
class SysUtils(object):
"""
Global system check and other utilities
"""
@staticmethod
def in_ipython():
try:
__IPYTHON__
except NameError:
return False
else:
return True
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment