From 6935fbcd066a925c525a577efd81ac9f15d0b12b Mon Sep 17 00:00:00 2001 From: Prajjwal Nijhara Date: Sat, 2 May 2020 06:17:33 +0530 Subject: [PATCH] Fix some code quality issues --- .deepsource.toml | 10 ++++++++++ applications/cli/commands/experiment/common.py | 2 +- applications/cli/commands/experiment/view.py | 12 ++++-------- applications/cli/commands/launch/launch.py | 4 ++-- .../cli/commands/launch/tests/test_launch.py | 2 +- applications/nauta-docs/app/tools/generate_index.py | 4 ++-- 6 files changed, 20 insertions(+), 14 deletions(-) create mode 100644 .deepsource.toml diff --git a/.deepsource.toml b/.deepsource.toml new file mode 100644 index 000000000..3ea082b21 --- /dev/null +++ b/.deepsource.toml @@ -0,0 +1,10 @@ +version = 1 + +test_patterns = ["*/tests/**"] + +[[analyzers]] +name = "python" +enabled = true + + [analyzers.meta] + runtime_version = "3.x.x" diff --git a/applications/cli/commands/experiment/common.py b/applications/cli/commands/experiment/common.py index 6fae4d58e..5f5f5b1a7 100644 --- a/applications/cli/commands/experiment/common.py +++ b/applications/cli/commands/experiment/common.py @@ -716,7 +716,7 @@ def analyze_ps_parameters_list(list_of_params: Tuple[str, ...]): try: param_values = str.strip(param_set, "{}") param_values_list = [l.strip() for l in param_values.split(",")] - param_tuple = tuple([l.replace(":", "=", 1) for l in param_values_list]) + param_tuple = tuple(l.replace(":", "=", 1) for l in param_values_list) ret_list.append(param_tuple) except Exception as e: log.exception(error_message) diff --git a/applications/cli/commands/experiment/view.py b/applications/cli/commands/experiment/view.py index 1af1a641f..efe0e7e73 100644 --- a/applications/cli/commands/experiment/view.py +++ b/applications/cli/commands/experiment/view.py @@ -326,17 +326,13 @@ def view(ctx: click.Context, experiment_name: str, tensorboard: bool, click.echo() top_cpu_users, top_mem_users = get_highest_usage() click.echo( - Texts.TOP_CPU_CONSUMERS.format(consumers=", ".join([ - res.user_name + Texts.TOP_CPU_CONSUMERS.format(consumers=", ".join(res.user_name for res in top_cpu_users[0:3 if len(top_cpu_users) > 2 - else len(top_cpu_users)] - ]))) + else len(top_cpu_users)]))) click.echo( - Texts.TOP_MEMORY_CONSUMERS.format(consumers=", ".join([ - res.user_name + Texts.TOP_MEMORY_CONSUMERS.format(consumers=", ".join(res.user_name for res in top_mem_users[0:3 if len(top_mem_users) > 2 - else len(top_mem_users)] - ]))) + else len(top_mem_users)]))) except Exception: click.echo(Texts.PROBLEMS_WHILE_GATHERING_USAGE_DATA) logger.exception( diff --git a/applications/cli/commands/launch/launch.py b/applications/cli/commands/launch/launch.py index dfafe57bd..5f647f14e 100644 --- a/applications/cli/commands/launch/launch.py +++ b/applications/cli/commands/launch/launch.py @@ -82,8 +82,8 @@ def tensorboard(ctx: click.Context, no_launch: bool, tensorboard_service_client_ try: tb = tensorboard_service_client.create_tensorboard(requested_runs) if tb.invalid_runs: - list_of_invalid_runs = ', '.join([f'{item.get("owner")}/{item.get("name")}' - for item in tb.invalid_runs]) + list_of_invalid_runs = ', '.join(f'{item.get("owner")}/{item.get("name")}' + for item in tb.invalid_runs) click.echo(Texts.TB_INVALID_RUNS_MSG.format(invalid_runs=list_of_invalid_runs)) except Exception as exe: err_message = Texts.TB_CREATE_ERROR_MSG diff --git a/applications/cli/commands/launch/tests/test_launch.py b/applications/cli/commands/launch/tests/test_launch.py index b260303ba..753daf361 100644 --- a/applications/cli/commands/launch/tests/test_launch.py +++ b/applications/cli/commands/launch/tests/test_launch.py @@ -311,5 +311,5 @@ def test_tensorboard_command_many_experiments_some_nonexisting(mocker, launch_te assert launch.sleep.call_count == 0 assert result.exit_code == 0 assert Texts.TB_INVALID_RUNS_MSG.format( - invalid_runs=", ".join([f'{item.get("owner")}/{item.get("name")}' for item in FAKE_INVALID_RUNS]) + invalid_runs=", ".join(f'{item.get("owner")}/{item.get("name")}' for item in FAKE_INVALID_RUNS) ) in result.output diff --git a/applications/nauta-docs/app/tools/generate_index.py b/applications/nauta-docs/app/tools/generate_index.py index 5d8c41d3b..c28e0dc55 100644 --- a/applications/nauta-docs/app/tools/generate_index.py +++ b/applications/nauta-docs/app/tools/generate_index.py @@ -37,10 +37,10 @@ def add_chapters_to_menu(local_chapters, file, menu): if len(local_chapters) == 0: return local_chapters = deque(local_chapters) - while len(local_chapters): + while local_chapters: new_chapter = Chapter(remove_hash(local_chapters.popleft()), file) subchapters = list() - while len(local_chapters): + while local_chapters: if local_chapters[0].startswith("##"): subchapters.append(remove_hash(local_chapters.popleft())) else: