* Added workaround so at least interactive python detection works

(although not perfectly) in python <= 2.5.
This commit is contained in:
Wirawan Purwanto
2012-02-16 13:32:55 -05:00
parent f8a101fbe9
commit 1674bfd256

View File

@@ -64,15 +64,23 @@ def detect_interactive(global_ns=None):
* For ipython, see if "__IPYTHON__" is defined in the user's global * For ipython, see if "__IPYTHON__" is defined in the user's global
namespace. namespace.
* For "python -i" invocation, sys.flags.interactive will be set to True. * For "python -i" invocation, sys.flags.interactive will be set to True.
(python 2.6+ only)
* For vanilla "python" invocation with no argument, then sys.ps1 * For vanilla "python" invocation with no argument, then sys.ps1
variable exists. variable exists.
""" """
def is_python_i():
# This approach only works for Python 2.6+
try:
return sys.flags.interactive
except:
return False
(g, b) = get_global_namespace_(global_ns) (g, b) = get_global_namespace_(global_ns)
if "__IPYTHON__" in g or hasattr(b, "__IPYTHON__"): if "__IPYTHON__" in g or hasattr(b, "__IPYTHON__"):
return { return {
'session': 'ipython', 'session': 'ipython',
} }
elif sys.flags.interactive: elif is_python_i(): # sys.flags.interactive:
return { return {
'session': 'python -i', 'session': 'python -i',
} }