upydev icon indicating copy to clipboard operation
upydev copied to clipboard

`Watch` mode would be nice

Open stsdc opened this issue 5 years ago • 10 comments

upydev watch -fre ./src/*.py would watch for any changes in files in a project directory. If change occurred it will upload only the changed file.

stsdc avatar May 02 '20 13:05 stsdc

I've done something similar with the 'git' integration for the SHELL-REPL modes check the gif in README: New in version 0.2.6: 'git' integration in SHELLS (SSL/Web/SERIAL): (This needs 'git' available in path, see Git)

and the Documentation for the SHELL-REPLS (SSL/Web and SERIAL)

So the device can act as a "remote" git repo, with a similar workflow. The commands I've implemented are:

  • Use git init dev to initiate device repo
  • Use git push dev after a git commit .. command or a git pull command to push the changes to the device.
  • Use git log dev to see the latest commit pushed to the device (git log dev -a to see all commits)
  • Use git log host to see the latest commit in the local repo
  • Use git status dev to see if the local repo is ahead of the device repo and track these changes
  • Use git clone_dev to clone the local repo into the device
  • Use git repo to open the remote repo in the web browser if remote repo exists Any other git command will be echoed directly to git

The only thing to be aware is empty folders won't be pushed, so just be sure every folder has a file in it.

Carglglz avatar May 02 '20 15:05 Carglglz

But You still have to type git push to push changes to board?

stsdc avatar May 02 '20 16:05 stsdc

Yes git push dev will push local changes to the "device repo", git push will push local changes to a remote (e.g. GitHub ) if it exists.

Otherwise for this watch mode there should be some sort of demon running to check for file changes inside a directory (cwd?) (name, number of files and hashes?)

But if you want to implement this mode feel free to try/do it 👍

Carglglz avatar May 02 '20 16:05 Carglglz

I'll look into this. This should work somehow like js task runners/bundlers.

stsdc avatar May 02 '20 17:05 stsdc

Look at this: https://stackoverflow.com/a/18599427/1589989

stsdc avatar May 07 '20 17:05 stsdc

I think I've came up with an idea on how to do this: using a log file in the cwd of the project.

The use of command upydev watch -fre cwd or similar, will create a log with with file names, hashes and number of files, so next time you do upydev put -diff will upload only the files that are different and then the log file is updated. This could be applied to d_sync command as d_sync -diff too, it may be a bit harder but still doable.

If change occurred it will upload only the changed file.

I think there is no need to automate the upload on every change, or is there?

I may give it a go this week

Carglglz avatar May 07 '20 21:05 Carglglz

Check #16

Carglglz avatar May 08 '20 17:05 Carglglz

Okay, my concept was to upload immediately after file change. But that is also nice to have.

stsdc avatar May 12 '20 18:05 stsdc

I know, but how frequent should this mode check if there are any changes? I usually tend to save the file even if I haven't finished. This would mean the file is uploaded every time I save it?

Carglglz avatar May 12 '20 19:05 Carglglz

Yes. I do have an autosave enabled. So it is required, for example, 1s wait before upload, so it doesn't trigger on every character. However I do now play with React Native and it pushes changes on every character :grinning:, but works OK.

stsdc avatar May 12 '20 21:05 stsdc