summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkorsunandrei <[email protected]>2024-01-24 19:40:09 +0300
committerAlexander Smirnov <[email protected]>2024-01-26 20:49:05 +0300
commitccdd7d3aed84ad876ff5d2045b1f1cc5eedb9aea (patch)
tree6be41db2338e1105d68afb4e06738642a1d7dbca
parent797de866c589bbfd60539e19ca6ffff2ff6825da (diff)
feat yamake: add ruff wrapper and ya make macro
-rw-r--r--build/conf/python.conf11
-rw-r--r--build/plugins/lib/test_const/__init__.py1
-rw-r--r--build/plugins/pybuild.py25
3 files changed, 35 insertions, 2 deletions
diff --git a/build/conf/python.conf b/build/conf/python.conf
index 8fcd11593d5..27a8bcd47a0 100644
--- a/build/conf/python.conf
+++ b/build/conf/python.conf
@@ -237,6 +237,17 @@ macro STYLE_PYTHON(pyproject...) {
}
# tag:python-specific tag:test
+STYLE_RUFF_VALUE=no
+STYLE_RUFF_PYPROJECT_VALUE=
+### @usage: STYLE_RUFF([pyproject])
+###
+### Check python3 sources for style issues using ruff.
+macro STYLE_RUFF(pyproject...) {
+ SET(STYLE_RUFF_VALUE yes)
+ SET(STYLE_RUFF_PYPROJECT_VALUE ${pyproject})
+}
+
+# tag:python-specific tag:test
### @usage: NO_DOCTESTS()
###
### Disable doctests in PY[|3|23_]TEST
diff --git a/build/plugins/lib/test_const/__init__.py b/build/plugins/lib/test_const/__init__.py
index 8037a5c266c..8a91bd5ebed 100644
--- a/build/plugins/lib/test_const/__init__.py
+++ b/build/plugins/lib/test_const/__init__.py
@@ -200,6 +200,7 @@ GO_TOOLS_RESOURCE = 'GO_TOOLS_RESOURCE_GLOBAL'
JSTYLE_RUNNER_LIB = 'JSTYLE_LIB_RESOURCE_GLOBAL'
NODEJS_RESOURCE = 'NODEJS_RESOURCE_GLOBAL'
NYC_RESOURCE = 'NYC_RESOURCE_GLOBAL'
+RUFF_RESOURCE = 'RUFF_RESOURCE_GLOBAL'
TEST_TOOL3_HOST = 'TEST_TOOL3_HOST_RESOURCE_GLOBAL'
TEST_TOOL3_HOST_LOCAL = 'TEST_TOOL3_HOST_LOCAL'
TEST_TOOL_HOST = 'TEST_TOOL_HOST_RESOURCE_GLOBAL'
diff --git a/build/plugins/pybuild.py b/build/plugins/pybuild.py
index 23ace17669c..e58f0906cdf 100644
--- a/build/plugins/pybuild.py
+++ b/build/plugins/pybuild.py
@@ -145,6 +145,8 @@ def add_python_lint_checks(unit, py_ver, files):
resolved_files.append(resolved)
return resolved_files
+ upath = unit.path()[3:]
+
no_lint_value = get_no_lint_value(unit)
if no_lint_value == "none":
no_lint_allowed_paths = (
@@ -161,8 +163,6 @@ def add_python_lint_checks(unit, py_ver, files):
"yt/python/", # YT-20053
)
- upath = unit.path()[3:]
-
if not upath.startswith(no_lint_allowed_paths):
ymake.report_configure_error("NO_LINT() is allowed only in " + ", ".join(no_lint_allowed_paths))
@@ -193,6 +193,27 @@ def add_python_lint_checks(unit, py_ver, files):
params += ["EXTRA_PARAMS"] + extra_params
unit.on_add_linter_check(params)
+ # ruff related stuff
+ if unit.get('STYLE_RUFF_VALUE') == 'yes':
+ if no_lint_value in ("none", "none_internal"):
+ ymake.report_configure_error(
+ 'NO_LINT() and STYLE_RUFF() can\'t be enabled both at the same time',
+ )
+ # temporary allow using ruff for taxi only
+ ruff_allowed_paths = ("taxi/",)
+ if not upath.startswith(ruff_allowed_paths):
+ ymake.report_configure_error("STYLE_RUFF() is allowed only in " + ", ".join(ruff_allowed_paths))
+
+ resolved_files = get_resolved_files()
+ if resolved_files:
+ resource = "build/external_resources/ruff"
+ 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]
+ unit.on_add_linter_check(params)
+
if files and unit.get('STYLE_PYTHON_VALUE') == 'yes' and is_py3(unit):
resolved_files = get_resolved_files()
if resolved_files: