clint
clint copied to clipboard
Fix sys.argv import when running inside LLDB Python interpreter.
I'm using clint.colored inside LLDB scripts, and this fix is required for that to work.
What do you think about finding a way to detect LLDB running and only do this in that scenario? I'm slightly worried that this could mask problems with argv
imports in other scenarios (although I can't think why this would ever happen, so maybe this isn't an issue)
I've checked os.environ
, and there's nothing special to check. sys.platform
is darwin
. sys.argv
is available without import for me:
> xcrun lldb
(lldb) script
Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.
>>> import sys
>>> sys.argv
[]
Can't think of anything else to check. Any ideas?
It actually appears that lldb loads python with an lldb
module which isn't usually around, so I think the following might be a good solution
try:
from sys import argv
# Can happen when executing inside LLDB context
except ImportError:
if lldb:
import sys
sys.argv = []
else:
raise ImportError
lldb
module seems to be automatically present only when running inside embedded interpreter, not when inserting externals scripts:
mblsha@siruba ~> cat 1.py
print lldb
mblsha@siruba ~> xcrun lldb
(lldb) command script import 1.py
error: module importing failed: Python error raised while importing module: reload() argument must be module - traceback: File "temp.py", line 1, in <module>
(lldb) script
Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.
>>> print lldb
<module 'lldb' from '/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Versions/A/Resources/Python/lldb/__init__.py'>
>>> ^D