Set calling program to UNKNOWN, when argv not in sys#3460
Set calling program to UNKNOWN, when argv not in sys#3460takluyver merged 1 commit intoipython:masterfrom
Conversation
|
Yuk, really? Under what conditions does this happen? The docs mention various special cases for |
|
It happend with https://github.com/psi4/psi4.0b4: $ psi ipython-embed.py
Traceback (most recent call last):
File "<string>", line 26, in <module>
File "/home/tomspur/IPython.git/IPython/__init__.py", line 43, in <module>
from .config.loader import Config
File "/home/tomspur/IPython.git/IPython/config/__init__.py", line 16, in <module>
from .application import *
File "/home/tomspur/IPython.git/IPython/config/application.py", line 67, in <module>
""".strip().format(app=os.path.basename(sys.argv[0]))
AttributeError: 'module' object has no attribute 'argv'I never used boost-python so far, so I don't know why this can happen, but at least it does... |
|
So it's embedding a Python interpreter, not just an IPython shell? I'm inclined to take the view that it's the embedding program's responsibility to provide a sane Python environment, not for us to work around any bizarre situation it can throw at us. |
|
Yes, it's embedding a Python interpreter and I want to start ipython inside of it, so I have easier access to the internal structure of psi. I think this is a fairly easy workaround, which could happen in other programs too. Nevertheless, it's your choice to include it or not, if the change is too nasty ;) |
|
If this is something that programs embedding a Python interpreter often do, then I'd say we should accept it. If it's something peculiar to psi, then I'd rather leave it, because there are hundreds of ways you could mess up Python features that we rely on, and it's not our job to try to handle them. |
|
@tomspur, thanks! This looks good, modulo that we'd much prefer to use |
It might happen, then the sys module has no argv, when embeding IPython into other programs with IPython.embed(). In that case, just set the calling program to "" or other logic in IPython will crash - for instance when checking for command line arguments.
|
@fperez, great, thanks. I've amended it to the empty string now instead. |
|
LGTM, but I think the comment should explain why this is needed, not what it's doing. |
|
Ready to merge, as soon as @tomspur updates the comment per @takluyver. |
|
Finished off in #3632. |
It might happen, then the sys module has no argv, when embeding IPython
into other programs with IPython.embed(). In that case, just set the
calling program to UNKNOWN or other logic in IPython will crash - for
instance when checking for command line arguments.