Skip to content

Commit

Permalink
Refactor ya style
Browse files Browse the repository at this point in the history
Refactor ya style

- Переписал процесс сбора целей для линтинга на использование `pathlib`

- Переписал исполнение на `ThreadPoolExecutor` вместо создания тредов и очереди

- Создал иерархию `Styler` классов. Поиск нужного стайлера переписал на hashmap lookup вместо перебора суффиксов через `endswith`

- Переписал поиск конфигов для ruff на trie

- Убрал `--fast` проверку для black, её добавили из-за <HIDDEN_URL>, соответствующий issue fixed <psf/black#1629>

- Убрал конструкции `if six.PY3`

- Добавил type annotations
commit_hash:84c5a78d9fb32fe3b1350d3a0743bee2a3ec5974
  • Loading branch information
andrei-levitskii committed Oct 8, 2024
1 parent 763d219 commit 5986d81
Show file tree
Hide file tree
Showing 10 changed files with 483 additions and 559 deletions.
26 changes: 10 additions & 16 deletions devtools/ya/handlers/style/__init__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
from __future__ import absolute_import

import core.common_opts
import core.yarg

from build.build_opts import CustomFetcherOptions, SandboxAuthOptions, ToolsOptions, BuildThreadsOptions
import core.yarg.consumers

from .enums import StylerKind
from .style import run_style

import devtools.ya.app


class StyleOptions(core.yarg.Options):
def __init__(self):
self.targets = []
self.targets: list[str] = []
self.dry_run = False
self.check = False
self.full_output = False
Expand Down Expand Up @@ -71,11 +74,11 @@ def consumer():

class FilterOptions(core.yarg.Options):
def __init__(self):
self.file_types = []
self.file_types: list[str] = []

@staticmethod
def consumer():
checks = ['py', 'cpp', 'go', 'yamake', 'cuda']
checks = [kind for kind in StylerKind]

return [
core.yarg.ArgConsumer(
Expand Down Expand Up @@ -130,22 +133,13 @@ def __init__(self):
FilterOptions(),
],
examples=[
core.yarg.UsageExample(
'{prefix}',
'restyle text from <stdin>, write result to <stdout>'
),
core.yarg.UsageExample(
'{prefix} .',
'restyle all files in current directory'
),
core.yarg.UsageExample('{prefix}', 'restyle text from <stdin>, write result to <stdout>'),
core.yarg.UsageExample('{prefix} .', 'restyle all files in current directory'),
core.yarg.UsageExample(
'{prefix} file.cpp',
'restyle file.cpp',
),
core.yarg.UsageExample(
'{prefix} folder/',
'restyle all files in subfolders recursively'
)
core.yarg.UsageExample('{prefix} folder/', 'restyle all files in subfolders recursively'),
],
unknown_args_as_free=False
unknown_args_as_free=False,
)
83 changes: 0 additions & 83 deletions devtools/ya/handlers/style/cpp_style.py

This file was deleted.

12 changes: 12 additions & 0 deletions devtools/ya/handlers/style/enums.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from enum import StrEnum, auto


STDIN_FILENAME_STAMP = 'STDIN_FILENAME_STAMP'


class StylerKind(StrEnum):
PY = auto()
CPP = auto()
CUDA = auto()
YAMAKE = auto()
GO = auto()
27 changes: 0 additions & 27 deletions devtools/ya/handlers/style/golang_style.py

This file was deleted.

120 changes: 0 additions & 120 deletions devtools/ya/handlers/style/python_style.py

This file was deleted.

38 changes: 0 additions & 38 deletions devtools/ya/handlers/style/ruff_config.py

This file was deleted.

4 changes: 2 additions & 2 deletions devtools/ya/handlers/style/state_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
app_ctx = sys.modules.get('app_ctx')


def stop():
def stop() -> None:
if app_ctx:
app_ctx.state.stop()


def check_cancel_state():
def check_cancel_state() -> None:
if app_ctx:
app_ctx.state.check_cancel_state()
Loading

0 comments on commit 5986d81

Please sign in to comment.