Open sjrl opened 2 years ago
@wuhu What do you think?
I think the warning is a good solution.
We are considering solution where this code is added to padl/__init__.py
:
try:
import inspect
from padl.dumptools.sourceget import get_source
_ = get_source(inspect.stack()[-1].filename)
# We do not want these to be padl level imports so we remove them
del inspect
del get_source
except Exception as e:
raise RuntimeError('PADL does not work in the current Interpreter Environment because we '
'rely on the inspect module to find source code. '
'Unfortunately, the source code typed at this interactive '
'prompt is discarded as soon as it is parsed. Therefore, we recommend '
'using the IPython interpreter or Jupyter Notebooks for interactive '
'sessions.') from e
However, the inspect.stack()[-1].filename
does not guarantee grabbing the frame that corresponds to the user input from the interactive environment. In fact depending on the environment (e.g. Python Interpreter, IPython, PyCharm, etc.) additional frames can be mixed in.
🛰️ Feature
Description
Make PADL to work in environments that do not save executed source code (e.g. in the base Python Interpreter Environment). Currently PADL will throw a
TypeError
if the source code of the transform is not findable by theinspect
module.gives
Solution
It would be nice if transforms could still be made and executed, but warn the user that saving will not work in this environment. We could do this by avoiding inspection when the source code is not available (e.g. returns as
None
) and print a warning to the user that saving will not work. Most likely a rare use-case, but it could be worth supporting.Alternatives
If we do not want to support this we could check if the source code is returned as
None
and suggest using a different interpreter like IPython.