10000 tools/mpremote: Allow user configuration on Windows. · micropython/micropython@8dabeb8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8dabeb8

Browse files
committed
tools/mpremote: Allow user configuration on Windows.
Signed-off-by: Jos Verlinde <jos_verlinde@hotmail.com>
1 parent c2771df commit 8dabeb8

File tree

2 files changed

+32
-17
lines changed

2 files changed

+32
-17
lines changed

docs/reference/mpremote.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,9 +430,7 @@ Shortcuts can be defined using the macro system. Built-in shortcuts are:
430430
Additional shortcuts can be defined by in user-configuration files, which is
431431
located at ``.config/mpremote/config.py`` relative to the ``XDG_CONFIG_HOME`` or ``HOME`` environment variable on unix systems
432432
, or on Windows relative to ``HOME``, ``USERPROFILE`` or ``APPDATA``.
433-
434-
For example:
435-
This file sho 10000 uld define a dictionary named ``commands``. The keys of this dictionary are the shortcuts
433+
This file should define a dictionary named ``commands``. The keys of this dictionary are the shortcuts
436434
and the values are either a string or a list-of-strings:
437435

438436
.. code-block:: python3

tools/mpremote/mpremote/main.py

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ def print_commands_help(cmds, help_key):
6161
print("See https://docs.micropython.org/en/latest/reference/mpremote.html")
6262

6363
print("\nList of commands:")
64-
print_commands_help(_COMMANDS, lambda x: x[1]().description) # extract description from argparse
64+
print_commands_help(
65+
_COMMANDS, lambda x: x[1]().description
66+
) # extract description from argparse
6567

6668
print("\nList of shortcuts:")
6769
print_commands_help(_command_expansions, lambda x: x[2]) # (args, sub, help_message)
@@ -95,7 +97,9 @@ def _bool_flag(cmd_parser, name, short_name, default, description):
9597

9698
def argparse_connect():
9799
cmd_parser = argparse.ArgumentParser(description="connect to given device")
98-
cmd_parser.add_argument("device", nargs=1, help="Either list, auto, id:x, port:x, or any valid device name/path")
100+
cmd_parser.add_argument(
101+
"device", nargs=1, help="Either list, auto, id:x, port:x, or any valid device name/path"
102+
)
99103
return cmd_parser
100104

101105

@@ -133,7 +137,9 @@ def argparse_repl():
133137
required=False,
134138
help="saves a copy of the REPL session to the specified path",
135139
)
136-
cmd_parser.add_argument("--inject-code", type=str, required=False, help="code to be run when Ctrl-J is pressed")
140+
cmd_parser.add_argument(
141+
"--inject-code", type=str, required=False, help="code to be run when Ctrl-J is pressed"
142+
)
137143
cmd_parser.add_argument(
138144
"--inject-file",
139145
type=str,
@@ -151,14 +157,18 @@ def argparse_eval():
151157

152158
def argparse_exec():
153159
cmd_parser = argparse.ArgumentParser(description="execute the string")
154-
_bool_flag(cmd_parser, "follow", "f", True, "follow output until the expression completes (default)")
160+
_bool_flag(
161+
cmd_parser, "follow", "f", True, "follow output until the expression completes (default)"
162+
)
155163
cmd_parser.add_argument("expr", nargs=1, help="expression to execute")
156164
return cmd_parser
157165

158166

159167
def argparse_run():
160168
cmd_parser = argparse.ArgumentParser(description="run the given local script")
161-
_bool_flag(cmd_parser, "follow", "f", True, "follow output until the script completes (default)")
169+
_bool_flag(
170+
cmd_parser, "follow", "f", True, "follow output until the script completes (default)"
171+
)
162172
cmd_parser.add_argument("path", nargs=1, help="path to script to execute")
163173
return cmd_parser
164174

@@ -179,15 +189,21 @@ def argparse_filesystem():
179189
None,
180190
"enable verbose output (defaults to True for all commands except cat)",
181191
)
182-
cmd_parser.add_argument("command", nargs=1, help="filesystem command (e.g. cat, cp, ls, rm, touch)")
192+
cmd_parser.add_argument(
193+
"command", nargs=1, help="filesystem command (e.g. cat, cp, ls, rm, touch)"
194+
)
183195
cmd_parser.add_argument("path", nargs="+", help="local and remote paths")
184196
return cmd_parser
185197

186198

187199
def argparse_mip():
188-
cmd_parser = argparse.ArgumentParser(description="install packages from micropython-lib or third-party sources")
200+
cmd_parser = argparse.ArgumentParser(
201+
description="install packages from micropython-lib or third-party sources"
202+
)
189203
_bool_flag(cmd_parser, "mpy", "m", True, "download as compiled .mpy files (default)")
190-
cmd_parser.add_argument("--target", type=str, required=False, help="destination direction on the device")
204+
cmd_parser.add_argument(
205+
"--target", type=str, required=False, help="destination direction on the device"
206+
)
191207
cmd_parser.add_argument(
192208
"--index",
193209
type=str,
@@ -330,10 +346,10 @@ def argparse_none(description):
330346
for port_num in range(4):
331347
for prefix, port in [("a", "/dev/ttyACM"), ("u", "/dev/ttyUSB"), ("c", "COM")]:
332348
if port_num == 0 and port == "COM":
333-
continue # skip COM0 as it does not exist
334-
_BUILTIN_COMMAND_EXPANSIONS[f"{prefix}{port_num}"] = {
335-
"command": f"connect {port}{port_num}",
336-
"help": f'connect to serial port "{port}{port_num}"',
349+
continue # skip COM0 as it does not exist on Windows
350+
_BUILTIN_COMMAND_EXPANSIONS["{}{}".format(prefix, port_num)] = {
351+
"command": "connect {}{}".format(port, port_num),
352+
"help": 'connect to serial port "{}{}"'.format(port, port_num),
337353
}
338354

339355

@@ -357,7 +373,6 @@ def load_user_config():
357373
break
358374
if not path:
359375
return config
360-
361376
config_file = os.path.join(path, "config.py")
362377
# Check if config file exists.
363378
if not os.path.exists(config_file):
@@ -514,7 +529,9 @@ def main():
514529
cmd_parser = parser_func()
515530
cmd_parser.prog = cmd
516531
# Catch all for unhandled positional arguments (this is the next command).
517-
cmd_parser.add_argument("next_command", nargs=argparse.REMAINDER, help=f"Next {_PROG} command")
532+
cmd_parser.add_argument(
533+
"next_command", nargs=argparse.REMAINDER, help=f"Next {_PROG} command"
534+
)
518535
args = cmd_parser.parse_args(command_args)
519536

520537
# Execute command.

0 commit comments

Comments
 (0)
0