Skip to content

Commit

Permalink
ruff: Address T and RET (#3364)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed Apr 26, 2023
1 parent a0b2c90 commit bcc0b8c
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
9 changes: 4 additions & 5 deletions conftest.py
Expand Up @@ -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:
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Expand Up @@ -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",
Expand All @@ -231,7 +232,6 @@ ignore = [
"SIM",
"BLE",
"D",
"RET",
"EXE",
"FBT",
"INP",
Expand All @@ -240,7 +240,6 @@ ignore = [
"PLR",
"PLW",
"SLF",
"T",
"TCH",
"TRY",
]
Expand Down
4 changes: 2 additions & 2 deletions src/ansiblelint/__main__.py
Expand Up @@ -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,
)
Expand All @@ -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,
)
Expand Down
4 changes: 2 additions & 2 deletions src/ansiblelint/schemas/__main__.py
Expand Up @@ -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
2 changes: 1 addition & 1 deletion 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": {
Expand Down
10 changes: 6 additions & 4 deletions test/schemas/src/rebuild.py
Expand Up @@ -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)
Expand All @@ -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)

Expand All @@ -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():
Expand All @@ -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
Expand Down

0 comments on commit bcc0b8c

Please sign in to comment.