* Added workaround so at least interactive python detection works

(although not perfectly) in python <= 2.5.
master
Wirawan Purwanto 12 years ago
parent f8a101fbe9
commit 1674bfd256
  1. 10
      interactive_tools.py

@ -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',
} }

Loading…
Cancel
Save