mpflash 0.8.4__py3-none-any.whl → 0.8.6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
mpflash/ask_input.py CHANGED
@@ -11,7 +11,8 @@ from loguru import logger as log
11
11
 
12
12
  from .common import DownloadParams, FlashParams, ParamType
13
13
  from .config import config
14
- from .mpboard_id import get_known_boards_for_port, get_known_ports, known_stored_boards
14
+ from .mpboard_id import (get_known_boards_for_port, get_known_ports,
15
+ known_stored_boards)
15
16
  from .mpremoteboard import MPRemoteBoard
16
17
  from .vendor.versions import micropython_versions
17
18
 
@@ -28,6 +29,11 @@ def ask_missing_params(
28
29
  Returns:
29
30
  ParamType: The updated parameters.
30
31
  """
32
+ if not config.interactive:
33
+ # no interactivity allowed
34
+ log.info("Interactive mode disabled. Skipping ask for user input.")
35
+ return params
36
+
31
37
  import inquirer
32
38
 
33
39
  log.trace(f"ask_missing_params: {params}")
@@ -36,9 +42,6 @@ def ask_missing_params(
36
42
  # if action download, multiple input
37
43
  multi_select = isinstance(params, DownloadParams)
38
44
  action = "download" if isinstance(params, DownloadParams) else "flash"
39
- if not config.interactive:
40
- # no interactivity allowed
41
- return params
42
45
 
43
46
  questions = []
44
47
  answers: dict[str, Union[str, List]] = {"action": action}
@@ -67,8 +70,14 @@ def ask_missing_params(
67
70
  answers["serial"] = [answers["serial"]]
68
71
  params.serial = [s.split()[0] for s in answers["serial"]] # split to remove the description
69
72
  if "port" in answers:
70
- params.ports = [p for p in params.ports if p != "?"] # remove the "?" if present
71
- params.ports.extend(answers["port"])
73
+ # params.ports = [p for p in params.ports if p != "?"] # remove the "?" if present
74
+ if isinstance(answers["port"], str):
75
+ params.ports.append(answers["port"])
76
+ elif isinstance(answers["port"], list): # type: ignore
77
+ params.ports.extend(answers["port"])
78
+ else:
79
+ raise ValueError(f"Unexpected type for answers['port']: {type(answers['port'])}")
80
+
72
81
  if "boards" in answers:
73
82
  params.boards = [b for b in params.boards if b != "?"] # remove the "?" if present
74
83
  params.boards.extend(answers["boards"] if isinstance(answers["boards"], list) else [answers["boards"]])
@@ -152,10 +161,18 @@ def ask_port_board(*, multi_select: bool, action: str):
152
161
  "Which {port} board firmware do you want to {action} " + "to {serial} ?" if action == "flash" else "?"
153
162
  ),
154
163
  choices=filter_matching_boards,
155
- validate=lambda _, x: True if x else "Please select at least one board", # type: ignore
164
+ validate=at_least_one_validation, # type: ignore
165
+ # validate=lambda _, x: True if x else "Please select at least one board", # type: ignore
156
166
  ),
157
167
  ]
158
168
 
169
+ def at_least_one_validation(answers, current) -> bool:
170
+ import inquirer.errors
171
+ if not current:
172
+ raise inquirer.errors.ValidationError("", reason="Please select at least one item.")
173
+ if isinstance(current, list) and not any(current):
174
+ raise inquirer.errors.ValidationError("", reason="Please select at least one item.")
175
+ return True
159
176
 
160
177
  def ask_mp_version(multi_select: bool, action: str):
161
178
  """
@@ -181,13 +198,6 @@ def ask_mp_version(multi_select: bool, action: str):
181
198
  # todo: this may be a little slow
182
199
  mp_versions = [v for v in mp_versions if "preview" in v or get_known_boards_for_port("stm32", [v])]
183
200
 
184
- def at_least_one_validation(answers, current) -> bool:
185
- if not current:
186
- raise inquirer.errors.ValidationError("", reason="Please select at least one version")
187
- if isinstance(current, list) and not any(current):
188
- raise inquirer.errors.ValidationError("", reason="Please select at least one version")
189
- return True
190
-
191
201
  message = "Which version(s) do you want to {action} " + ("to {serial} ?" if action == "flash" else "?")
192
202
  q = input_ux(
193
203
  # inquirer.List(
@@ -32,5 +32,6 @@ def enter_bootloader(
32
32
  raise MPFlashError(f"Unknown bootloader method {method}")
33
33
  if result:
34
34
  time.sleep(wait_after)
35
- log.error(f"Failed to enter bootloader on {mcu.serialport}")
35
+ else:
36
+ log.error(f"Failed to enter bootloader on {mcu.serialport}")
36
37
  return result
mpflash/cli_flash.py CHANGED
@@ -17,7 +17,8 @@ from .cli_list import show_mcus
17
17
  from .common import FlashParams
18
18
  from .config import config
19
19
  from .flash import flash_list
20
- from .worklist import WorkList, full_auto_worklist, manual_worklist, single_auto_worklist
20
+ from .worklist import (WorkList, full_auto_worklist, manual_worklist,
21
+ single_auto_worklist)
21
22
 
22
23
  # #########################################################################################################
23
24
  # CLI
@@ -120,7 +121,8 @@ def cli_flash_board(**kwargs) -> int:
120
121
 
121
122
  params = FlashParams(**kwargs)
122
123
  params.versions = list(params.versions)
123
- params.boards = list(params.boards)
124
+ params.ports = list(params.ports)
125
+ params.boards = list(params.boards)
124
126
  params.serial = list(params.serial)
125
127
  params.ignore = list(params.ignore)
126
128
  params.bootloader = BootloaderMethod(params.bootloader)
mpflash/cli_group.py CHANGED
@@ -14,6 +14,7 @@ from .logger import log, make_quiet, set_loglevel
14
14
  def cb_verbose(ctx, param, value):
15
15
  """Callback to set the log level to DEBUG if verbose is set"""
16
16
  if value and not config.quiet:
17
+ # log.debug(f"Setting verbose mode to {value}")
17
18
  config.verbose = True
18
19
  if value > 1:
19
20
  set_loglevel("TRACE")
@@ -26,19 +27,21 @@ def cb_verbose(ctx, param, value):
26
27
  return value
27
28
 
28
29
 
29
- def cb_interactive(ctx, param, value):
30
- if value:
31
- config.interactive = value
30
+ def cb_interactive(ctx, param, value:bool):
31
+ log.trace(f"Setting interactive mode to {value}")
32
+ config.interactive = value
32
33
  return value
33
34
 
34
35
 
35
36
  def cb_test(ctx, param, value):
36
37
  if value:
38
+ log.trace(f"Setting tests to {value}")
37
39
  config.tests = value
38
40
  return value
39
41
 
40
42
 
41
43
  def cb_quiet(ctx, param, value):
44
+ log.trace(f"Setting quiet mode to {value}")
42
45
  if value:
43
46
  make_quiet()
44
47
  return value
mpflash/config.py CHANGED
@@ -1,11 +1,14 @@
1
1
  """centralized configuration for mpflash"""
2
2
 
3
+ import os
3
4
  from pathlib import Path
4
5
  from typing import List
5
6
 
6
7
  import pkg_resources
7
8
  import platformdirs
8
9
 
10
+ from mpflash.logger import log
11
+
9
12
 
10
13
  def get_version():
11
14
  name = __package__ or "mpflash"
@@ -21,10 +24,23 @@ class MPtoolConfig:
21
24
  quiet: bool = False
22
25
  verbose: bool = False
23
26
  ignore_ports: List[str] = []
24
- interactive: bool = True
25
27
  firmware_folder: Path = platformdirs.user_downloads_path() / "firmware"
26
28
  # test options specified on the commandline
27
29
  tests: List[str] = []
30
+ _interactive: bool = True
31
+
32
+ @property
33
+ def interactive(self):
34
+ # No interactions in CI
35
+ if os.getenv('GITHUB_ACTIONS') == 'true':
36
+ log.warning("Disabling interactive mode in CI")
37
+ return False
38
+ return self._interactive
39
+
40
+ @interactive.setter
41
+ def interactive(self, value:bool):
42
+ self._interactive = value
43
+
28
44
 
29
45
 
30
46
  config = MPtoolConfig()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mpflash
3
- Version: 0.8.4
3
+ Version: 0.8.6
4
4
  Summary: Flash and download tool for MicroPython firmwares
5
5
  Home-page: https://github.com/Josverl/micropython-stubber/blob/main/src/mpflash/README.md
6
6
  License: MIT
@@ -1,17 +1,17 @@
1
1
  mpflash/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  mpflash/add_firmware.py,sha256=u_g9mID557fptLEJ1Nld9n27V1R1og8uEkadm0O3YTw,3435
3
- mpflash/ask_input.py,sha256=e54WfgktG7Ff8dBUknXioROq3lPNZ-eacUjfmUvFfS0,8496
4
- mpflash/bootloader/__init__.py,sha256=NRi_zWLNhstoUeisXlknrNyrCcEaHrzEkTxnrmUg1m0,1304
3
+ mpflash/ask_input.py,sha256=ipkRIMb_kl4j9o8f_LtpX8jL8dZnTeGiTvE87fA8LBw,8953
4
+ mpflash/bootloader/__init__.py,sha256=ikSmoovdenmOqBsmI99pjsYLRi-DghbQ3-DlbiCy4Rg,1319
5
5
  mpflash/bootloader/manual.py,sha256=4FNQg0JpyRmfISrDDfZ5j9iQBK-Jyrnz8nLqKf1ZEuc,3104
6
6
  mpflash/bootloader/micropython.py,sha256=QQJlXUnyVA4cRS2O4GbrQhpKhFFvxtQC5G6WQcSCbp8,409
7
7
  mpflash/bootloader/touch1200.py,sha256=AJ4GPLtvCR5LDDe5Uu_5Rg8OI2JHxEB-blzCcO5x9Tc,1511
8
8
  mpflash/cli_download.py,sha256=zufBC0xNPZCq28mG_fepupziizbm86wTpfNEszkei9Q,3656
9
- mpflash/cli_flash.py,sha256=ITd9eJzvdtr6SeeB3PO5Ja2jG4TFxsW7JfL3pCNJBn0,7288
10
- mpflash/cli_group.py,sha256=gvUaQM-4wk6fV50YxkMJeYEt3D0ZsQJM7t86T8xOpWE,2139
9
+ mpflash/cli_flash.py,sha256=KOn1T9lThFs5pkhWZY_QCEdyB66xk6eJjS3n995hwPk,7354
10
+ mpflash/cli_group.py,sha256=MsySUNipL8xkQAu4yuQPkFLoZNtQ5RPWtX3diHHrPdE,2334
11
11
  mpflash/cli_list.py,sha256=_3XzR8RyjlojbOqGKm_TLwcQojCb4OgCYi7mcjjoflI,2046
12
12
  mpflash/cli_main.py,sha256=MHhU1cAYEhwOpHG2p3OEfwpSrn9-J2foGVZqby_HO8k,1134
13
13
  mpflash/common.py,sha256=gkj71hGibMEcmThJ5LSrAV5vp6SpJAJNLHWO4GjB040,5929
14
- mpflash/config.py,sha256=R7PomStIFHSTnLhpWhw9P2DL_b-8a8Wrja3aY-dPm6A,762
14
+ mpflash/config.py,sha256=VqaS6dT1UFigVmYRtVVBTi7cNQ6UKReaN4VUj3D5Ip4,1166
15
15
  mpflash/connected.py,sha256=CBG_DJ33OPWAPbX-ICQpL1LcFOhNYpLUSB0Q5v7gi9s,3029
16
16
  mpflash/download.py,sha256=VFV0XP8mTnBXOeo_JbyHBjIQJ0PUUiXu8hoO0lAxid8,14235
17
17
  mpflash/downloaded.py,sha256=cHq_fWUuZ0sXOCs5d3NIf3etUDsAXtnwnO7tkRqJE9A,4870
@@ -45,8 +45,8 @@ mpflash/vendor/pydfu.py,sha256=_MdBRo1EeNeKDqFPSTB5tNL1jGSBJgsVeVjE5e7Pb8s,20542
45
45
  mpflash/vendor/readme.md,sha256=iIIZxuLUIGHQ0KODzYVtMezsztvyxCXcNJp_AzwTIPk,86
46
46
  mpflash/vendor/versions.py,sha256=thk1a5wEEhXIQoL0zZ7oooeFyQeSoI00CIUbZF0b3rI,3783
47
47
  mpflash/worklist.py,sha256=MKHDynttVP3lsHSfb7DEqeQ2mRV0da96lD4lIcS_zQY,5962
48
- mpflash-0.8.4.dist-info/entry_points.txt,sha256=Jk_visOhYOsZIcSP2Ms9hKqfKy1iorR-6dYltSoWCpY,52
49
- mpflash-0.8.4.dist-info/LICENSE,sha256=mWpNhsIxWzetYNnTpr4eb3HtgsxGIC8KcYWxXEcxQvE,1077
50
- mpflash-0.8.4.dist-info/METADATA,sha256=wjudSFDz_BU3eYbqjjnxd68dCHfzaZpnR37MD2UCh9s,15275
51
- mpflash-0.8.4.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
52
- mpflash-0.8.4.dist-info/RECORD,,
48
+ mpflash-0.8.6.dist-info/entry_points.txt,sha256=Jk_visOhYOsZIcSP2Ms9hKqfKy1iorR-6dYltSoWCpY,52
49
+ mpflash-0.8.6.dist-info/LICENSE,sha256=mWpNhsIxWzetYNnTpr4eb3HtgsxGIC8KcYWxXEcxQvE,1077
50
+ mpflash-0.8.6.dist-info/METADATA,sha256=uahnuzKIjIEmZush0O6RZDbW_qzbLlUBHq_ZRU3WT7A,15275
51
+ mpflash-0.8.6.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
52
+ mpflash-0.8.6.dist-info/RECORD,,