diff options
author | korsunandrei <korsunandrei@yandex-team.com> | 2024-02-20 19:01:36 +0300 |
---|---|---|
committer | korsunandrei <korsunandrei@yandex-team.com> | 2024-02-20 19:19:11 +0300 |
commit | ee61d9c0aa80dcecbfa9d94b4ffab13082be61fd (patch) | |
tree | 8a6b85c14c7e6df4c34ba000427cfc9a4840fcf0 /build/plugins | |
parent | 0102408c4c66050d006364ec447e3824a5f79579 (diff) | |
download | ydb-ee61d9c0aa80dcecbfa9d94b4ffab13082be61fd.tar.gz |
feat yamake: use json for choosing config for ruff linter
38f291cca1eb7eea40d55a4ce5e4048caaf89372
Diffstat (limited to 'build/plugins')
-rw-r--r-- | build/plugins/_common.py | 4 | ||||
-rw-r--r-- | build/plugins/lib/tests/ruff/__init__.py | 17 | ||||
-rw-r--r-- | build/plugins/lib/tests/ruff/ya.make | 11 | ||||
-rw-r--r-- | build/plugins/pybuild.py | 14 | ||||
-rw-r--r-- | build/plugins/ya.make | 1 |
5 files changed, 43 insertions, 4 deletions
diff --git a/build/plugins/_common.py b/build/plugins/_common.py index 9ac1d580d0..cd1d8024a8 100644 --- a/build/plugins/_common.py +++ b/build/plugins/_common.py @@ -11,11 +11,11 @@ class Result(object): def lazy(func): result = Result() - def wrapper(): + def wrapper(*args, **kwargs): try: return result._result except AttributeError: - result._result = func() + result._result = func(*args, **kwargs) return result._result diff --git a/build/plugins/lib/tests/ruff/__init__.py b/build/plugins/lib/tests/ruff/__init__.py new file mode 100644 index 0000000000..2009d0e29a --- /dev/null +++ b/build/plugins/lib/tests/ruff/__init__.py @@ -0,0 +1,17 @@ +import os + + +def get_ruff_config(path, config_paths, arc_root): + # type(str, dict, str) -> Optional[str] + relative_path = os.path.relpath(path, arc_root) + + # find longest path + deepest_path = '' + for p in config_paths.keys(): + if relative_path.startswith(p) and len(p) > len(deepest_path): + deepest_path = p + if deepest_path: + config = config_paths[deepest_path] + full_config_path = os.path.join(arc_root, config) + return full_config_path + return None diff --git a/build/plugins/lib/tests/ruff/ya.make b/build/plugins/lib/tests/ruff/ya.make new file mode 100644 index 0000000000..1d5c87e041 --- /dev/null +++ b/build/plugins/lib/tests/ruff/ya.make @@ -0,0 +1,11 @@ +OWNER(g:ymake) + +PY23_LIBRARY() + +STYLE_PYTHON() + +PY_SRCS( + __init__.py +) + +END() diff --git a/build/plugins/pybuild.py b/build/plugins/pybuild.py index cc5e93129c..04d00e4c4b 100644 --- a/build/plugins/pybuild.py +++ b/build/plugins/pybuild.py @@ -1,4 +1,5 @@ import collections +import json import os import six from hashlib import md5 @@ -11,6 +12,7 @@ YA_IDE_VENV_VAR = 'YA_IDE_VENV' PY_NAMESPACE_PREFIX = 'py/namespace' BUILTIN_PROTO = 'builtin_proto' DEFAULT_FLAKE8_FILE_PROCESSING_TIME = "1.5" # in seconds +RUFF_CONFIG_PATHS_FILE = 'build/config/tests/ruff/ruff_config_paths.json' def _split_macro_call(macro_call, data, item_size, chunk_size=1024): @@ -135,6 +137,14 @@ def get_srcdir(path, unit): return rootrel_arc_src(path, unit)[: -len(path)].rstrip('/') +@lazy +def get_ruff_configs(unit): + arc_config_path = unit.resolve_arc_path(RUFF_CONFIG_PATHS_FILE) + abs_config_path = unit.resolve(arc_config_path) + with open(abs_config_path, 'r') as fd: + return list(json.load(fd).values()) + + def add_python_lint_checks(unit, py_ver, files): @lazy def get_resolved_files(): @@ -210,8 +220,8 @@ def add_python_lint_checks(unit, py_ver, files): params = ["ruff", "tools/ruff_linter/bin/ruff_linter"] params += ["FILES"] + resolved_files params += ["GLOBAL_RESOURCES", resource] - ruff_cfg = unit.get('STYLE_RUFF_PYPROJECT_VALUE') or 'build/config/tests/ruff/ruff.toml' - params += ['CONFIGS', ruff_cfg] + configs = [RUFF_CONFIG_PATHS_FILE, 'build/config/tests/ruff/ruff.toml'] + get_ruff_configs(unit) + params += ['CONFIGS'] + configs unit.on_add_linter_check(params) if files and unit.get('STYLE_PYTHON_VALUE') == 'yes' and is_py3(unit): diff --git a/build/plugins/ya.make b/build/plugins/ya.make index 164104c562..e55053fb9f 100644 --- a/build/plugins/ya.make +++ b/build/plugins/ya.make @@ -48,4 +48,5 @@ RECURSE( lib/proxy lib/test_const lib/test_const/proxy + lib/tests/ruff ) |