diff --git a/IPython/testing/tools.py b/IPython/testing/tools.py index c54db89..348eb8d 100644 --- a/IPython/testing/tools.py +++ b/IPython/testing/tools.py @@ -156,6 +156,28 @@ def default_config(): return config +def get_ipython_cmd(as_string=False): + """ + Return appropriate IPython command line name. By default, this will return + a list that can be used with subprocess.Popen, for example, but passing + `as_string=True` allows for returning the IPython command as a string. + + Parameters + ---------- + as_string: bool + Flag to allow to return the command as a string. + """ + # FIXME: remove workaround for 2.6 support + if sys.version_info[:2] > (2,6): + ipython_cmd = [sys.executable, "-m", "IPython"] + else: + ipython_cmd = ["ipython"] + + if as_string: + ipython_cmd = " ".join(ipython_cmd) + + return ipython_cmd + def ipexec(fname, options=None): """Utility to call 'ipython filename'. @@ -188,12 +210,8 @@ def ipexec(fname, options=None): _ip = get_ipython() test_dir = os.path.dirname(__file__) - - # FIXME: remove workaround for 2.6 support - if sys.version_info[:2] > (2,6): - ipython_cmd = [sys.executable, "-m", "IPython"] - else: - ipython_cmd = ["ipython"] + + ipython_cmd = get_ipython_cmd() # Absolute path for filename full_fname = os.path.join(test_dir, fname) full_cmd = ipython_cmd + cmdargs + [full_fname]