From ee38a56e5325566ac813259c5b2fa01c0209ffcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= <6774676+eumiro@users.noreply.github.com> Date: Thu, 10 Aug 2023 10:45:46 +0000 Subject: [PATCH] Refactor: Simplify code in breeze (#33273) * Refactor: Simplify code in breeze --------- Co-authored-by: Tzu-ping Chung --- .../commands/release_management_commands.py | 15 +++++++++------ .../src/airflow_breeze/commands/setup_commands.py | 2 +- .../airflow_breeze/commands/testing_commands.py | 3 +-- dev/breeze/src/airflow_breeze/utils/run_utils.py | 5 +---- .../src/airflow_breeze/utils/selective_checks.py | 12 +++++------- 5 files changed, 17 insertions(+), 20 deletions(-) diff --git a/dev/breeze/src/airflow_breeze/commands/release_management_commands.py b/dev/breeze/src/airflow_breeze/commands/release_management_commands.py index 7ba67c7943b3c..925ce2bd5fc03 100644 --- a/dev/breeze/src/airflow_breeze/commands/release_management_commands.py +++ b/dev/breeze/src/airflow_breeze/commands/release_management_commands.py @@ -1029,12 +1029,15 @@ def release_prod_images( def is_package_in_dist(dist_files: list[str], package: str) -> bool: """Check if package has been prepared in dist folder.""" - for file in dist_files: - if file.startswith(f'apache_airflow_providers_{package.replace(".", "_")}') or file.startswith( - f'apache-airflow-providers-{package.replace(".", "-")}' - ): - return True - return False + return any( + file.startswith( + ( + f'apache_airflow_providers_{package.replace(".", "_")}', + f'apache-airflow-providers-{package.replace(".", "-")}', + ) + ) + for file in dist_files + ) def get_prs_for_package(package_id: str) -> list[int]: diff --git a/dev/breeze/src/airflow_breeze/commands/setup_commands.py b/dev/breeze/src/airflow_breeze/commands/setup_commands.py index 9d6c558449d23..2668b1c319281 100644 --- a/dev/breeze/src/airflow_breeze/commands/setup_commands.py +++ b/dev/breeze/src/airflow_breeze/commands/setup_commands.py @@ -410,7 +410,7 @@ def get_command_hash_dict(hash_file_content: str) -> dict[str, str]: results = {} for line in hash_file_content.splitlines(): strip_line = line.strip() - if strip_line.strip() == "" or strip_line.startswith("#"): + if not strip_line or strip_line.startswith("#"): continue command = ":".join(strip_line.split(":")[:-1]) the_hash = strip_line.split(":")[-1] diff --git a/dev/breeze/src/airflow_breeze/commands/testing_commands.py b/dev/breeze/src/airflow_breeze/commands/testing_commands.py index d892727ee48dc..68e3c688c63a3 100644 --- a/dev/breeze/src/airflow_breeze/commands/testing_commands.py +++ b/dev/breeze/src/airflow_breeze/commands/testing_commands.py @@ -587,7 +587,6 @@ def helm_tests( env_variables["HELM_TEST_PACKAGE"] = helm_test_package perform_environment_checks() cleanup_python_generated_files() - cmd = [*DOCKER_COMPOSE_COMMAND, "run", "--service-ports", "--rm", "airflow"] - cmd.extend(list(extra_pytest_args)) + cmd = [*DOCKER_COMPOSE_COMMAND, "run", "--service-ports", "--rm", "airflow", *extra_pytest_args] result = run_command(cmd, env=env_variables, check=False, output_outside_the_group=True) sys.exit(result.returncode) diff --git a/dev/breeze/src/airflow_breeze/utils/run_utils.py b/dev/breeze/src/airflow_breeze/utils/run_utils.py index 133e512347e44..5f059bad6707f 100644 --- a/dev/breeze/src/airflow_breeze/utils/run_utils.py +++ b/dev/breeze/src/airflow_breeze/utils/run_utils.py @@ -361,10 +361,7 @@ def commit_sha(): def filter_out_none(**kwargs) -> dict: """Filters out all None values from parameters passed.""" - for key in list(kwargs): - if kwargs[key] is None: - kwargs.pop(key) - return kwargs + return {key: val for key, val in kwargs.items() if val is not None} def check_if_image_exists(image: str) -> bool: diff --git a/dev/breeze/src/airflow_breeze/utils/selective_checks.py b/dev/breeze/src/airflow_breeze/utils/selective_checks.py index 7dfbabf8b7149..846b0ead808d9 100644 --- a/dev/breeze/src/airflow_breeze/utils/selective_checks.py +++ b/dev/breeze/src/airflow_breeze/utils/selective_checks.py @@ -620,7 +620,7 @@ def _get_test_types_to_run(self) -> list[str]: get_console().print( "[warning]There are no core/other files. Only tests relevant to the changed files are run.[/]" ) - sorted_candidate_test_types = list(sorted(candidate_test_types)) + sorted_candidate_test_types = sorted(candidate_test_types) get_console().print("[warning]Selected test type candidates to run:[/]") get_console().print(sorted_candidate_test_types) return sorted_candidate_test_types @@ -722,15 +722,13 @@ def docs_filter_list_as_string(self) -> str | None: ): return _ALL_DOCS_LIST packages = [] - if any( - [file.startswith("airflow/") or file.startswith("docs/apache-airflow/") for file in self._files] - ): + if any(file.startswith(("airflow/", "docs/apache-airflow/")) for file in self._files): packages.append("apache-airflow") - if any([file.startswith("docs/apache-airflow-providers/") for file in self._files]): + if any(file.startswith("docs/apache-airflow-providers/") for file in self._files): packages.append("apache-airflow-providers") - if any([file.startswith("chart/") or file.startswith("docs/helm-chart") for file in self._files]): + if any(file.startswith(("chart/", "docs/helm-chart")) for file in self._files): packages.append("helm-chart") - if any([file.startswith("docs/docker-stack/") for file in self._files]): + if any(file.startswith("docs/docker-stack/") for file in self._files): packages.append("docker-stack") if providers_affected: for provider in providers_affected: