Compiling in scripts

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
dvrhax
Posts: 6
Joined: Fri Jul 07, 2017 11:13 pm

Compiling in scripts

Postby dvrhax » Wed Jul 12, 2017 2:57 am

Looking through the forum it appears that this should be possible but doesn't go into great details of the specifics about how to include your own custom python modules into the binary so that your programs can access them natively. Specifically I'm looking for where in the src tree you would put scripts and what if any build switches need to be thrown to get it to work.

Thanks

User avatar
Roberthh
Posts: 655
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Compiling in scripts

Postby Roberthh » Wed Jul 12, 2017 2:03 pm

If you place python modules into the directory "modules", they will be compiled during the build process and embedded into the binary as frozen bytecode.

User avatar
pythoncoder
Posts: 1635
Joined: Fri Jul 18, 2014 8:01 am

Re: Compiling in scripts

Postby pythoncoder » Thu Jul 13, 2017 6:52 am

@dvrhax it would help us answer your query if you clarified what you are aiming to achieve.

If you put a Python source module in the filesystem you can import it and use it. As @Roberthh explained, you can alternatively precompile the module and "freeze" the resultant bytecode as part of the build. The module can then be used in exactly the same way as if it were in the filesystem. The advantage is that RAM is saved in two ways. Firstly the compiler isn't invoked at runtime. And secondly the bytecode resides in Flash rather than in RAM.
Peter Hinch

dvrhax
Posts: 6
Joined: Fri Jul 07, 2017 11:13 pm

Re: Compiling in scripts

Postby dvrhax » Fri Jul 14, 2017 1:28 am

Thanks for the clarification. I was looking to do the latter I have the mysql library that I was looking to use but I didn't want it cluttering up the file system plus I assumed there would be other advantages to having it compiled in. Thanks to the both of you for your help.


Return to “Development of MicroPython”

Who is online

Users browsing this forum: No registered users and 1 guest