From b3b1e120a140cbdd079f0e06e939392163ef808b Mon Sep 17 00:00:00 2001 From: Guilherme Gallo Date: Mon, 10 Mar 2025 15:50:33 -0300 Subject: [PATCH] ci/update_tag: fix linter errors Signed-off-by: Guilherme Gallo Part-of: --- bin/ci/test/test_update_tag.py | 9 ++------- bin/ci/update_tag.py | 29 +++++++++-------------------- 2 files changed, 11 insertions(+), 27 deletions(-) diff --git a/bin/ci/test/test_update_tag.py b/bin/ci/test/test_update_tag.py index a17912b8425..0404b1b3a1a 100644 --- a/bin/ci/test/test_update_tag.py +++ b/bin/ci/test/test_update_tag.py @@ -1,4 +1,3 @@ -import os import sys import subprocess import yaml @@ -295,9 +294,7 @@ def test_main_list(monkeypatch, capsys, mock_container_dir, temp_container_ci_fi """ # Monkeypatch find_components to return a known list. for comp in ["comp-a", "comp-b"]: - setup_build_script_and_container_ci_file( - mock_container_dir, temp_container_ci_file, comp - ) + setup_build_script_and_container_ci_file(mock_container_dir, temp_container_ci_file, comp) # Set sys.argv to simulate passing --list. monkeypatch.setattr(sys, "argv", ["bin/ci/update_tag.py", "--list"]) @@ -379,9 +376,7 @@ def test_build_script_error_exit_codes( ) monkeypatch.setattr(subprocess, "run", lambda *args, **kwargs: fake_result) monkeypatch.setattr(sys, "argv", ["bin/ci/update_tag.py", "--check", "foo"]) - monkeypatch.setattr( - "bin.ci.update_tag.get_current_tag_value", lambda *args: "current_tag" - ) + monkeypatch.setattr("bin.ci.update_tag.get_current_tag_value", lambda *args: "current_tag") # Mock sys.exit to capture the exit code instead of exiting the test with pytest.raises(SystemExit) as e: diff --git a/bin/ci/update_tag.py b/bin/ci/update_tag.py index af0ddafe2bc..875150f8a08 100755 --- a/bin/ci/update_tag.py +++ b/bin/ci/update_tag.py @@ -89,11 +89,7 @@ def from_script_name_to_component(script_name: str) -> str: def from_script_name_to_tag_var(script_name: str) -> str: # e.g., "build-angle.sh" -> "ANGLE_TAG" - return ( - re.sub(r"^build-([a-z0-9_-]+)\.sh$", r"\1_TAG", script_name) - .replace("-", "_") - .upper() - ) + return re.sub(r"^build-([a-z0-9_-]+)\.sh$", r"\1_TAG", script_name).replace("-", "_").upper() def prepare_setup_env_script() -> Path: @@ -180,9 +176,7 @@ def find_candidate_components() -> list[str]: return sorted(candidates.intersection(build_scripts)) -def filter_components( - components: list[str], includes: list[str], excludes: list[str] -) -> list[str]: +def filter_components(components: list[str], includes: list[str], excludes: list[str]) -> list[str]: """ Returns components that match at least one `includes` regex and none of the `excludes` regex. If includes is empty, returns an empty list (unless user explicitly does --all or --include). @@ -258,9 +252,7 @@ def run_build_script(component: str, check_only: bool = False) -> Optional[str]: # Tag check failed, let's dissect the error if result.returncode == 2: - logging.error( - f"Tag mismatch for {component}." - ) + logging.error(f"Tag mismatch for {component}.") logging.error(result.stdout) return None @@ -273,17 +265,16 @@ def run_build_script(component: str, check_only: bool = False) -> Optional[str]: sys.exit(3) # Unexpected error in the build script, propagate the exit code - logging.fatal( - f"Build script for {component} failed with return code {result.returncode}" - ) + logging.fatal(f"Build script for {component} failed with return code {result.returncode}") logging.error(result.stdout) sys.exit(result.returncode) def load_image_tags_yaml() -> YamlData: - # 0) Check if the YAML file exists - if not os.path.isfile(CONDITIONAL_TAGS_FILE): - raise FileNotFoundError(f"Conditional build image tags file not found: {CONDITIONAL_TAGS_FILE}") + if not PATHS.conditional_tags.is_file(): + raise FileNotFoundError( + f"Conditional build image tags file not found: {PATHS.conditional_tags}" + ) with open(str(PATHS.conditional_tags), "r", encoding="utf-8") as f: data = yaml.safe_load(f) @@ -364,9 +355,7 @@ Exit codes: default=[], help="Full match regex pattern for components to exclude.", ) - parser.add_argument( - "--all", action="store_true", help="Equivalent to --include '.*'" - ) + parser.add_argument("--all", action="store_true", help="Equivalent to --include '.*'") parser.add_argument( "--check", "-c",