-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
py/builtinimport: Look in every directory of PATH. #10814
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
base: master
Are you sure you want to change the base?
Conversation
We now scan all elements of "usys.path" for (sub)modules. Previously, this scan was only done for toplevel modules, which prevented selectively overriding a submodule. This was a problem in low-memory situations.
Code size report:
|
Thanks @smurfix -- I investigated a different approach to a similar problem in #8922 I'm curious how this comes up in the non-frozen case? i.e. how do you end up with two on-filesystem hierarchies. That said, I'm not sure I realised that MicroPython's behavior here is actually different to CPython, and if I understand correctly, the approach used in this PR actually improves CPython compatibility? (And would solve the frozen scenario I outlined in my PR). |
Sorry I didn't see you'd already mentioned this already in #10813. I agree with what you said there, but there needs to be some thought as to maintaining CPython compatibility. In particular consider this case (which I think is likely a common case for what you're trying to improve):
user does "import foo; foo.x" Now the user creates on the filesystem
(i.e. they've patched a.py for development, but left the rest of the Then
On CPython, this will ignore the "dev" directory entirely. On current MicroPython, and this PR, it will ignore We could make it a requirement that you must also override all (In summary, I think this PR works well as long as you're entirely working with namespace packages, but as soon as |
IMHO whether CPython does or does not ignore the "dev" directory, and/or whatever subhierarchy still is accessible because it assumes your packages are namespace-y, is mostly immaterial because on CPython you simply create a copy of the whole "foo" subtree when you need to edit it, point your PYTHONPATH to it, and you're set. We can't do that on MicroPython because doing so requires too much RAM.
Well, this patch essentially namespace-ifies all packages, and thus behaves exactly the same as CPython – except for the fact that it doesn't require I don't think there's much confusion with
Given that currently there aren't any namespace-y packages on MicroPython, you're correct by definition. however, the chance that somebody has a |
I can't lay claim to a solution, but here are a few thoughts.
|
Scan all elements of "usys.path" for (sub)modules.
Previously, this scan was only done for toplevel modules, which prevented selectively overriding a submodule. This was a problem in low-memory situations, particularly when debugging.
Closes #10813.
NB, while this is somewhat less efficient than the previous code, the overhead should be negligible compared to reading the file and possibly byte-compiling it. The speed loss is also offset by the fact that you can now selectively override single submodules instead of copying the whole module tree to the device (assuming that this is possible in the first place).