JetBrains / intellij-micropython

Plugin for MicroPython devices in PyCharm and IntelliJ
https://plugins.jetbrains.com/plugin/9777-micropython
Apache License 2.0
507 stars 106 forks source link

"Flash main.py" creates folder structure on device even with source root set #192

Open kadin2048 opened 2 years ago

kadin2048 commented 2 years ago

I am running Pycharm 2021.3 with intellij-micropython downloaded from the plugin repository today (10 June 2022).

I created a test project called "esp8266-test" which on my local machine is stored in ~/src/. I created a single Python file called main.py (so it is stored at ~/src/esp8266-test/main.py) with a single print() statement. I then set the "esp8266-test" directory as a Sources Root (right click, Mark Directory as Sources Root) so it's blue and specifically marked as sources root.

I then ran "Flash main.py" from the Run menu. I expected this to copy the main.py file to the root of the device's filesystem, which would cause it to be run automatically on each boot (after boot.py).

However that is not what is happening. Instead, the micropython plugin seems to be recreating the entire folder hierarchy that the Python file is stored in on my hard drive, on the device filesystem. This doesn't make sense, but I can't get it to not do it.

Output from Flash main.py:

Connecting to /dev/tty.wchusbserial1d10
Uploading files: 0% (0/1)
/Users/myusername/src/esp8266-test/main.py -> ../../../../../../Users/myusername/src/esp8266-test/main.py
Uploading files: 100% (1/1)
Soft reboot

As can be seen, it is creating the directories /Users/myusername/src/esp8266-test/ on the device filesystem. I don't know why, because it should be treating esp8266-test as the source root and putting the enclosed Python file (main.py) onto the device root.

This can be further verified in the REPL:

MicroPython v1.18 on 2022-01-17; ESP module with ESP8266
Type "help()" for more information.
>>> 
>>> import os
>>> os.listdir()
['Users']

I have tried repeatedly setting/unsetting/setting the project root at the source root, to no avail. I have also tried restarting PyCharm. The behavior is repeatable.

Can anyone advise if there is something I'm missing? It looks like a bug to me.

kadin2048 commented 2 years ago

I also tested and observed the same behavior using the latest PyCharm:

PyCharm 2022.1.2 (Community Edition)
Build #PC-221.5787.24, built on May 31, 2022
Runtime version: 11.0.15+10-b2043.56 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 10.13.6
GC: G1 Young Generation, G1 Old Generation
Memory: 2048M
Cores: 8
Registry:
    debugger.watches.in.variables=false

Non-Bundled Plugins:
    intellij-micropython (1.3.1)
FynnFreyer commented 2 years ago

This is happening to me too on

PyCharm 2022.1.3 (Professional Edition)
Build #PY-221.5921.27, built on June 21, 2022

The plugin is running /path/to/project/venv/bin/python /path/to/PyCharm2022.1/intellij-micropython/scripts/microupload.py -C /path/to/project/src -v /dev/ttyACM0 /path/to/project/src/main.py and the program is not executing, but when I manually run /path/to/project/venv/bin/python /path/to/PyCharm2022.1/intellij-micropython/scripts/microupload.py -C /path/to/project/src -v /dev/ttyACM0 main.py in a terminal, everything works fine.

(the difference between the two commands being only the missing project path at the end in the second command)