Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pre-commit: enable ruff #106

Merged
merged 2 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ repos:
hooks:
- id: pyspelling
args: ["--config", ".spellcheck.yml"]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.7
hooks:
- id: ruff
args: [--fix]
- id: ruff-format
23 changes: 11 additions & 12 deletions src/otk/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ def root() -> int:


def _process(arguments: argparse.Namespace, dry_run: bool) -> int:
src = pathlib.Path(
"/dev/stdin" if arguments.input is None else arguments.input
src = pathlib.Path("/dev/stdin" if arguments.input is None else arguments.input)
dst = (
pathlib.Path("/dev/stdout" if arguments.output is None else arguments.output)
if not dry_run
else None
)
dst = pathlib.Path(
"/dev/stdout" if arguments.output is None else arguments.output
) if not dry_run else None

if not src.exists():
log.fatal("INPUT path %r does not exist", str(src))
Expand Down Expand Up @@ -94,9 +94,7 @@ def _process(arguments: argparse.Namespace, dry_run: bool) -> int:
target_requested = list(target_available.keys())[0]

if target_requested not in target_available:
log.fatal(
"requested target %r does not exist in INPUT", target_requested
)
log.fatal("requested target %r does not exist in INPUT", target_requested)
return 1

# resolve the full tree first
Expand All @@ -107,7 +105,10 @@ def _process(arguments: argparse.Namespace, dry_run: bool) -> int:
kind, name = target_requested.split(".")
except ValueError:
# TODO handle earlier
log.fatal("malformed target name %r. We need a format of '<TARGET_KIND>.<TARGET_NAME>'.", target_requested)
log.fatal(
"malformed target name %r. We need a format of '<TARGET_KIND>.<TARGET_NAME>'.",
target_requested,
)
return 1

# re-resolve the specific target with the specific context and target if
Expand All @@ -117,9 +118,7 @@ def _process(arguments: argparse.Namespace, dry_run: bool) -> int:

# and then output by writing to the output
if not dry_run:
dst.write_text(
target_registry.get(kind, CommonTarget)().as_string(spec, tree)
)
dst.write_text(target_registry.get(kind, CommonTarget)().as_string(spec, tree))

return 0

Expand Down
Loading