@@ -62,7 +62,9 @@ def print_commands_help(cmds, help_key):
62
62
print ("See https://docs.micropython.org/en/latest/reference/mpremote.html" )
63
63
64
64
print ("\n List of commands:" )
65
- print_commands_help (_COMMANDS , lambda x : x [1 ]().description ) # extract description from argparse
65
+ print_commands_help (
66
+ _COMMANDS , lambda x : x [1 ]().description
67
+ ) # extract description from argparse
66
68
67
69
print ("\n List of shortcuts:" )
68
70
print_commands_help (_command_expansions , lambda x : x [2 ]) # (args, sub, help_message)
@@ -96,7 +98,9 @@ def _bool_flag(cmd_parser, name, short_name, default, description):
96
98
97
99
def argparse_connect ():
98
100
cmd_parser = argparse .ArgumentParser (description = "connect to given device" )
99
- cmd_parser .add_argument ("device" , nargs = 1 , help = "Either list, auto, id:x, port:x, or any valid device name/path" )
101
+ cmd_parser .add_argument (
102
+ "device" , nargs = 1 , help = "Either list, auto, id:x, port:x, or any valid device name/path"
103
+ )
100
104
return cmd_parser
101
105
102
106
@@ -134,7 +138,9 @@ def argparse_repl():
134
138
required = False ,
135
139
help = "saves a copy of the REPL session to the specified path" ,
136
140
)
137
- cmd_parser .add_argument ("--inject-code" , type = str , required = False , help = "code to be run when Ctrl-J is pressed" )
141
+ cmd_parser .add_argument (
142
+ "--inject-code" , type = str , required = False , help = "code to be run when Ctrl-J is pressed"
143
+ )
138
144
cmd_parser .add_argument (
139
145
"--inject-file" ,
140
146
type = str ,
@@ -152,14 +158,18 @@ def argparse_eval():
152
158
153
159
def argparse_exec ():
154
160
cmd_parser = argparse .ArgumentParser (description = "execute the string" )
155
- _bool_flag (cmd_parser , "follow" , "f" , True , "follow output until the expression completes (default)" )
161
+ _bool_flag (
162
+ cmd_parser , "follow" , "f" , True , "follow output until the expression completes (default)"
163
+ )
156
164
cmd_parser .add_argument ("expr" , nargs = 1 , help = "expression to execute" )
157
165
return cmd_parser
158
166
159
167
160
168
def argparse_run ():
161
169
cmd_parser = argparse .ArgumentParser (description = "run the given local script" )
162
- _bool_flag (cmd_parser , "follow" , "f" , True , "follow output until the script completes (default)" )
170
+ _bool_flag (
171
+ cmd_parser , "follow" , "f" , True , "follow output until the script completes (default)"
172
+ )
163
173
cmd_parser .add_argument ("path" , nargs = 1 , help = "path to script to execute" )
164
174
return cmd_parser
165
175
@@ -197,9 +207,13 @@ def argparse_filesystem():
197
9E88
207
198
208
199
209
def argparse_mip ():
200
- cmd_parser = argparse .ArgumentParser (description = "install packages from micropython-lib or third-party sources" )
210
+ cmd_parser = argparse .ArgumentParser (
211
+ description = "install packages from micropython-lib or third-party sources"
212
+ )
201
213
_bool_flag (cmd_parser , "mpy" , "m" , True , "download as compiled .mpy files (default)" )
202
- cmd_parser .add_argument ("--target" , type = str , required = False , help = "destination direction on the device" )
214
+ cmd_parser .add_argument (
215
+ "--target" , type = str , required = False , help = "destination direction on the device"
216
+ )
203
217
cmd_parser .add_argument (
204
218
"--index" ,
205
219
type = str ,
@@ -373,36 +387,33 @@ def argparse_none(description):
373
387
for port_num in range (4 ):
374
388
for prefix , port in [("a" , "/dev/ttyACM" ), ("u" , "/dev/ttyUSB" ), ("c" , "COM" )]:
375
389
if port_num == 0 and port == "COM" :
376
- continue # skip COM0 as it does not exist
377
- _BUILTIN_COMMAND_EXPANSIONS [f" { prefix } { port_num } " ] = {
378
- "command" : f "connect { port } { port_num } " ,
379
- "help" : f 'connect to serial port "{ port } { port_num } "' ,
390
+ continue # skip COM0 as it does not exist on Windows
391
+ _BUILTIN_COMMAND_EXPANSIONS ["{}{}" . format ( prefix , port_num ) ] = {
392
+ "command" : "connect {}{}" . format ( port , port_num ) ,
393
+ "help" : 'connect to serial port "{}{ }"' . format ( port , port_num ) ,
380
394
}
381
395
382
396
383
397
def load_user_config ():
384
398
# Create empty config object.
385
399
config = __build_class__ (lambda : None , "Config" )()
386
400
config .commands = {}
387
- # use $XDG_CONFIG_HOME,$HOME $env:USERPROFILE% or $env:APPDATA
388
401
path = None
389
- for env_var in ("XDG_CONFIG_HOME" , "HOME" , "USERPROFILE " , "APPDATA " ):
402
+ for env_var in ("XDG_CONFIG_HOME" , "HOME" , "APPDATA " , "USERPROFILE " ):
390
403
path = os .getenv (env_var )
391
404
if not path :
392
405
continue
393
- if os .path .exists (os .path .join (path , ".config" , _PROG , "config.py" )):
406
+ if env_var == "HOME" and os .path .exists (os .path .join (path , ".config" , _PROG , "config.py" )):
394
407
# Unix style
395
- path = os .path .join (path , ".config" , _PROG , "config.py" )
408
+ path = os .path .join (path , ".config" , _PROG )
396
409
break
397
410
elif os .path .exists (os .path .join (path , _PROG , "config.py" )):
398
411
# Windows style
399
- path = os .path .join (path , _PROG , "config.py" )
412
+ path = os .path .join (path , _PROG )
400
413
break
401
414
if not path :
402
415
return config
403
-
404
416
config_file = os .path .join (path , "config.py" )
405
- # Check if config file exists.
406
417
if not os .path .exists (config_file ):
407
418
return config
408
419
@@ -557,7 +568,9 @@ def main():
557
568
cmd_parser = parser_func ()
558
569
cmd_parser .prog = cmd
559
570
# Catch all for unhandled positional arguments (this is the next command).
560
- cmd_parser .add_argument ("next_command" , nargs = argparse .REMAINDER , help = f"Next { _PROG } command" )
571
+ cmd_parser .add_argument (
572
+ "next_command" , nargs = argparse .REMAINDER , help = f"Next { _PROG } command"
573
+ )
561
574
args = cmd_parser .parse_args (command_args )
562
575
563
576
# Execute command.
0 commit comments