Skip to content

tools/mpremote: Add manifest function.#8231

Open
andrewleech wants to merge 1 commit into
micropython:masterfrom
andrewleech:mpremote_manifest
Open

tools/mpremote: Add manifest function.#8231
andrewleech wants to merge 1 commit into
micropython:masterfrom
andrewleech:mpremote_manifest

Conversation

@andrewleech
Copy link
Copy Markdown
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
Copy Markdown

codecov-commenter commented Jan 31, 2022

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.46%. Comparing base (2dc2e30) to head (f5da2d3).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #8231   +/-   ##
=======================================
  Coverage   98.46%   98.46%           
=======================================
  Files         176      176           
  Lines       22784    22784           
=======================================
  Hits        22435    22435           
  Misses        349      349           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@andrewleech
Copy link
Copy Markdown
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
Comment thread tools/mpremote/mpremote/console.py
@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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

Is there any progress on #7731?

@andrewleech
Copy link
Copy Markdown
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
Copy link
Copy Markdown
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
Comment thread tools/mpremote/pyproject.toml Outdated
"setuptools>=42",
"wheel"
"wheel",
"mpy-cross",
Copy link
Copy Markdown
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
Copy Markdown
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.

Add a `manifest` command that processes a MicroPython manifest.py file,
compiles .py files to .mpy using mpy-cross, and places the output in a
local build directory.  When combined with `mount`, the compiled modules
are added to the device's sys.path and are automatically re-built on
soft-reset.

Signed-off-by: Andrew Leech <[email protected]>
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