Skip to content

Support importing native modules in native packages. #2657

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

Merged
merged 3 commits into from
Mar 5, 2020

Conversation

tannewt
Copy link
Member

@tannewt tannewt commented Feb 25, 2020

This only fixes the import portion. It doesn't actually change
reference behavior because modules within a package could already
be referenced through the parent package even though an error should
have been thrown.

This only fixes the `import` portion. It doesn't actually change
reference behavior because modules within a package could already
be referenced through the parent package even though an error should
have been thrown.
@tannewt
Copy link
Member Author

tannewt commented Feb 26, 2020

@jepler @v923z This should allow for importing submodules of ulab.

I've linked @jimmo to it and I bet @dpgeorge would be interested too.

@v923z
Copy link

v923z commented Feb 26, 2020

So the claim is that

from ulab import fft

fft.fft(...)

would work with this fix, right? If so, it is really great, thanks for taking care of it!

@dpgeorge Damien, do you think this could be merged into micropython proper on a reasonable time scale? With that we could maintain a single version of ulab, ant that would save some resources on our end.

@dpgeorge
Copy link

@tannewt thanks for the note, I'll look into incorporating this or similar. I didn't yet look in detail but this might be related: micropython#4731

@jimmo
Copy link

jimmo commented Feb 26, 2020

See micropython#5701 for the equivalent change upstream. Thanks for suggesting this, I think it's a much better approach than micropython#4731

Some minor notes on this PR:

  • Might need to check when looking at the globals dict that the result is actually a module (i.e. type == mp_module_type).
  • You can avoid the change in objmodule.c by just setting a flag in builtinimport, then avoid calling mp_store_attr at all.

@tannewt
Copy link
Member Author

tannewt commented Feb 26, 2020

Thanks @jimmo and @dpgeorge. Will keep an eye on upstream and plan on replacing this PR next time we merge from upstream.

@jimmo Good idea on the type check. I've added it and confirmed we can't import microcontroller.cpu which is not a module. My preference is to keep the set_attr because I'm assuming a module will track whether it's members have been imported in the future rather than having import manage it.

@tannewt
Copy link
Member Author

tannewt commented Mar 3, 2020

@jepler I think this is ready to merge.

Copy link

@jepler jepler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor nit.

Testing performed: merged with ulab branch and:

>>> import ulab.fft as fft
>>> fft.spectrum
<function>

@tannewt
Copy link
Member Author

tannewt commented Mar 3, 2020

@jepler Removed! Please take another look!

@jepler jepler self-requested a review March 5, 2020 20:28
Copy link

@jepler jepler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! And thanks for your patience while I missed the notification for 2 days.

I'm going to assume these "cancelled checks" are nothing to worry about.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants