From 1eecc616f522d28712490e6fbd74b4579b34b82b Mon Sep 17 00:00:00 2001 From: Siarhei Siniak Date: Sun, 10 Nov 2024 21:15:20 +0300 Subject: [PATCH] [~] Refactor --- _m.py | 44 ++++++++++++++++++++++++++++-------- dotfiles/.local/bin/commands | 2 +- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/_m.py b/_m.py index c489448..604aae3 100644 --- a/_m.py +++ b/_m.py @@ -62,21 +62,47 @@ def env( return None -def ruff(args: list[str]) -> None: +def ruff(argv: list[str]) -> None: + parser = argparse.ArgumentParser() + parser.add_argument( + '-i', + dest='paths', + help='specify paths to check', + default=[], + action='append', + ) + parser.add_argument( + '-e', + dest='exclude', + help='rules to ignore', + default=[], + action='append', + ) + + options, args = parser.parse_known_args(argv) + + if len(options.paths) == 0: + options.paths.extend([ + '.', + 'dotfiles/.local/bin/commands', + ]) + + if len(options.exclude) == 0: + options.exclude.extend([ + 'E731', + 'E713', + 'E714', + 'E703', + ]) + res = env([ '-m', 'ruff', 'check', *args, '--output-format', 'json', - '--ignore', ','.join([ - 'E731', - 'E713', - 'E714', - 'E703', - ]), - '.', - 'dotfiles/.local/bin/commands', + '--ignore', ','.join(options.exclude), + *options.paths, ], stdout=subprocess.PIPE, stderr=subprocess.PIPE) assert not res is None diff --git a/dotfiles/.local/bin/commands b/dotfiles/.local/bin/commands index db6ac72..208808d 100755 --- a/dotfiles/.local/bin/commands +++ b/dotfiles/.local/bin/commands @@ -23,7 +23,7 @@ import tempfile import time import traceback -from typing import (Literal, Optional, Iterable, TypedDict, Callable, Any,) +from typing import (Literal, Optional, TypedDict, Callable,) logger = logging.getLogger(__name__)