From 443a9ae45fb99e77f1c3bbcbc48c32c892543aaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franck=20P=C3=A9rignon?= <franck.perignon@imag.fr> Date: Wed, 5 Mar 2014 14:21:52 +0000 Subject: [PATCH] Fix bug in set default path due to diff between python and ipython behavior --- HySoP/hysop/tools/io_utils.py | 32 ++++++++++++++++++++++++++++++-- HySoP/hysop/tools/sys_utils.py | 18 ++++++++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 HySoP/hysop/tools/sys_utils.py diff --git a/HySoP/hysop/tools/io_utils.py b/HySoP/hysop/tools/io_utils.py index 1cced5183..58fabff58 100644 --- a/HySoP/hysop/tools/io_utils.py +++ b/HySoP/hysop/tools/io_utils.py @@ -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 diff --git a/HySoP/hysop/tools/sys_utils.py b/HySoP/hysop/tools/sys_utils.py new file mode 100644 index 000000000..78d997fb9 --- /dev/null +++ b/HySoP/hysop/tools/sys_utils.py @@ -0,0 +1,18 @@ +""" +@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 -- GitLab