fix(dev): run mpremote from PATH or python -m
Made-with: Cursor
This commit is contained in:
27
dev.py
27
dev.py
@@ -1,10 +1,20 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import shutil
|
||||
import subprocess
|
||||
import serial
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def mpremote_base():
|
||||
"""mpremote on PATH, or same interpreter as this script (e.g. pipenv venv)."""
|
||||
exe = shutil.which("mpremote")
|
||||
if exe:
|
||||
return [exe]
|
||||
return [sys.executable, "-m", "mpremote"]
|
||||
|
||||
|
||||
print(sys.argv)
|
||||
|
||||
# Extract port (first arg if it's not a command)
|
||||
@@ -19,17 +29,20 @@ for cmd in sys.argv[1:]:
|
||||
match cmd:
|
||||
case "src":
|
||||
if port:
|
||||
subprocess.call(["mpremote", "connect", port, "fs", "cp", "-r", ".", ":" ], cwd="src")
|
||||
subprocess.call(
|
||||
[*mpremote_base(), "connect", port, "fs", "cp", "-r", ".", ":"],
|
||||
cwd="src",
|
||||
)
|
||||
else:
|
||||
print("Error: Port required for 'src' command")
|
||||
case "lib":
|
||||
if port:
|
||||
subprocess.call(["mpremote", "connect", port, "fs", "cp", "-r", "lib", ":" ])
|
||||
subprocess.call([*mpremote_base(), "connect", port, "fs", "cp", "-r", "lib", ":"])
|
||||
else:
|
||||
print("Error: Port required for 'lib' command")
|
||||
case "ls":
|
||||
if port:
|
||||
subprocess.call(["mpremote", "connect", port, "fs", "ls", ":" ])
|
||||
subprocess.call([*mpremote_base(), "connect", port, "fs", "ls", ":"])
|
||||
else:
|
||||
print("Error: Port required for 'ls' command")
|
||||
case "reset":
|
||||
@@ -49,7 +62,7 @@ for cmd in sys.argv[1:]:
|
||||
print("Error: Port required for 'follow' command")
|
||||
case "db":
|
||||
if port:
|
||||
subprocess.call(["mpremote", "connect", port, "fs", "cp", "-r", "db", ":" ])
|
||||
subprocess.call([*mpremote_base(), "connect", port, "fs", "cp", "-r", "db", ":"])
|
||||
else:
|
||||
print("Error: Port required for 'db' command")
|
||||
case "test":
|
||||
@@ -64,7 +77,7 @@ for cmd in sys.argv[1:]:
|
||||
for test_file in test_files:
|
||||
print(f"Running {test_file}")
|
||||
code = subprocess.call(
|
||||
["mpremote", "connect", port, "run", test_file]
|
||||
[*mpremote_base(), "connect", port, "run", test_file]
|
||||
)
|
||||
if code != 0:
|
||||
failed.append((test_file, code))
|
||||
@@ -73,6 +86,8 @@ for cmd in sys.argv[1:]:
|
||||
for test_file, code in failed:
|
||||
print(f" {test_file} (exit {code})")
|
||||
else:
|
||||
subprocess.call(["mpremote", "connect", port, "run", "test/all.py"])
|
||||
subprocess.call(
|
||||
[*mpremote_base(), "connect", port, "run", "test/all.py"]
|
||||
)
|
||||
else:
|
||||
print("Error: Port required for 'test' command")
|
||||
|
||||
Reference in New Issue
Block a user