From bcc0b8c51f6c4379faf483d32bcb08d1e103f8b1 Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Wed, 26 Apr 2023 19:10:25 +0100 Subject: [PATCH] ruff: Address T and RET (#3364) --- conftest.py | 9 ++++----- pyproject.toml | 3 +-- src/ansiblelint/__main__.py | 4 ++-- src/ansiblelint/schemas/__main__.py | 4 ++-- src/ansiblelint/schemas/__store__.json | 2 +- test/schemas/src/rebuild.py | 10 ++++++---- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/conftest.py b/conftest.py index d7edace57a..6d63ce410b 100644 --- a/conftest.py +++ b/conftest.py @@ -18,11 +18,10 @@ if not importlib.util.find_spec(module): missing.append(module) if missing: - print( - f"FATAL: Missing modules: {', '.join(missing)} -- probably you missed installing test requirements with: pip install -e '.[test]'", - file=sys.stderr, + pytest.exit( + reason=f"FATAL: Missing modules: {', '.join(missing)} -- probably you missed installing test requirements with: pip install -e '.[test]'", + returncode=1, ) - sys.exit(1) # we need to be sure that we have the requirements installed as some tests # might depend on these. This approach is compatible with GHA caching. try: @@ -32,7 +31,7 @@ text=True, ) except subprocess.CalledProcessError as exc: - print(f"{exc}\n{exc.stderr}\n{exc.stdout}", file=sys.stderr) + print(f"{exc}\n{exc.stderr}\n{exc.stdout}", file=sys.stderr) # noqa: T201 sys.exit(1) # ruff: noqa: E402 diff --git a/pyproject.toml b/pyproject.toml index dc38d31d5f..c9698eb7a3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -223,6 +223,7 @@ markers = ["eco: Tests effects on a set of 3rd party ansible repositories"] ignore = [ "E501", # we use black "ERA001", # auto-removal of commented out code affects development and vscode integration + "RET504", # Unnecessary variable assignment before `return` statement # temporary disabled until we fix them: "ANN", "ARG", @@ -231,7 +232,6 @@ ignore = [ "SIM", "BLE", "D", - "RET", "EXE", "FBT", "INP", @@ -240,7 +240,6 @@ ignore = [ "PLR", "PLW", "SLF", - "T", "TCH", "TRY", ] diff --git a/src/ansiblelint/__main__.py b/src/ansiblelint/__main__.py index 16de6526c3..30fe1563d6 100755 --- a/src/ansiblelint/__main__.py +++ b/src/ansiblelint/__main__.py @@ -356,7 +356,7 @@ def path_inject() -> None: # noqa: C901 paths[idx] = os.path.expanduser(path) expanded = True if expanded: # pragma: no cover - print( + print( # noqa: T201 "WARNING: PATH altered to expand ~ in it. Read https://stackoverflow.com/a/44704799/99834 and correct your system configuration.", file=sys.stderr, ) @@ -375,7 +375,7 @@ def path_inject() -> None: # noqa: C901 if not os.environ.get("PYENV_VIRTUAL_ENV", None): if inject_paths: - print( + print( # noqa: T201 f"WARNING: PATH altered to include {', '.join(inject_paths)} :: This is usually a sign of broken local setup, which can cause unexpected behaviors.", file=sys.stderr, ) diff --git a/src/ansiblelint/schemas/__main__.py b/src/ansiblelint/schemas/__main__.py index 855f8637c3..1bbab1871e 100644 --- a/src/ansiblelint/schemas/__main__.py +++ b/src/ansiblelint/schemas/__main__.py @@ -114,7 +114,7 @@ def refresh_schemas(min_age_seconds: int = 3600 * 24) -> int: # noqa: C901 if __name__ == "__main__": if refresh_schemas(60 * 10): # pragma: no cover - print("Schemas were updated.") + print("Schemas were updated.") # noqa: T201 sys.exit(1) else: # pragma: no cover - print("Schemas not updated", 0) + print("Schemas not updated", 0) # noqa: T201 diff --git a/src/ansiblelint/schemas/__store__.json b/src/ansiblelint/schemas/__store__.json index 29d0686dd9..06c5bb414f 100644 --- a/src/ansiblelint/schemas/__store__.json +++ b/src/ansiblelint/schemas/__store__.json @@ -1,6 +1,6 @@ { "ansible-lint-config": { - "etag": "1697c92b482f53635bd57d7715f83e63a168c834a648ec945ab90207c36e696f", + "etag": "ae3bdb0eed9825f89ad76dc5dc4d812ca08591558bbdde401ba68030d658c6f6", "url": "https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/ansible-lint-config.json" }, "ansible-navigator-config": { diff --git a/test/schemas/src/rebuild.py b/test/schemas/src/rebuild.py index 530070a68f..a647bbc3d2 100644 --- a/test/schemas/src/rebuild.py +++ b/test/schemas/src/rebuild.py @@ -77,7 +77,7 @@ def is_ref_used(obj: Any, ref: str) -> bool: invalid_var_names = sorted(list(keyword.kwlist) + play_keywords) if "__peg_parser__" in invalid_var_names: invalid_var_names.remove("__peg_parser__") - print("Updating invalid var names") + print("Updating invalid var names") # noqa: T201 with open("f/vars.json", "r+", encoding="utf-8") as f: vars_schema = json.load(f) @@ -89,7 +89,7 @@ def is_ref_used(obj: Any, ref: str) -> bool: f.write("\n") f.truncate() - print("Compiling subschemas...") + print("Compiling subschemas...") # noqa: T201 with open("f/ansible.json", encoding="utf-8") as f: combined_json = json.load(f) @@ -112,7 +112,9 @@ def is_ref_used(obj: Any, ref: str) -> bool: del sub_json[key] for key in sub_json: if key not in ["$schema", "$defs"]: - print(f"Unexpected key found at combined schema root: ${key}") + print( # noqa: T201 + f"Unexpected key found at combined schema root: ${key}", + ) sys.exit(2) # Copy keys from subschema to root for key, value in combined_json["$defs"][subschema].items(): @@ -129,7 +131,7 @@ def is_ref_used(obj: Any, ref: str) -> bool: if not is_ref_used(sub_json, k): spare.append(k) for k in spare: - print(f"{subschema}: deleting unused '{k}' definition") + print(f"{subschema}: deleting unused '{k}' definition") # noqa: T201 del sub_json["$defs"][k] if not spare: break