Skip to content

Commit

Permalink
Merge branch 'mpflash/add_boardnames' into mpflash/add-firmware
Browse files Browse the repository at this point in the history
  • Loading branch information
Josverl committed May 27, 2024
2 parents 193d78f + bc80291 commit fd59f54
Show file tree
Hide file tree
Showing 12 changed files with 898 additions and 2,379 deletions.
164 changes: 164 additions & 0 deletions board_id.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from pathlib import Path\n",
"\n",
"import src.mpflash as mpflash\n",
"import src.mpflash.mpflash.mpboard_id.get_boardnames as get_boardnames\n",
"\n",
"from src.mpflash.mpflash.mpboard_id.get_boardnames import Board, main as get_boardnames_main, boards_from_repo\n",
"import jsons\n"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"all = boards_from_repo(Path(\"repos/micropython\"), version=\"\")\n",
"few = all[:4]\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'[{\"board\": \"ESP32_GENERIC\", \"board_name\": \"-\", \"description\": \"ESP32-D2WD\", \"family\": \"micropython\", \"id\": \"ESP32_GENERIC\", \"mcu_name\": \"-\", \"path\": \"ports/esp32/boards/ESP32_GENERIC/mpconfigboard.cmake\", \"port\": \"esp32\", \"version\": \"v1.17.5-177-g923b5dbc-dirty\"}, {\"board\": \"ESP32_GENERIC\", \"board_name\": \"-\", \"description\": \"Generic ESP32 module with OTA\", \"family\": \"micropython\", \"id\": \"ESP32_GENERIC\", \"mcu_name\": \"-\", \"path\": \"ports/esp32/boards/ESP32_GENERIC/mpconfigboard.cmake\", \"port\": \"esp32\", \"version\": \"v1.17.5-177-g923b5dbc-dirty\"}, {\"board\": \"ESP32_GENERIC\", \"board_name\": \"-\", \"description\": \"Generic ESP32 module with SPIRAM\", \"family\": \"micropython\", \"id\": \"ESP32_GENERIC\", \"mcu_name\": \"-\", \"path\": \"ports/esp32/boards/ESP32_GENERIC/mpconfigboard.cmake\", \"port\": \"esp32\", \"version\": \"v1.17.5-177-g923b5dbc-dirty\"}, {\"board\": \"ESP32_GENERIC\", \"board_name\": \"-\", \"description\": \"ESP32-UNICORE\", \"family\": \"micropython\", \"id\": \"ESP32_GENERIC\", \"mcu_name\": \"-\", \"path\": \"ports/esp32/boards/ESP32_GENERIC/mpconfigboard.cmake\", \"port\": \"esp32\", \"version\": \"v1.17.5-177-g923b5dbc-dirty\"}]'"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data: str = jsons.dumps(few, indent=2, sort_keys=True, default=str)\n",
"u\n",
"data\n"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[Board(description='ESP32-D2WD', board_name='-', mcu_name='-', port='esp32', path=WindowsPath('ports/esp32/boards/ESP32_GENERIC/mpconfigboard.cmake'), id='ESP32_GENERIC', version='v1.17.5-177-g923b5dbc-dirty', family='micropython', board='ESP32_GENERIC'),\n",
" Board(description='Generic ESP32 module with OTA', board_name='-', mcu_name='-', port='esp32', path=WindowsPath('ports/esp32/boards/ESP32_GENERIC/mpconfigboard.cmake'), id='ESP32_GENERIC', version='v1.17.5-177-g923b5dbc-dirty', family='micropython', board='ESP32_GENERIC'),\n",
" Board(description='Generic ESP32 module with SPIRAM', board_name='-', mcu_name='-', port='esp32', path=WindowsPath('ports/esp32/boards/ESP32_GENERIC/mpconfigboard.cmake'), id='ESP32_GENERIC', version='v1.17.5-177-g923b5dbc-dirty', family='micropython', board='ESP32_GENERIC'),\n",
" Board(description='ESP32-UNICORE', board_name='-', mcu_name='-', port='esp32', path=WindowsPath('ports/esp32/boards/ESP32_GENERIC/mpconfigboard.cmake'), id='ESP32_GENERIC', version='v1.17.5-177-g923b5dbc-dirty', family='micropython', board='ESP32_GENERIC')]"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from typing import List\n",
"\n",
"jsons.loads(data, List[Board])\n"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[Board2(description='ESP32-D2WD', board_name='-', mcu_name='-', port='esp32', path=WindowsPath('ports/esp32/boards/ESP32_GENERIC/mpconfigboard.cmake'), id='ESP32_GENERIC', version='v1.17.5-177-g923b5dbc-dirty', family='micropython', board='ESP32_GENERIC', variant=''),\n",
" Board2(description='Generic ESP32 module with OTA', board_name='-', mcu_name='-', port='esp32', path=WindowsPath('ports/esp32/boards/ESP32_GENERIC/mpconfigboard.cmake'), id='ESP32_GENERIC', version='v1.17.5-177-g923b5dbc-dirty', family='micropython', board='ESP32_GENERIC', variant=''),\n",
" Board2(description='Generic ESP32 module with SPIRAM', board_name='-', mcu_name='-', port='esp32', path=WindowsPath('ports/esp32/boards/ESP32_GENERIC/mpconfigboard.cmake'), id='ESP32_GENERIC', version='v1.17.5-177-g923b5dbc-dirty', family='micropython', board='ESP32_GENERIC', variant=''),\n",
" Board2(description='ESP32-UNICORE', board_name='-', mcu_name='-', port='esp32', path=WindowsPath('ports/esp32/boards/ESP32_GENERIC/mpconfigboard.cmake'), id='ESP32_GENERIC', version='v1.17.5-177-g923b5dbc-dirty', family='micropython', board='ESP32_GENERIC', variant='')]"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from dataclasses import dataclass, field\n",
"\n",
"\n",
"@dataclass()\n",
"class Board2:\n",
" \"\"\"MicroPython Board definition\"\"\"\n",
"\n",
" # TODO: add variant\n",
" description: str\n",
" board_name: str\n",
" mcu_name: str\n",
" port: str\n",
" path: Path\n",
" id: str = field(default=\"\") # board id\n",
" board: str = field(default=\"\") # or property for board_id\n",
" version: str = field(default=\"\") # version of MicroPython\"\"\n",
" family: str = field(default=\"micropython\")\n",
" variant: str = field(default=\"\")\n",
"\n",
" def __post_init__(self):\n",
" # allow load of files without id\n",
" if not self.id and self.board:\n",
" self.id = self.board\n",
" elif not self.board and self.id:\n",
" self.board = self.id\n",
" if not self.board and not self.id:\n",
" raise ValueError(\"Board or id must be set\")\n",
"\n",
"\n",
"jsons.loads(data, List[Board2])\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# write to file\n",
"with open(\"few.json\", \"w\") as f:\n",
" f.write(jsons.dumps(few, indent=4))\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"with open(\"./board_info.json\", \"r\") as file:\n",
" info = jsons.load(file.read(), Board)\n",
"info\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
1 change: 1 addition & 0 deletions board_info.json

Large diffs are not rendered by default.

Empty file added few.json
Empty file.
23 changes: 11 additions & 12 deletions src/mpflash/mpflash/ask_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,18 @@ def filter_matching_boards(answers: dict) -> Sequence[Tuple[str, str]]:
Returns:
Sequence[Tuple[str, str]]: The filtered boards.
"""
versions = None
# if version is not asked ; then need to get the version from the inputs
if "versions" in answers:
_versions = list(answers["versions"])
if "stable" in _versions:
_versions.remove("stable")
_versions.append(micropython_versions()[-2]) # latest stable
if "preview" in _versions:
_versions.remove("preview")
_versions.extend((micropython_versions()[-1], micropython_versions()[-2])) # latest preview and stable

some_boards = known_stored_boards(answers["port"], _versions) # or known_mp_boards(answers["port"])
else:
some_boards = known_stored_boards(answers["port"])
versions = list(answers["versions"])
if "stable" in versions:
versions.remove("stable")
versions.append(micropython_versions()[-2]) # latest stable
elif "preview" in versions:
versions.remove("preview")
versions.extend((micropython_versions()[-1], micropython_versions()[-2])) # latest preview and stable

some_boards = known_stored_boards(answers["port"], versions) # or known_mp_boards(answers["port"])

if some_boards:
# Create a dictionary where the keys are the second elements of the tuples
Expand All @@ -119,7 +118,7 @@ def filter_matching_boards(answers: dict) -> Sequence[Tuple[str, str]]:
# Get the values of the dictionary, which are the unique items from the original list
some_boards = list(unique_dict.values())
else:
some_boards = [(f"No {answers['port']} boards found for version(s) {_versions}", "")]
some_boards = [(f"No {answers['port']} boards found for version(s) {versions}", "")]
return some_boards


Expand Down
Loading

0 comments on commit fd59f54

Please sign in to comment.