Skip to content

Commit

Permalink
limit ruff rules
Browse files Browse the repository at this point in the history
  • Loading branch information
braingram committed Apr 11, 2023
1 parent 13334ba commit f931156
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 41 deletions.
2 changes: 1 addition & 1 deletion asdf/_convenience.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def info(node_or_path, max_rows=DEFAULT_MAX_ROWS, max_cols=DEFAULT_MAX_COLS, sho
"""
with _manage_node(node_or_path) as node:
lines = render_tree(node, max_rows=max_rows, max_cols=max_cols, show_values=show_values, identifier="root")
print("\n".join(lines)) # noqa: T201
print("\n".join(lines))


@contextmanager
Expand Down
2 changes: 1 addition & 1 deletion asdf/asdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1657,7 +1657,7 @@ def info(
identifier="root",
refresh_extension_manager=refresh_extension_manager,
)
print("\n".join(lines)) # noqa: T201
print("\n".join(lines))

def search(self, key=NotSet, type_=NotSet, value=NotSet, filter_=None):
"""
Expand Down
20 changes: 10 additions & 10 deletions asdf/commands/edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def edit(path):
# Extract the YAML portion of the original file:
with generic_io.get_file(path, mode="r") as fd:
if fd.peek(len(constants.ASDF_MAGIC)) != constants.ASDF_MAGIC:
print(f"Error: '{path}' is not an ASDF file.") # noqa: T201
print(f"Error: '{path}' is not an ASDF file.")
return 1

original_content, available_bytes, contains_blocks = read_yaml(fd)
Expand All @@ -217,22 +217,22 @@ def edit(path):
new_content = f.read()

if new_content == original_content:
print("No changes made to file") # noqa: T201
print("No changes made to file")
return 0

try:
new_asdf_version = parse_asdf_version(new_content)
new_yaml_version = parse_yaml_version(new_content)
except Exception as e: # noqa: BLE001
print(f"Error: failed to parse ASDF header: {str(e)}") # noqa: T201
print(f"Error: failed to parse ASDF header: {str(e)}")
choice = request_input("(c)ontinue editing or (a)bort? ", ["c", "a"])
if choice == "a":
return 1

continue

if new_asdf_version != original_asdf_version or new_yaml_version != original_yaml_version:
print("Error: cannot modify ASDF Standard or YAML version using this tool.") # noqa: T201
print("Error: cannot modify ASDF Standard or YAML version using this tool.")
choice = request_input("(c)ontinue editing or (a)bort? ", ["c", "a"])
if choice == "a":
return 1
Expand All @@ -246,7 +246,7 @@ def edit(path):
with open_asdf(io.BytesIO(new_content), _force_raw_types=True):
pass
except yaml.YAMLError as e:
print("Error: failed to parse updated YAML:") # noqa: T201
print("Error: failed to parse updated YAML:")
print_exception(e)
choice = request_input("(c)ontinue editing or (a)bort? ", ["c", "a"])
if choice == "a":
Expand All @@ -255,7 +255,7 @@ def edit(path):
continue

except schema.ValidationError as e:
print("Warning: updated ASDF tree failed validation:") # noqa: T201
print("Warning: updated ASDF tree failed validation:")
print_exception(e)
choice = request_input("(c)ontinue editing, (f)orce update, or (a)bort? ", ["c", "f", "a"])
if choice == "a":
Expand All @@ -265,7 +265,7 @@ def edit(path):
continue

except Exception as e: # noqa: BLE001
print("Error: failed to read updated file as ASDF:") # noqa: T201
print("Error: failed to read updated file as ASDF:")
print_exception(e)
choice = request_input("(c)ontinue editing or (a)bort? ", ["c", "a"])
if choice == "a":
Expand All @@ -291,7 +291,7 @@ def edit(path):
else:
# File does not have sufficient space, and binary blocks
# are present.
print("Warning: updated YAML larger than allocated space. File must be rewritten.") # noqa: T201
print("Warning: updated YAML larger than allocated space. File must be rewritten.")
choice = request_input("(c)ontinue or (a)bort? ", ["c", "a"])
if choice == "a":
return 1
Expand Down Expand Up @@ -346,7 +346,7 @@ def print_exception(e):
if len(lines) > 20:
lines = lines[0:20] + ["..."]
for line in lines:
print(f" {line}") # noqa: T201
print(f" {line}")


def request_input(message, choices):
Expand All @@ -366,7 +366,7 @@ def request_input(message, choices):
if choice in choices:
return choice

print(f"Invalid choice: {choice}") # noqa: T201
print(f"Invalid choice: {choice}")

return None

Expand Down
12 changes: 6 additions & 6 deletions asdf/commands/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ def _print_extension_details(ext, tags_only):
tag_uris.append(typ.make_yaml_tag(typ.name))

if len(tag_uris) > 0:
print("tags:") # noqa: T201
print("tags:")
for tag_uri in sorted(tag_uris):
print(f" - {tag_uri}") # noqa: T201
print(f" - {tag_uri}")

if not tags_only:
types = []
Expand All @@ -77,14 +77,14 @@ def _print_extension_details(ext, tags_only):
types.extend(typ.types)

if len(types) > 0:
print("types:") # noqa: T201
print("types:")
for typ in sorted(types, key=_format_type_name):
print(f" - {_format_type_name(typ)}") # noqa: T201
print(f" - {_format_type_name(typ)}")


def find_extensions(summary, tags_only):
for ext in get_extensions():
print(_format_extension(ext)) # noqa: T201
print(_format_extension(ext))
if not summary:
_print_extension_details(ext, tags_only)
print() # noqa: T201
print()
31 changes: 9 additions & 22 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -162,29 +162,16 @@ exclude_lines = [
[tool.ruff]
target-version = "py38"
line-length = 120
select = ["ALL"]
select = [
# minimal set to match pre-ruff behavior
"E", # pycodestyle
"F", # pyflakes, autoflake
"I", # isort
"S", # bandit
"UP", # pyupgrade
"RUF", # ruff specific, includes yesqa
]
extend-ignore = [
# Ignored check groups
"C90", # mccabe complexity
"D", # pydocstyle
"ANN", # flake8-annotations
"FBT", # flake8-boolean-trap
"ARG", # flake8-unused-arguments
"DTZ", # flake8-datetimez
"PTH", # flake8-use-pathlib
# Individually ignored checks
"B028", # No explicit stacklevel argument
"PIE810", # Call `startswith` once with a `tuple`
"PLC1901", # compare-to-empty-string
"PLR0911", # Too many return statements
"PLR0912", # Too many branches
"PLR0913", # Too many arguments to function call
"PLR0915", # Too many statements
"PLR2004", # Magic value used in comparison
"SLF001", # Private member accessed
"TRY002", # Create your own exception
"TRY301", # Abstract raise to an inner function
"TRY400", # Use logging.exception instead of logging.error
"S310", # URL open for permitted schemes
]
extend-exclude = ["asdf/extern/*", "docs/*"]
Expand Down
2 changes: 1 addition & 1 deletion pytest_asdf/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def runtest(self):

ff._open_impl(ff, buff, mode="rw")
except Exception:
print(f"Example: {self.example.description}\n From file: {self.filename}") # noqa: T201
print(f"Example: {self.example.description}\n From file: {self.filename}")
raise

# Just test we can write it out. A roundtrip test
Expand Down

0 comments on commit f931156

Please sign in to comment.