forked from platformio/platformio-core
		
	Introduce Black to automate code formatting
This commit is contained in:
		| @@ -25,35 +25,35 @@ from platformio import exception, fs, proc, util | ||||
| from platformio.commands.debug import helpers | ||||
| from platformio.managers.core import inject_contrib_pysite | ||||
| from platformio.project.config import ProjectConfig | ||||
| from platformio.project.helpers import (is_platformio_project, | ||||
|                                         load_project_ide_data) | ||||
| from platformio.project.helpers import is_platformio_project, load_project_ide_data | ||||
|  | ||||
|  | ||||
| @click.command("debug", | ||||
|                context_settings=dict(ignore_unknown_options=True), | ||||
|                short_help="PIO Unified Debugger") | ||||
| @click.option("-d", | ||||
|               "--project-dir", | ||||
|               default=os.getcwd, | ||||
|               type=click.Path(exists=True, | ||||
|                               file_okay=False, | ||||
|                               dir_okay=True, | ||||
|                               writable=True, | ||||
|                               resolve_path=True)) | ||||
| @click.option("-c", | ||||
|               "--project-conf", | ||||
|               type=click.Path(exists=True, | ||||
|                               file_okay=True, | ||||
|                               dir_okay=False, | ||||
|                               readable=True, | ||||
|                               resolve_path=True)) | ||||
| @click.command( | ||||
|     "debug", | ||||
|     context_settings=dict(ignore_unknown_options=True), | ||||
|     short_help="PIO Unified Debugger", | ||||
| ) | ||||
| @click.option( | ||||
|     "-d", | ||||
|     "--project-dir", | ||||
|     default=os.getcwd, | ||||
|     type=click.Path( | ||||
|         exists=True, file_okay=False, dir_okay=True, writable=True, resolve_path=True | ||||
|     ), | ||||
| ) | ||||
| @click.option( | ||||
|     "-c", | ||||
|     "--project-conf", | ||||
|     type=click.Path( | ||||
|         exists=True, file_okay=True, dir_okay=False, readable=True, resolve_path=True | ||||
|     ), | ||||
| ) | ||||
| @click.option("--environment", "-e", metavar="<environment>") | ||||
| @click.option("--verbose", "-v", is_flag=True) | ||||
| @click.option("--interface", type=click.Choice(["gdb"])) | ||||
| @click.argument("__unprocessed", nargs=-1, type=click.UNPROCESSED) | ||||
| @click.pass_context | ||||
| def cli(ctx, project_dir, project_conf, environment, verbose, interface, | ||||
|         __unprocessed): | ||||
| def cli(ctx, project_dir, project_conf, environment, verbose, interface, __unprocessed): | ||||
|     # use env variables from Eclipse or CLion | ||||
|     for sysenv in ("CWD", "PWD", "PLATFORMIO_PROJECT_DIR"): | ||||
|         if is_platformio_project(project_dir): | ||||
| @@ -63,7 +63,8 @@ def cli(ctx, project_dir, project_conf, environment, verbose, interface, | ||||
|  | ||||
|     with fs.cd(project_dir): | ||||
|         config = ProjectConfig.get_instance( | ||||
|             project_conf or join(project_dir, "platformio.ini")) | ||||
|             project_conf or join(project_dir, "platformio.ini") | ||||
|         ) | ||||
|         config.validate(envs=[environment] if environment else None) | ||||
|  | ||||
|         env_name = environment or helpers.get_default_debug_env(config) | ||||
| @@ -74,68 +75,64 @@ def cli(ctx, project_dir, project_conf, environment, verbose, interface, | ||||
|         assert debug_options | ||||
|  | ||||
|     if not interface: | ||||
|         return helpers.predebug_project(ctx, project_dir, env_name, False, | ||||
|                                         verbose) | ||||
|         return helpers.predebug_project(ctx, project_dir, env_name, False, verbose) | ||||
|  | ||||
|     configuration = load_project_ide_data(project_dir, env_name) | ||||
|     if not configuration: | ||||
|         raise exception.DebugInvalidOptions( | ||||
|             "Could not load debug configuration") | ||||
|         raise exception.DebugInvalidOptions("Could not load debug configuration") | ||||
|  | ||||
|     if "--version" in __unprocessed: | ||||
|         result = proc.exec_command([configuration['gdb_path'], "--version"]) | ||||
|         if result['returncode'] == 0: | ||||
|             return click.echo(result['out']) | ||||
|         raise exception.PlatformioException("\n".join( | ||||
|             [result['out'], result['err']])) | ||||
|         result = proc.exec_command([configuration["gdb_path"], "--version"]) | ||||
|         if result["returncode"] == 0: | ||||
|             return click.echo(result["out"]) | ||||
|         raise exception.PlatformioException("\n".join([result["out"], result["err"]])) | ||||
|  | ||||
|     try: | ||||
|         fs.ensure_udev_rules() | ||||
|     except exception.InvalidUdevRules as e: | ||||
|         for line in str(e).split("\n") + [""]: | ||||
|             click.echo( | ||||
|                 ('~"%s\\n"' if helpers.is_mi_mode(__unprocessed) else "%s") % | ||||
|                 line) | ||||
|                 ('~"%s\\n"' if helpers.is_mi_mode(__unprocessed) else "%s") % line | ||||
|             ) | ||||
|  | ||||
|     debug_options['load_cmds'] = helpers.configure_esp32_load_cmds( | ||||
|         debug_options, configuration) | ||||
|     debug_options["load_cmds"] = helpers.configure_esp32_load_cmds( | ||||
|         debug_options, configuration | ||||
|     ) | ||||
|  | ||||
|     rebuild_prog = False | ||||
|     preload = debug_options['load_cmds'] == ["preload"] | ||||
|     load_mode = debug_options['load_mode'] | ||||
|     preload = debug_options["load_cmds"] == ["preload"] | ||||
|     load_mode = debug_options["load_mode"] | ||||
|     if load_mode == "always": | ||||
|         rebuild_prog = ( | ||||
|             preload | ||||
|             or not helpers.has_debug_symbols(configuration['prog_path'])) | ||||
|         rebuild_prog = preload or not helpers.has_debug_symbols( | ||||
|             configuration["prog_path"] | ||||
|         ) | ||||
|     elif load_mode == "modified": | ||||
|         rebuild_prog = ( | ||||
|             helpers.is_prog_obsolete(configuration['prog_path']) | ||||
|             or not helpers.has_debug_symbols(configuration['prog_path'])) | ||||
|         rebuild_prog = helpers.is_prog_obsolete( | ||||
|             configuration["prog_path"] | ||||
|         ) or not helpers.has_debug_symbols(configuration["prog_path"]) | ||||
|     else: | ||||
|         rebuild_prog = not isfile(configuration['prog_path']) | ||||
|         rebuild_prog = not isfile(configuration["prog_path"]) | ||||
|  | ||||
|     if preload or (not rebuild_prog and load_mode != "always"): | ||||
|         # don't load firmware through debug server | ||||
|         debug_options['load_cmds'] = [] | ||||
|         debug_options["load_cmds"] = [] | ||||
|  | ||||
|     if rebuild_prog: | ||||
|         if helpers.is_mi_mode(__unprocessed): | ||||
|             click.echo('~"Preparing firmware for debugging...\\n"') | ||||
|             output = helpers.GDBBytesIO() | ||||
|             with util.capture_std_streams(output): | ||||
|                 helpers.predebug_project(ctx, project_dir, env_name, preload, | ||||
|                                          verbose) | ||||
|                 helpers.predebug_project(ctx, project_dir, env_name, preload, verbose) | ||||
|             output.close() | ||||
|         else: | ||||
|             click.echo("Preparing firmware for debugging...") | ||||
|             helpers.predebug_project(ctx, project_dir, env_name, preload, | ||||
|                                      verbose) | ||||
|             helpers.predebug_project(ctx, project_dir, env_name, preload, verbose) | ||||
|  | ||||
|         # save SHA sum of newly created prog | ||||
|         if load_mode == "modified": | ||||
|             helpers.is_prog_obsolete(configuration['prog_path']) | ||||
|             helpers.is_prog_obsolete(configuration["prog_path"]) | ||||
|  | ||||
|     if not isfile(configuration['prog_path']): | ||||
|     if not isfile(configuration["prog_path"]): | ||||
|         raise exception.DebugInvalidOptions("Program/firmware is missed") | ||||
|  | ||||
|     # run debugging client | ||||
| @@ -143,7 +140,7 @@ def cli(ctx, project_dir, project_conf, environment, verbose, interface, | ||||
|     from platformio.commands.debug.client import GDBClient, reactor | ||||
|  | ||||
|     client = GDBClient(project_dir, __unprocessed, debug_options, env_options) | ||||
|     client.spawn(configuration['gdb_path'], configuration['prog_path']) | ||||
|     client.spawn(configuration["gdb_path"], configuration["prog_path"]) | ||||
|  | ||||
|     signal.signal(signal.SIGINT, lambda *args, **kwargs: None) | ||||
|     reactor.run() | ||||
|   | ||||
		Reference in New Issue
	
	Block a user