Skip to content

Commit 12d3446

Browse files
committed
add default value to unspecified project options
1 parent c547bbb commit 12d3446

File tree

8 files changed

+92
-156
lines changed

8 files changed

+92
-156
lines changed

apps/microtvm/arduino/template_project/microtvm_api_server.py

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,6 @@
5656
raise FileNotFoundError(f"Board file {{{BOARDS}}} does not exist.")
5757

5858

59-
def get_cmsis_path(cmsis_path: pathlib.Path) -> pathlib.Path:
60-
"""Returns CMSIS dependency path"""
61-
if cmsis_path:
62-
return pathlib.Path(cmsis_path)
63-
if os.environ.get("CMSIS_PATH"):
64-
return pathlib.Path(os.environ.get("CMSIS_PATH"))
65-
assert False, "'cmsis_path' option not passed!"
66-
67-
6859
class BoardAutodetectFailed(Exception):
6960
"""Raised when no attached hardware is found matching the requested board"""
7061

@@ -337,7 +328,7 @@ def _copy_cmsis(self, project_path: pathlib.Path, cmsis_path: str):
337328
However, the latest release does not include header files that are copied in this function.
338329
"""
339330
(project_path / "include" / "cmsis").mkdir()
340-
cmsis_path = get_cmsis_path(cmsis_path)
331+
cmsis_path = pathlib.Path(cmsis_path)
341332
for item in self.CMSIS_INCLUDE_HEADERS:
342333
shutil.copy2(
343334
cmsis_path / "CMSIS" / "NN" / "Include" / item,
@@ -357,7 +348,7 @@ def _populate_makefile(
357348
flags = {
358349
"FQBN": self._get_fqbn(board),
359350
"VERBOSE_FLAG": "--verbose" if verbose else "",
360-
"ARUINO_CLI_CMD": self._get_arduino_cli_cmd(arduino_cli_cmd),
351+
"ARUINO_CLI_CMD": arduino_cli_cmd,
361352
"BOARD": board,
362353
"BUILD_EXTRA_FLAGS": build_extra_flags,
363354
}
@@ -377,9 +368,10 @@ def _populate_makefile(
377368
def generate_project(self, model_library_format_path, standalone_crt_dir, project_dir, options):
378369
# List all used project options
379370
board = options["board"]
380-
verbose = options.get("verbose")
381371
project_type = options["project_type"]
382-
arduino_cli_cmd = options.get("arduino_cli_cmd")
372+
arduino_cli_cmd = options["arduino_cli_cmd"]
373+
verbose = options["verbose"]
374+
383375
cmsis_path = options.get("cmsis_path")
384376
compile_definitions = options.get("compile_definitions")
385377
extra_files_tar = options.get("extra_files_tar")
@@ -455,12 +447,6 @@ def generate_project(self, model_library_format_path, standalone_crt_dir, projec
455447
build_extra_flags,
456448
)
457449

458-
def _get_arduino_cli_cmd(self, arduino_cli_cmd: str):
459-
if not arduino_cli_cmd:
460-
arduino_cli_cmd = ARDUINO_CLI_CMD
461-
assert arduino_cli_cmd, "'arduino_cli_cmd' command not passed and not found by default!"
462-
return arduino_cli_cmd
463-
464450
def _get_platform_version(self, arduino_cli_path: str) -> float:
465451
# sample output of this command:
466452
# 'arduino-cli alpha Version: 0.18.3 Commit: d710b642 Date: 2021-05-14T12:36:58Z\n'
@@ -494,11 +480,10 @@ def _get_fqbn(self, board: str):
494480

495481
def build(self, options):
496482
# List all used project options
497-
arduino_cli_cmd = options.get("arduino_cli_cmd")
483+
arduino_cli_cmd = options["arduino_cli_cmd"]
498484
warning_as_error = options.get("warning_as_error")
499485

500-
cli_command = self._get_arduino_cli_cmd(arduino_cli_cmd)
501-
self._check_platform_version(cli_command, warning_as_error)
486+
self._check_platform_version(arduino_cli_cmd, warning_as_error)
502487
compile_cmd = ["make", "build"]
503488
# Specify project to compile
504489
subprocess.run(compile_cmd, check=True, cwd=API_SERVER_DIR)
@@ -539,7 +524,7 @@ def _parse_connected_boards(self, tabular_str):
539524

540525
def _auto_detect_port(self, arduino_cli_cmd: str, board: str) -> str:
541526
# It is assumed only one board with this type is connected to this host machine.
542-
list_cmd = [self._get_arduino_cli_cmd(arduino_cli_cmd), "board", "list"]
527+
list_cmd = [arduino_cli_cmd, "board", "list"]
543528
list_cmd_output = subprocess.run(
544529
list_cmd, check=True, stdout=subprocess.PIPE
545530
).stdout.decode("utf-8")
@@ -599,7 +584,7 @@ def _get_board_from_makefile(self, makefile_path: pathlib.Path) -> str:
599584

600585
def flash(self, options):
601586
# List all used project options
602-
arduino_cli_cmd = options.get("arduino_cli_cmd")
587+
arduino_cli_cmd = options["arduino_cli_cmd"]
603588
warning_as_error = options.get("warning_as_error")
604589
port = options.get("port")
605590
board = options.get("board")
@@ -608,9 +593,8 @@ def flash(self, options):
608593
if not board:
609594
board = self._get_board_from_makefile(API_SERVER_DIR / MAKEFILE_FILENAME)
610595

611-
cli_command = self._get_arduino_cli_cmd(arduino_cli_cmd)
612-
self._check_platform_version(cli_command, warning_as_error)
613-
port = self._get_arduino_port(cli_command, board, port, serial_number)
596+
self._check_platform_version(arduino_cli_cmd, warning_as_error)
597+
port = self._get_arduino_port(arduino_cli_cmd, board, port, serial_number)
614598

615599
upload_cmd = ["make", "flash", f"PORT={port}"]
616600
for _ in range(self.FLASH_MAX_RETRIES):
@@ -639,7 +623,7 @@ def open_transport(self, options):
639623
import serial.tools.list_ports
640624

641625
# List all used project options
642-
arduino_cli_cmd = options.get("arduino_cli_cmd")
626+
arduino_cli_cmd = options["arduino_cli_cmd"]
643627
port = options.get("port")
644628
board = options.get("board")
645629
serial_number = options.get("serial_number")

0 commit comments

Comments
 (0)