Skip to content

Commit

Permalink
Simplify conditions on len() in dev (#33562)
Browse files Browse the repository at this point in the history
  • Loading branch information
eumiro authored Aug 21, 2023
1 parent 6b624e5 commit 50abdce
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 36 deletions.
22 changes: 11 additions & 11 deletions dev/breeze/src/airflow_breeze/commands/kubernetes_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,9 +392,7 @@ def _delete_cluster(python: str, kubernetes_version: str, output: Output | None)

def _delete_all_clusters():
clusters = list(K8S_CLUSTERS_PATH.iterdir())
if len(clusters) == 0:
get_console().print("\n[warning]No clusters.\n")
else:
if clusters:
get_console().print("\n[info]Deleting clusters")
for cluster_name in clusters:
resolved_path = cluster_name.resolve()
Expand All @@ -414,6 +412,8 @@ def _delete_all_clusters():
shutil.rmtree(cluster_name.resolve(), ignore_errors=True)
else:
resolved_path.unlink()
else:
get_console().print("\n[warning]No clusters.\n")


@kubernetes_group.command(
Expand Down Expand Up @@ -515,10 +515,7 @@ def status(kubernetes_version: str, python: str, wait_time_in_seconds: int, all:
make_sure_kubernetes_tools_are_installed()
if all:
clusters = list(K8S_CLUSTERS_PATH.iterdir())
if len(clusters) == 0:
get_console().print("\n[warning]No clusters.\n")
sys.exit(1)
else:
if clusters:
failed = False
get_console().print("[info]\nCluster status:\n")
for cluster_name in clusters:
Expand All @@ -536,6 +533,9 @@ def status(kubernetes_version: str, python: str, wait_time_in_seconds: int, all:
if failed:
get_console().print("\n[error]Some clusters are not healthy!\n")
sys.exit(1)
else:
get_console().print("\n[warning]No clusters.\n")
sys.exit(1)
else:
if not _status(
python=python,
Expand Down Expand Up @@ -1233,10 +1233,7 @@ def _logs(python: str, kubernetes_version: str):
def logs(python: str, kubernetes_version: str, all: bool):
if all:
clusters = list(K8S_CLUSTERS_PATH.iterdir())
if len(clusters) == 0:
get_console().print("\n[warning]No clusters.\n")
sys.exit(1)
else:
if clusters:
get_console().print("[info]\nDumping cluster logs:\n")
for cluster_name in clusters:
name = cluster_name.name
Expand All @@ -1245,6 +1242,9 @@ def logs(python: str, kubernetes_version: str, all: bool):
get_console().print(f"[warning]\nCould not get cluster from {name}. Skipping.\n")
continue
_logs(python=found_python, kubernetes_version=found_kubernetes_version)
else:
get_console().print("\n[warning]No clusters.\n")
sys.exit(1)
else:
_logs(python=python, kubernetes_version=kubernetes_version)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ def add_back_references(
"Provide the path of cloned airflow-site repo\n"
)
sys.exit(1)
if len(packages_plus_all_providers) == 0:
if not packages_plus_all_providers:
get_console().print(
"\n[error]You need to specify at least one package to generate back references for\n"
)
Expand Down Expand Up @@ -1469,7 +1469,7 @@ def update_constraints(
get_console().print("[error]You have to provide one of --updated-constraint or --comment-file[/]")
sys.exit(1)
airflow_versions_array = airflow_versions.split(",")
if len(airflow_versions_array) == 0:
if not airflow_versions_array:
get_console().print("[error]No airflow versions specified - you provided empty string[/]")
sys.exit(1)
get_console().print(f"Updating constraints for {airflow_versions_array} with {updated_constraint}")
Expand Down
2 changes: 1 addition & 1 deletion dev/breeze/src/airflow_breeze/params/build_ci_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def extra_docker_build_flags(self) -> list[str]:
extra_ci_flags.extend(
["--build-arg", f"AIRFLOW_CONSTRAINTS_REFERENCE={self.airflow_constraints_reference}"]
)
if self.airflow_constraints_location is not None and len(self.airflow_constraints_location) > 0:
if self.airflow_constraints_location:
extra_ci_flags.extend(
["--build-arg", f"AIRFLOW_CONSTRAINTS_LOCATION={self.airflow_constraints_location}"]
)
Expand Down
4 changes: 2 additions & 2 deletions dev/breeze/src/airflow_breeze/params/build_prod_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def args_for_remote_install(self) -> list:
@property
def extra_docker_build_flags(self) -> list[str]:
extra_build_flags = []
if len(self.install_airflow_reference) > 0:
if self.install_airflow_reference:
AIRFLOW_INSTALLATION_METHOD = (
"https://github.com/apache/airflow/archive/"
+ self.install_airflow_reference
Expand All @@ -125,7 +125,7 @@ def extra_docker_build_flags(self) -> list[str]:
]
)
extra_build_flags.extend(self.args_for_remote_install)
elif len(self.install_airflow_version) > 0:
elif self.install_airflow_version:
if not re.match(r"^[0-9\.]+((a|b|rc|alpha|beta|pre)[0-9]+)?$", self.install_airflow_version):
get_console().print(
f"\n[error]ERROR: Bad value for install-airflow-version:{self.install_airflow_version}"
Expand Down
2 changes: 1 addition & 1 deletion dev/breeze/src/airflow_breeze/params/doc_build_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def args_doc_builder(self) -> list[str]:
doc_args.append("--one-pass-only")
if AIRFLOW_BRANCH != "main":
doc_args.append("--disable-provider-checks")
if self.package_filter and len(self.package_filter) > 0:
if self.package_filter:
for single_filter in self.package_filter:
doc_args.extend(["--package-filter", single_filter])
return doc_args
9 changes: 3 additions & 6 deletions dev/breeze/src/airflow_breeze/params/shell_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,8 @@ def compose_file(self) -> str:
integrations = ALL_INTEGRATIONS
else:
integrations = self.integration
if len(integrations) > 0:
for integration in integrations:
compose_file_list.append(DOCKER_COMPOSE_DIR / f"integration-{integration}.yml")
for integration in integrations:
compose_file_list.append(DOCKER_COMPOSE_DIR / f"integration-{integration}.yml")
if "trino" in integrations and "kerberos" not in integrations:
get_console().print(
"[warning]Adding `kerberos` integration as it is implicitly needed by trino",
Expand All @@ -272,9 +271,7 @@ def compose_file(self) -> str:

@property
def command_passed(self):
cmd = None
if len(self.extra_args) > 0:
cmd = str(self.extra_args[0])
cmd = str(self.extra_args[0]) if self.extra_args else None
return cmd

@property
Expand Down
2 changes: 1 addition & 1 deletion dev/breeze/src/airflow_breeze/utils/coertions.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ def coerce_bool_value(value: str | bool) -> bool:


def one_or_none_set(iterable: Iterable[bool]) -> bool:
return len([i for i in iterable if i]) in (0, 1)
return sum(1 for i in iterable if i) in (0, 1)
8 changes: 4 additions & 4 deletions dev/breeze/src/airflow_breeze/utils/docker_command_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ def prepare_arguments_for_docker_build_command(image_params: CommonBuildParams)
)
for optional_arg in image_params.optional_image_args:
param_value = get_env_variable_value(optional_arg, params=image_params)
if len(param_value) > 0:
if param_value:
args_command.append("--build-arg")
args_command.append(optional_arg.upper() + "=" + param_value)
args_command.extend(image_params.docker_cache_directive)
Expand Down Expand Up @@ -809,13 +809,13 @@ def autodetect_docker_context():
get_console().print("[warning]Could not detect docker builder. Using default.[/]")
return "default"
context_list = output.stdout.splitlines()
if len(context_list) == 0:
if not context_list:
get_console().print("[warning]Could not detect docker builder. Using default.[/]")
return "default"
if len(context_list) == 1:
elif len(context_list) == 1:
get_console().print(f"[info]Using {context_list[0]} as context.[/]")
return context_list[0]
if len(context_list) > 1:
else:
for preferred_context in PREFERRED_CONTEXTS:
if preferred_context in context_list:
get_console().print(f"[info]Using {preferred_context} as context.[/]")
Expand Down
2 changes: 1 addition & 1 deletion dev/breeze/src/airflow_breeze/utils/md5_build_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def md5sum_check_if_build_is_needed(md5sum_cache_dir: Path) -> bool:
"""
build_needed = False
modified_files, not_modified_files = calculate_md5_checksum_for_files(md5sum_cache_dir, update=False)
if len(modified_files) > 0:
if modified_files:
get_console().print(
f"[warning]The following important files are modified in {AIRFLOW_SOURCES_ROOT} "
f"since last time image was built: [/]\n\n"
Expand Down
2 changes: 1 addition & 1 deletion dev/breeze/src/airflow_breeze/utils/run_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def exclude_command(_index: int, _arg: str) -> bool:
return False
if _arg.startswith("-"):
return True
if len(_arg) == 0:
if not _arg:
return True
if _arg.startswith("/"):
# Skip any absolute paths
Expand Down
6 changes: 3 additions & 3 deletions dev/breeze/src/airflow_breeze/utils/selective_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def find_all_providers_affected(
get_console().print(
"[info]This PR had `allow suspended provider changes` label set so it will continue"
)
if len(all_providers) == 0:
if not all_providers:
return None
for provider in list(all_providers):
all_providers.update(
Expand Down Expand Up @@ -355,7 +355,7 @@ def full_tests_needed(self) -> bool:
if self._github_event in [GithubEvents.PUSH, GithubEvents.SCHEDULE, GithubEvents.WORKFLOW_DISPATCH]:
get_console().print(f"[warning]Full tests needed because event is {self._github_event}[/]")
return True
if len(self._matching_files(FileGroupForCi.ENVIRONMENT_FILES, CI_FILE_GROUP_MATCHES)) > 0:
if self._matching_files(FileGroupForCi.ENVIRONMENT_FILES, CI_FILE_GROUP_MATCHES):
get_console().print("[warning]Running everything because env files changed[/]")
return True
if FULL_TESTS_NEEDED_LABEL in self._pr_labels:
Expand Down Expand Up @@ -495,7 +495,7 @@ def _should_be_run(self, source_area: FileGroupForCi) -> bool:
get_console().print(f"[warning]{source_area} enabled because we are running everything[/]")
return True
matched_files = self._matching_files(source_area, CI_FILE_GROUP_MATCHES)
if len(matched_files) > 0:
if matched_files:
get_console().print(
f"[warning]{source_area} enabled because it matched {len(matched_files)} changed files[/]"
)
Expand Down
2 changes: 1 addition & 1 deletion dev/breeze/tests/test_exclude_from_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ def test_exclude_from_matrix(
exclusion_list = excluded_combos(list_1, list_2)
assert representative_list == expected_representative_list
assert len(representative_list) == len(list_1) * len(list_2) - len(exclusion_list)
assert len(set(representative_list) & set(exclusion_list)) == 0
assert not set(representative_list).intersection(exclusion_list)
4 changes: 2 additions & 2 deletions dev/provider_packages/prepare_provider_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,7 @@ def get_all_changes_for_package(
changes_table += changes_table_for_version
if verbose:
print_changes_table(changes_table)
return True, list_of_list_of_changes if len(list_of_list_of_changes) > 0 else None, changes_table
return True, list_of_list_of_changes or None, changes_table


def get_provider_details(provider_package_id: str) -> ProviderPackageDetails:
Expand Down Expand Up @@ -1337,7 +1337,7 @@ def update_release_notes(
version_suffix=version_suffix,
)
jinja_context["DETAILED_CHANGES_RST"] = changes
jinja_context["DETAILED_CHANGES_PRESENT"] = len(changes) > 0
jinja_context["DETAILED_CHANGES_PRESENT"] = bool(changes)
update_changelog_rst(
jinja_context,
provider_package_id,
Expand Down

0 comments on commit 50abdce

Please sign in to comment.