-
-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
investigate relative imports. #4
Comments
I played around with this. If you can get |
Right now, I tested this by having two files: wat/say.ipynb: def say(what):
print(what) wat/init.ipynb from .say import say
__all__ = [say] Now, from outside, I could do this: from wat import say
say('hello world') That calls the correct function, and works! So this works from the outside. However, if I try to execute wat/init.ipynb in the notebook interface, I get the following error on import:
if I run: __package__ = 'ipynb.fs.wat' before importing, it gets to:
Which is better. if I do a: import ipynb.fs.wat in init.ipynb it succeeds (weird!) and then if I try to relative import again I get:
Curious and needs more investigation :D |
So I did a bunch of work here, and it kinda works. In test.ipynb:
In client.ipynb:
This works. The first two lines in the client are the boilerplate. We might be able to automate that with some ipynb extension setup maybe? Note that this totally works when you're calling it from python directly or with |
Funkier than expected. Right now, if notebook A imports notebook B as: from ipynb.fs.full.notebookB import foo and then notebook B imports notebook C as import ipynb.fs
from .defs.notebookC import bar The transient import will fail, since the package for notebookB will already be The underlying core problem is:
It looks like we might need to do AST munging to make this happen. We just munge AST to resolve the relative imports ourselves. |
I'm guessing we'll have user that want to
import ..anipynbmodule
not sure how to do that explicitly.The text was updated successfully, but these errors were encountered: