8000 tools/mpremote: Remove non-existent COM0. · micropython/micropython@c2771df · GitHub
[go: up one dir, main page]

Skip to content

Commit c2771df

Browse files
committed
tools/mpremote: Remove non-existent COM0.
Signed-off-by: Jos Verlinde <jos_verlinde@hotmail.com>
1 parent 6db5a2c commit c2771df

File tree

1 file changed

+20
-36
lines changed

1 file changed

+20
-36
lines changed

tools/mpremote/mpremote/main.py

Lines changed: 20 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ 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(
65-
_COMMANDS, lambda x: x[1]().description
66-
) # extract description from argparse
64+
print_commands_help(_COMMANDS, lambda x: x[1]().description) # extract description from argparse
6765

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

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

105101

@@ -137,9 +133,7 @@ def argparse_repl():
137133
required=False,
138134
help="saves a copy of the REPL session to the specified path",
139135
)
140-
cmd_parser.add_argument(
141-
"--inject-code", type=str, required=False, help="code to be run when Ctrl-J is pressed"
142-
)
136+
cmd_parser.add_argument("--inject-code", type=str, required=False, help="code to be run when Ctrl-J is pressed")
143137
cmd_parser.add_argument(
144138
"--inject-file",
145139
type=str,
@@ -157,18 +151,14 @@ def argparse_eval():
157151

158152
def argparse_exec():
159153
cmd_parser = argparse.ArgumentParser(description="execute the string")
160-
_bool_flag(
161-
cmd_parser, "follow", "f", True, "follow output until the expression completes (default)"
162-
)
154+
_bool_flag(cmd_parser, "follow", "f", True, "follow output until the expression completes (default)")
163155
cmd_parser.add_argument("expr", nargs=1, help="expression to execute")
164156
return cmd_parser
165157

166158

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

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

198186

199187
def argparse_mip():
200-
cmd_parser = argparse.ArgumentParser(
201-
description="install packages from micropython-lib or third-party sources"
202-
)
188+
cmd_parser = argparse.ArgumentParser(description="install packages from micropython-lib or third-party sources")
203189
_bool_flag(cmd_parser, "mpy", "m", True, "download as compiled .mpy files (default)")
204-
cmd_parser.add_argument(
205-
"--target", type=str, required=False, help="destination direction on the device"
206-
)
190+
cmd_parser.add_argument("--target", type=str, required=False, help="destination direction on the device")
207191
cmd_parser.add_argument(
208192
"--index",
209193
type=str,
@@ -341,13 +325,15 @@ def argparse_none(description):
341325
"--version": "version",
342326
}
343327

344-
# Add "a0", "a1", ..., "u0", "u1", ..., "c0", "c1", ... as aliases
328+
# Add "a0", "a1", ..., "u0", "u1", ..., "c1", "c2", ... as aliases
345329
# for "connect /dev/ttyACMn" (and /dev/ttyUSBn, COMn) etc.
346330
for port_num in range(4):
347331
for prefix, port in [("a", "/dev/ttyACM"), ("u", "/dev/ttyUSB"), ("c", "COM")]:
348-
_BUILTIN_COMMAND_EXPANSIONS["{}{}".format(prefix, port_num)] = {
349-
"command": "connect {}{}".format(port, port_num),
350-
"help": 'connect to serial port "{}{}"'.format(port, port_num),
332+
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}"',
351337
}
352338

353339

@@ -361,16 +347,17 @@ def load_user_config():
361347
path = os.getenv(env_var)
362348
if not path:
363349
continue
364-
if os.path.exists( os.path.join(path,".config", _PROG, "config.py")):
350+
if os.path.exists(os.path.join(path, ".config", _PROG, "config.py")):
365351
# Unix style
366-
path = os.path.join(path,".config", _PROG, "config.py")
352+
path = os.path.join(path, ".config", _PROG, "config.py")
367353
break
368-
elif os.path.exists( os.path.join(path, _PROG, "config.py")):
354+
elif os.path.exists(os.path.join(path, _PROG, "config.py")):
369355
# Windows style
370-
path = os.path.join(path, _PROG,"config.py")
356+
path = os.path.join(path, _PROG, "config.py")
371357
break
372358
if not path:
373359
return config
360+
374361
config_file = os.path.join(path, "config.py")
375362
# Check if config file exists.
376363
if not os.path.exists(config_file):
@@ -386,7 +373,6 @@ def load_user_config():
386373
config.__dict__["__file__"] = config_file
387374
exec(config_data, config.__dict__)
388375
os.chdir(prev_cwd)
389-
390376
return config
391377

392378

@@ -528,9 +514,7 @@ def main():
528514
cmd_parser = parser_func()
529515
cmd_parser.prog = cmd
530516
# Catch all for unhandled positional arguments (this is the next command).
531-
cmd_parser.add_argument(
532-
"next_command", nargs=argparse.REMAINDER, help=f"Next {_PROG} command"
533-
)
517+
cmd_parser.add_argument("next_command", nargs=argparse.REMAINDER, help=f"Next {_PROG} command")
534518
args = cmd_parser.parse_args(command_args)
535519

536520
# Execute command.

0 commit comments

Comments
 (0)
0