DavesCodeMusings / mpremote-vscode

Visual Studio Code extension for mpremote Python module
BSD 2-Clause "Simplified" License
11 stars 1 forks source link

Target destination for `sync` #24

Closed djesic closed 4 months ago

djesic commented 5 months ago

Just found this project, thank you for developing it! I have a request that a small feature that would make it a permanent part of my tooling This would be a kind of follow up for #19

Similar to srcSubdirectory, is it possible to add a target destination for the sync command?

ie. Copy the srcSubdirectory folder to /flash/lib/ on the board

Thank you for considering this feature request

Kind regards, Danilo

DavesCodeMusings commented 5 months ago

I think this is something that could be added without much trouble. I'm assuming you're using a microcontroller that has the flash filesystem mounted on /flash instead of on /. I recall reading about that in the MicroPython docs, but I don't recall the details. Let me do some searching and see what I can figure out.

DavesCodeMusings commented 4 months ago

There is already a feature for Change remote working directory (chdir) that allows you to choose a path on the microcontroller flash and always prepend the path to any upload operations. However... it does not currently affect sync operations.

I think adding a configuration checkbox option for something like "Use remote working directory for sync" might do the trick.

I hesitate to add an extension option like "Prepend path", because that would affect all attached devices. And, in the rare instance you had two microcontrollers attached, one using /flash and one not, you would have problems with a global setting like that.

So, with my proposed solution, you would:

  1. Select the "Use remote working dir for sync" checkbox option in the extension settings.
  2. Right-click your microcontroller in the Serial Explorer area and select Change remote working directory (chdir) selecting the /flash subdir.
  3. Upload everything with Sync and watch your files go into /flash.
  4. Profit!

Any comments are welcome.

djesic commented 4 months ago

I think those are good precautions. The flow makes sense 🙂

DavesCodeMusings commented 4 months ago

This should be good to go in version 1.21.11 and beyond.

  1. Select the "Use Remote Working Dir For Sync" checkbox option in the extension settings.
  2. Right-click your microcontroller in the Serial Explorer area and select Change remote working directory (chdir) selecting the subdir you want to use as the root (e.g. /flash).
  3. Upload everything with Sync and watch your files go into the remote working directory.

Unchecking the configuration option or not setting a remote working directory will upload everything into / as has been the behavior in the past.

djesic commented 4 months ago

I've updated the extension and checked the box, but step 2. is not giving me any input field or output on the terminal to enter the path

DavesCodeMusings commented 4 months ago

The path is selected per microcontroller using the Change Remote Working Directory (chdir) command. You'll find it by right-clicking the serial port for your microcontroller. In the screenshot below, I'm setting the remote working directory for the device on COM3.

image

Then up at the top of the VS Code window, you'll get a selection list of directories on the device.

image

Select the directory you want to use as the remote root.

djesic commented 4 months ago

Yes, was doing the same for my device /dev/ttyACM0 image

DavesCodeMusings commented 4 months ago

Look up at the top of your VS Code window for the dropdown showing directories you can choose from. image

djesic commented 4 months ago

That selector for the folder is not showing up for me 😢

DavesCodeMusings commented 4 months ago

Try creating a directory with mkdir (like /tmp or anything). Maybe it's not recognizing the /flash mountpoint as a directory???

DavesCodeMusings commented 4 months ago

Can you try this from a REPL prompt (the last dir name, /lib, could be any dir name that's on the device.)

>>> from os import stat
>>> stat("boot.py")
>>> stat("/flash")
>>> stat("/lib")

Hopefully, you'll see something like this:

>>> from os import stat
>>> stat("boot.py")
(32768, 0, 0, 0, 0, 0, 571, 2181, 2181, 2181)
>>> stat("/flash")
(16384, 0, 0, 0, 0, 0, 1073739552, 0, 0, 0)
>>> stat("/lib")
(16384, 0, 0, 0, 0, 0, 1076419753, 0, 0, 0)

32768 indicates a regular file. 16384 indicates a directory. This is how the extension decides what to show when presenting the selection dropdown. If /flash is not showing as 16384, it's not going to be shown in the selection list.

If that's the case, I'm curious what the number is for /flash.

djesic commented 4 months ago
>>> from os import stat
>>> stat("boot.py")
(32768, 0, 0, 0, 0, 0, 454, 768660232, 768660232, 768660232)
>>> stat("/flash")
(16384, 0, 0, 0, 0, 0, 0, 0, 0, 0)
>>> stat("/flash/lib")
(16384, 0, 0, 0, 0, 0, 0, 768667474, 768667474, 768667474)
DavesCodeMusings commented 4 months ago

That seems correct. boot.py is 32768, so it's interpreted as a regular file. /flash is 16384, so it's interpreted as a directory. I'm surprised you are not seeing it in the dropdown. Even if I've already changed to a directory, I still see the dropdown with .. as a selection.

image

Though one time I forgot to exit the REPL prompt before trying Change Remote Working Directory and then I got similar behavior to what you're seeing. Maybe that's it??? If it is, try exiting REPL with CTRL-X first and see if it works.

djesic commented 4 months ago

Tried detaching and then attaching, I've tried some of the commands and none are able to list anything from the device 😢 This is from mkdir

╰─❯ mpremote connect /dev/ttyACM0 fs mkdir '/test'
mkdir :/test
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
OSError: [Errno 19] ENODEV

It could be that it's the fault of my board/setup somehow, I appreciate time you've invested into helping me already

DavesCodeMusings commented 4 months ago

All my boards are Espressif devices. The /flash dir isn't used on those, so I'm kind of stumbling in the dark. I think the fact stat("/flash") shows up as 32768 is a good sign though.

If you get it to work, could you post the solution here for others?

djesic commented 4 months ago

Absolutely, I will do some trial and error and report if I manage to make it work on my board. For reference, I'm working on an STM based board - Arduino Portenta H7