Skip to content

Commit

Permalink
Refactor: Simplify code in breeze (#33273)
Browse files Browse the repository at this point in the history
* Refactor: Simplify code in breeze

---------

Co-authored-by: Tzu-ping Chung <[email protected]>
  • Loading branch information
eumiro and uranusjr authored Aug 10, 2023
1 parent 01a6c1e commit 7c950a8
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
2 changes: 1 addition & 1 deletion dev/breeze/src/airflow_breeze/commands/setup_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
3 changes: 1 addition & 2 deletions dev/breeze/src/airflow_breeze/commands/testing_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
5 changes: 1 addition & 4 deletions dev/breeze/src/airflow_breeze/utils/run_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 5 additions & 7 deletions dev/breeze/src/airflow_breeze/utils/selective_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 7c950a8

Please sign in to comment.