anyway, how is your workflow?

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
_jg_
Posts: 12
Joined: Sat Mar 19, 2016 3:47 am

anyway, how is your workflow?

Post by _jg_ » Mon Jan 08, 2018 1:21 am

hi everyone

first a little background: i wrote a (dummy almost) module in my laptop, and then copied to /lib directory in my pyboard's flash card. When i connected to pyboard's REPL i could import the module but it did not work. After a while i detected a missing colon and after that all went well.

The reason of this post is to ask you of how is yoor work flow when developing scripts or modules for your boards..

At first i tried testing my module with the unix port in my machine but it didnt work because i needed "pyb" library and it is not installed in that port. Tried to install it with

Code: Select all

 >micropython -m upip  install pyb
but it throws an error "Error installing 'pyb': , packages may be partially installed"
Second try: i placed "prints" along the file expecting that during the import those "prints" would indicate where it failed.. did not work.
Third try: placing objects along the module.. expected that after importing the module i could make dir(myModule) and see which objects where created.. did not work either (only __file__ and __name__ showing). Seems that if there is an error the module name can be imported but the whole thing is ignored.
So what i ended up doing was edit directly the file in the sd card and comment this; comment that; until i found the error.

So i made it work but i wonder -and ask you guys- if there a smoother way of working this out. How do you do it?

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: anyway, how is your workflow?

Post by pythoncoder » Mon Jan 08, 2018 6:36 am

The pyb module supports and requires Pyboard hardware so cannot be used with the Unix port. The Unix port is best for developing code which is not hardware dependent and for porting CPython code to MicroPython.

For Pyboard development I edit files on the PC and use rshell to update the SD card. If a module has a syntax error it will not be imported - you need to issue ctrl-X to go back to the rshell prompt, correct the error on your PC file, copy it back to the SD card, and re-try the import. After a successful import dir() will work.

This approach ensures the master copy is on the PC and also allows you to use version control. Print statements also work. Bear in mind (if you come from a Python2 background) that Python3 requires parens: print('Hello'). It's worth learning the changes between Python2 and Python3 - some are quite subtle but Python3 is much improved.
Peter Hinch
Index to my micropython libraries.

SpotlightKid
Posts: 463
Joined: Wed Apr 08, 2015 5:19 am

Re: anyway, how is your workflow?

Post by SpotlightKid » Mon Jan 08, 2018 11:50 am

Even though the unix port of micropython does not support all modules the bare metal ports have, you can still use it to do a syntax-only check on your .py files. You could also use CPython or mpy-cross for this. I even often run flake8 via CPython on my micropython source files.

stijn
Posts: 735
Joined: Thu Apr 24, 2014 9:13 am

Re: anyway, how is your workflow?

Post by stijn » Mon Jan 08, 2018 2:58 pm

SpotlightKid wrote:
Mon Jan 08, 2018 11:50 am
I even often run flake8 via CPython on my micropython source files.
This. Writing Python in a text editor which has automatic live Flake8 linting catches so many syntax/forgot import/wrong indent/variable name misspelled/... errors it would almost be a mistake not to use it. And add PEP8 formatting to that to get everything looking consistent and readable. And linting of files so you get a usable 'go to definition' is also pretty handy.
Last edited by stijn on Mon Jan 08, 2018 2:59 pm, edited 1 time in total.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: anyway, how is your workflow?

Post by dhylands » Mon Jan 08, 2018 2:58 pm

I'll often use a pyb stub to verify that I can load stuff on the host side. An example of one of my stubs is here:
https://github.com/dhylands/bioloid3/blob/master/pyb.py
Somebody else put together a more complete stub here:
https://github.com/dastultz/micropython-pyb

When I do get around to actually testing on the pyboard, I use rshell. I normally have my editor open and leave rshell running in a terminal window. I cd into the destination directory on the pyboard that I'm using and then create a command something like this:

Code: Select all

cp /home/dhylands/some-directory/foo.py .; repl ~ import foo ~
into the rshell prompt. This will copy the file over enter the REPL and import the module. If it fails, I can hit Control-X to exit the REPL. I'll edit my file on the host and hit the up arrow at the rshell prompt and re-test.

rshell also has an rsync command now to sync an entire directory tree. For smallish self-contained files, I might use the edit command in rshell, but I've found I prefer to have the master copy of everything on the host.

_jg_
Posts: 12
Joined: Sat Mar 19, 2016 3:47 am

Re: anyway, how is your workflow?

Post by _jg_ » Tue Jan 09, 2018 1:33 am

thanks for all your replies.

interesting and useful all of them.
I though the unix port was meant to be almost a simulation of working with the board.
I think using flake8 is what will make the catching of errors less annoying.
I had no idea of those "stubs", anytime i'll give them a try.

my actual workflow is somehow similar to pythoncoder's. I set up a gnu-screen session, in one window edit the local file, other window connected to the pyboard, and another one to make the copy from laptop to board.
i was afraid that copying files from PC to pyboard too often could be stressfull to the board.. is it? is it less stressful if i use rsync instead of the command-line-copy?

thanks.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: anyway, how is your workflow?

Post by pythoncoder » Tue Jan 09, 2018 6:19 am

An alternative to flake8 is pylint.

As for worries about flash wear, I don't think the method of updating the filesystem will alter this. But there are some very heavy users of the Pyboard in here and I don't think anyone's worn one out yet. It's rated at 10,000 cycles - do the maths ;)

You can avoid flash wear with an SD card, in which case the Flash is only written when you flash new firmware. The one serious concern is if your program repeatedly writes a file to flash where you could clock up 10K cycles quite quickly.

I use SD cards in development because they are bigger and faster. I only use the Flash filesystem for a final deployment, notably in ultra low power applications.
Peter Hinch
Index to my micropython libraries.

Post Reply