Skip to content
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

Python module support is not yet implemented #14

Closed
pfalcon opened this issue Dec 30, 2013 · 7 comments
Closed

Python module support is not yet implemented #14

pfalcon opened this issue Dec 30, 2013 · 7 comments
Labels

Comments

@pfalcon
Copy link
Contributor

pfalcon commented Dec 30, 2013

Not trying to cause any hassle, but instead to have fact recorded, and possible to get some comments regarding planning and issues related to implementation.

So, "import" statement (well, import() builtin func) is currently not implemented (just dumps its args), and mp_module_new() has following comment:

// temporary way of making C modules
// hack: use class to mimic a module

I understand that full-fledged modules support is probably not top-priority for MCU port - being able to create C modules and using just single main Python app already allows to do a lot of things. But sooner or later it will be needed - that's what we all expect from Python - being easily to reuse 3rd-party modules, right? (Actually #7 already touched on that.) And "unix" port is pretty orphaned without it.

So, any planning/ETA when this might be implemented? Any blockers on the road? For example, I don't know if all needed things on core side are there, but I may imagine there're many "boring" questions like modules search paths, then differences between search paths/mehods for ports (MCU vs unix), support for precompiled bytecode files, etc. etc.

@dpgeorge
Copy link
Member

Yep, import is not yet functional :) This was pretty much the next thing on my list to get working, since I know it's very important, and I can't really call it Micro Python if it ain't got import/modules.

There are no road blocks, I just need time to implement it. The compiler emits correct import code, all the framework is there to run "import" when needed, and module-level variables (dictionary) is already being used for the main script.

@Neon22
Copy link
Contributor

Neon22 commented Dec 31, 2013

I'm hoping to help with this issue by doing the following. Can you guys validate if this is a good idea - or if the import module for micropython will take care of it ?

It makes a minmal set of python code by copying and stripping unused functions out of imported modules.
First - it processes the tree of imports from all python files.
Second - it copies these files to a new subdirectory, renames them and their respective imports so the new files are loaded instead of the original modules.
Third - it removes all unused code from these files.
The end result is a minimal python setup which will have the smallest memory footprint.

It is one way to solve the problem, but the import preprocessor could also strip out unused functions (I think).

Is this a useful thing to do ?
Its here: https://github.com/Neon22/python-flavin

@pfalcon
Copy link
Contributor Author

pfalcon commented Dec 31, 2013

@dpgeorge: Good plan, thanks!

@pfalcon
Copy link
Contributor Author

pfalcon commented Dec 31, 2013

@Neon22: Regardless of how uPy module system will work, I guess your tool is useful. I hope you tried to search prior art to avoid reinventing a wheel (but I personally never heard of such tool for Python). Also I hope you keep in mind that in general case it's not possible to do what you want in a dynamic language ;-). Because for example you can do obj.getattr("do_" + method)(). So, I hope you'll balance automation and heuristics vs user configurability. Java's ProGuard as used e.g. by Android can be example of production-quality tool which does this stuff. All in all, this is worth a separate space to discuss (yeah, we'll need forum in some time ;-). Hope someone indeed helps Damien with that to let him do hacking, which noone else can do ;-).)

@dpgeorge
Copy link
Member

dpgeorge commented Jan 1, 2014

@Neon22: the upython code will not do any of this. It will act as normal CPython does and read in the right Python script, compile/run it, and assign global names as appropriate. Any minification, as you suggest, would need to be done by a preprocessor. So your tool would be useful, but I wouldn't classifiy it as a priority.

@dpgeorge
Copy link
Member

dpgeorge commented Jan 3, 2014

Basic import is now working. Still some things to fix up so I'll keep this issue open.

@pfalcon
Copy link
Contributor Author

pfalcon commented Jan 13, 2014

Basic import indeed works, so let's close this and open more feature-detailed tickets as needed.

@pfalcon pfalcon closed this as completed Jan 13, 2014
tannewt referenced this issue in tannewt/circuitpython Dec 17, 2016
…ge member

to make for easy conversion. Fixes #14.
drrk pushed a commit to drrk/micropython that referenced this issue Jan 22, 2017
tannewt referenced this issue in tannewt/circuitpython Jul 28, 2020
retryfail pushed a commit to retryfail/micropython that referenced this issue Aug 20, 2020
ftpserver.c: Initialize file offset (+ other minor changes)
WeActStudio pushed a commit to WeActStudio/micropython that referenced this issue Feb 14, 2021
mattytrentini referenced this issue in mattytrentini/micropython Jul 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants