Skip to content

tools/mpremote: Add manifest function. #8231

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

andrewleech
Copy link
Contributor

Add manifest command to mpremote which will compile a manifest.py from the specified folder, eg:

      $ MPY_DIR=../../micropython 
      $ PORT_DIR=../../micropython/ports/esp32
      $ mpremote manifest .

This will assemble / mpy-cross everything specified in the manifest.py into the folder _manifest.
If the current folder is also mounted, this folder will automatically be added to the path, eg:

      $ mpremote manifest . mount .

Alternatively, the built folder can by copied / synched to the device, in which case
the copied folder will be added to the path:

      $ mpremote manifest -s . 

A soft-reset will re-process the manifest file to include any local updates allowing fast development of local files in a larger project without needing to copy / import-over-mount all files every reset.

Ideally, if the mpy_cross python package is installed from pypi, the local MPY_DIR=../../micropython variables will not need to be specified (unless your local manifest uses them directly`

@andrewleech andrewleech force-pushed the mpremote_manifest branch 2 times, most recently from 6835ef4 to 4099608 Compare January 31, 2022 07:13
@codecov-commenter
Copy link

codecov-commenter commented Jan 31, 2022

Codecov Report

Merging #8231 (10f2db7) into master (0a21762) will increase coverage by 0.00%.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #8231   +/-   ##
=======================================
  Coverage   98.39%   98.40%           
=======================================
  Files         153      153           
  Lines       20187    20188    +1     
=======================================
+ Hits        19864    19865    +1     
  Misses        323      323           
Impacted Files Coverage Δ
py/compile.c 99.94% <0.00%> (+<0.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0a21762...10f2db7. Read the comment docs.

@andrewleech
Copy link
Contributor Author

andrewleech commented Jan 31, 2022

mpremote is also being packaged to wheel in github-actions in this PR, can be tested with

Go to actions page for the task, download artifact link at bottom: https://github.com/micropython/micropython/actions/runs/1775611454

https://github.com/micropython/micropython/suites/5129239273/artifacts/154344973

unzip mpremote.zip
pip install mpremote*.whl

@andrewleech andrewleech force-pushed the mpremote_manifest branch 5 times, most recently from 1a740b6 to e700ee8 Compare February 1, 2022 00:14
@andrewleech andrewleech changed the title WIP: mpremote manifest support mpremote manifest support Feb 1, 2022
@dpgeorge dpgeorge added the tools Relates to tools/ directory in source, or other tooling label Feb 1, 2022
@andrewleech andrewleech changed the title mpremote manifest support WIP: mpremote manifest support Feb 4, 2022
@andrewleech
Copy link
Contributor Author

I still want to do some more work here to speed up the sync process, make it as efficient as I can.

With a remote littlefs partition on esp32 even just doing recursive file listing can be painfully slow ( ~ 12 seconds for 128 files across 28 folders ), not sure how much could be done to improve this.

One of the main things I'd like to fix is more related to fs cp -r than the manifest.
When copying a folder from computer over an existing remote folder, existing files will be overwritten however remote files/folders contained within that have since been deleted on computer will be left on the device. This way you can have stale content causing unexpected results.
On linux, a cp -r will entirely replace an existing folder unless you add the -u flag.

@dpgeorge
Copy link
Member

dpgeorge commented Feb 4, 2022

I want to look into general file transfer speed using mpremote. It should be possible to improve the speed for files going in to the device.

On linux, a cp -r will entirely replace an existing folder unless you add the -u flag.

+1

@andrewleech
Copy link
Contributor Author

I haven't looked at the actual file transfer speed over the serial port, however I've got re-copying folders working much faster with either a sha or (size + mtime) check on remote vs local filesystems.

The best speed so far is by scanning the remote folder tree into a dict and passing that back to mpremote to check against local folder; this can be used to delete extra remote files and not transfer ones that aren't needed.

Most of the time for this operation on a mostly unchanged folder is just in a recursive walk in micropython, even with just one os.stat per file it can be quite slow. Might not be able to do much about that though, no way to know if there are extra files to delete without doing a os.listdir and then os.stat on each one to know if it's a dir or a file...

@dpgeorge
Copy link
Member

dpgeorge commented Feb 4, 2022

no way to know if there are extra files to delete without doing a os.listdir and then os.stat on each one to know if it's a dir or a file...

try uos.ilistdir()

@andrewleech
Copy link
Contributor Author

Yes of course, I did forget about the difference between the two. I'll try that later and see how much improvement it makes

@peterhinch
Copy link
Contributor

Is there any progress on #7731?

@andrewleech
Copy link
Contributor Author

Is there any progress on #7731?

I haven't run into this issue myself so hadn't seen that ticket. At least it looks reasonably easy to reproduce, though there could be a few issues in that mix too

@andrewleech andrewleech force-pushed the mpremote_manifest branch 2 times, most recently from 10f2db7 to 4ff9a53 Compare March 9, 2022 22:45
@andrewleech
Copy link
Contributor Author

For now I've trimmed this PR back down to just the manifest command, no sync. This command combined with mount is enough on many devices (ones with native usb at least) to allow fast development of projects which use a manifest file to organise the files / libraries.

I'll continue to work on sync / deploy command/s, along with any file transfer speed improvements & fixes in a follow up PR.

@andrewleech andrewleech changed the title WIP: mpremote manifest support tools/mpremote: Add manifest function. Mar 10, 2022
@@ -1,6 +1,7 @@
[build-system]
requires = [
"setuptools>=42",
"wheel"
"wheel",
"mpy-cross",
Copy link
Contributor

Choose a reason for hiding this comment

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

should 'mpy-cross' be pinned to a specific version, or is it intentionally un-versioned ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My intention at the time was to be un-pinned, to always use latest (because I generally always use latest micropython).
However now, there's efforts under way to have the mpy-cross package built / managed as part of this repo and integrate it into mpremote in a cleaner and more compatible way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tools Relates to tools/ directory in source, or other tooling
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants