aboutsummaryrefslogtreecommitdiffstats
path: root/build
diff options
context:
space:
mode:
authoralevitskii <alevitskii@yandex-team.com>2024-12-11 09:19:53 +0300
committeralevitskii <alevitskii@yandex-team.com>2024-12-11 09:43:10 +0300
commit782ee12dcd41268c49cdcfd427a33f8a05142b01 (patch)
treeff73c4926a154b0f96aad6acb4639ee8e0081676 /build
parent4746be4e7d8a883476160a3756105393f9d5b4f6 (diff)
downloadydb-782ee12dcd41268c49cdcfd427a33f8a05142b01.tar.gz
Support python custom linter configs during configuration
Lookup custom linter config commit_hash:364d26435b2794b125199732eb055678b7e96026
Diffstat (limited to 'build')
-rw-r--r--build/conf/python.conf16
-rw-r--r--build/plugins/_dart_fields.py90
-rw-r--r--build/plugins/ytest.py1
3 files changed, 62 insertions, 45 deletions
diff --git a/build/conf/python.conf b/build/conf/python.conf
index 34786b2c53..340705beb6 100644
--- a/build/conf/python.conf
+++ b/build/conf/python.conf
@@ -267,7 +267,7 @@ multimodule PY3_PROGRAM {
}
# tag:python-specific tag:internal
-### @usage: _ADD_PY_LINTER_CHECK(NAME name LINTER linter [DEPENDS deps] CONFIGS configs_file [GLOBAL_RESOURCES gr] [FILE_PROCESSING_TIME fpt] [EXTRA_PARAMS params] [PROJECT_TO_CONFIG_MAP pcm] [FLAKE_MIGRATIONS_CONFIG fmc] [CUSTOM_CONFIG cc])
+### @usage: _ADD_PY_LINTER_CHECK(NAME name LINTER linter [DEPENDS deps] CONFIGS configs_file [GLOBAL_RESOURCES gr] [FILE_PROCESSING_TIME fpt] [EXTRA_PARAMS params] [PROJECT_TO_CONFIG_MAP pcm] [FLAKE_MIGRATIONS_CONFIG fmc] [CUSTOM_CONFIG cc] [CONFIG_TYPE ct])
###
### Triggers respective plugin
macro _ADD_PY_LINTER_CHECK(Args...) {
@@ -283,21 +283,23 @@ macro STYLE_DUMMY() {
}
# tag:python-specific tag:test
-### @usage: STYLE_PYTHON([pyproject])
+### @usage: STYLE_PYTHON([CONFIG_TYPE config_type])
###
### Check python3 sources for style issues using black.
-macro STYLE_PYTHON(pyproject...) {
- _ADD_PY_LINTER_CHECK(NAME black LINTER tools/black_linter/black_linter FILE_PROCESSING_TIME $BLACK_FILE_PROCESSING_TIME CONFIGS $PYTHON_LINTERS_DEFAULT_CONFIGS CUSTOM_CONFIG $pyproject)
+macro STYLE_PYTHON(CONFIG_TYPE="") {
+ .ALLOWED_IN_COMMON=yes
+ _ADD_PY_LINTER_CHECK(NAME black LINTER tools/black_linter/black_linter FILE_PROCESSING_TIME $BLACK_FILE_PROCESSING_TIME CONFIGS $PYTHON_LINTERS_DEFAULT_CONFIGS CUSTOM_CONFIG $CONFIG_TYPE CONFIG_TYPE $CONFIG_TYPE)
}
# tag:python-specific tag:test
-### @usage: STYLE_RUFF()
+### @usage: STYLE_RUFF([CONFIG_TYPE config_type])
###
### Check python3 sources for style issues using ruff.
RUFF_PROJECT_TO_CONFIG_MAP=build/config/tests/ruff/ruff_config_paths.json
-macro STYLE_RUFF() {
+macro STYLE_RUFF(CONFIG_TYPE="") {
+ .ALLOWED_IN_COMMON=yes
SET_APPEND(_MAKEFILE_INCLUDE_LIKE_DEPS ${ARCADIA_ROOT}/${RUFF_PROJECT_TO_CONFIG_MAP})
- _ADD_PY_LINTER_CHECK(NAME ruff LINTER tools/ruff_linter/bin/ruff_linter GLOBAL_RESOURCES build/external_resources/ruff CONFIGS $PYTHON_LINTERS_DEFAULT_CONFIGS PROJECT_TO_CONFIG_MAP $RUFF_PROJECT_TO_CONFIG_MAP)
+ _ADD_PY_LINTER_CHECK(NAME ruff LINTER tools/ruff_linter/bin/ruff_linter GLOBAL_RESOURCES build/external_resources/ruff CONFIGS $PYTHON_LINTERS_DEFAULT_CONFIGS PROJECT_TO_CONFIG_MAP $RUFF_PROJECT_TO_CONFIG_MAP CONFIG_TYPE $CONFIG_TYPE)
}
# tag:python-specific tag:test
diff --git a/build/plugins/_dart_fields.py b/build/plugins/_dart_fields.py
index eb5a0baa75..d7d0fa5737 100644
--- a/build/plugins/_dart_fields.py
+++ b/build/plugins/_dart_fields.py
@@ -571,13 +571,52 @@ class Linter:
class LintConfigs:
KEY = 'LINT-CONFIGS'
+ @staticmethod
+ def _from_config_type(unit, spec_args):
+ if not spec_args.get('CONFIG_TYPE') or not spec_args.get('CONFIG_TYPE')[0]:
+ return
+ linter_name = spec_args['NAME'][0]
+ config_type = spec_args.get('CONFIG_TYPE')[0]
+ if config_type not in consts.LINTER_CONFIG_TYPES[linter_name]:
+ message = "Unknown {} linter config type: {}. Allowed types: {}".format(
+ linter_name, config_type, ', '.join(consts.LINTER_CONFIG_TYPES[linter_name])
+ )
+ ymake.report_configure_error(message)
+ raise DartValueError()
+ if common_configs_dir := unit.get('MODULE_COMMON_CONFIGS_DIR'):
+ config = os.path.join(common_configs_dir, config_type)
+ path = unit.resolve(config)
+ if os.path.exists(path):
+ return _common.strip_roots(config)
+ message = "File not found: {}".format(path)
+ ymake.report_configure_error(message)
+ raise DartValueError()
+ else:
+ message = "Config type specifier is only allowed with autoincludes"
+ ymake.report_configure_error(message)
+ raise DartValueError()
+
@classmethod
def python_configs(cls, unit, flat_args, spec_args):
resolved_configs = []
- project_to_config_map = spec_args.get('PROJECT_TO_CONFIG_MAP', [])
- if project_to_config_map:
- # ruff, TODO rewrite once custom configs migrated to autoincludes scheme
+ if (custom_config := spec_args.get('CUSTOM_CONFIG')) and '/' in custom_config[0]:
+ # black if custom config is passed.
+ # XXX During migration we want to use the same macro parameter
+ # for path to linter config and config type
+ # thus, we check if '/' is present, if it is then it's a path
+ # TODO delete once custom configs migrated to autoincludes scheme
+ custom_config = custom_config[0]
+ assert_file_exists(unit, custom_config)
+ resolved_configs.append(custom_config)
+ return {cls.KEY: serialize_list(resolved_configs)}
+
+ if config := cls._from_config_type(unit, spec_args):
+ # specified by config type, autoincludes scheme
+ return {cls.KEY: serialize_list([config])}
+
+ if project_to_config_map := spec_args.get('PROJECT_TO_CONFIG_MAP'):
+ # ruff, TODO delete once custom configs migrated to autoincludes scheme
project_to_config_map = project_to_config_map[0]
assert_file_exists(unit, project_to_config_map)
resolved_configs.append(project_to_config_map)
@@ -587,23 +626,14 @@ class LintConfigs:
resolved_configs.append(c)
return {cls.KEY: serialize_list(resolved_configs)}
- custom_config = spec_args.get('CUSTOM_CONFIG', [])
- if custom_config:
- # black if custom config is passed
- # TODO rewrite once custom configs migrated to autoincludes scheme
- custom_config = custom_config[0]
- assert_file_exists(unit, custom_config)
- resolved_configs.append(custom_config)
- return {cls.KEY: serialize_list(resolved_configs)}
-
+ # default config
+ linter_name = spec_args['NAME'][0]
config = spec_args['CONFIGS'][0]
- # black without custom config or flake8, using default configs file
assert_file_exists(unit, config)
- name = spec_args['NAME'][0]
- cfg = get_linter_configs(unit, config)[name]
+ cfg = get_linter_configs(unit, config)[linter_name]
assert_file_exists(unit, cfg)
resolved_configs.append(cfg)
- if name in ('flake8', 'py2_flake8'):
+ if linter_name in ('flake8', 'py2_flake8'):
resolved_configs.extend(spec_args.get('FLAKE_MIGRATIONS_CONFIG', []))
return {cls.KEY: serialize_list(resolved_configs)}
@@ -615,29 +645,13 @@ class LintConfigs:
config = custom_config[0]
assert_file_exists(unit, config)
return {cls.KEY: serialize_list([config])}
- linter_name = spec_args['NAME'][0]
- if config_type := spec_args.get('CONFIG_TYPE'):
- config_type = config_type[0]
- if config_type not in consts.LINTER_CONFIG_TYPES[linter_name]:
- message = "Unknown CPP linter config type: {}. Allowed types: {}".format(
- config_type, ', '.join(consts.LINTER_CONFIG_TYPES[linter_name])
- )
- ymake.report_configure_error(message)
- raise DartValueError()
- if common_configs_dir := unit.get('MODULE_COMMON_CONFIGS_DIR'):
- config = os.path.join(common_configs_dir, config_type)
- path = unit.resolve(config)
- if os.path.exists(path):
- config = _common.strip_roots(config)
- return {cls.KEY: serialize_list([config])}
- message = "File not found: {}".format(path)
- ymake.report_configure_error(message)
- raise DartValueError()
- else:
- message = "Config type specifier is only allowed with autoincludes"
- ymake.report_configure_error(message)
- raise DartValueError()
+
+ if config := cls._from_config_type(unit, spec_args):
+ # specified by config type, autoincludes scheme
+ return {cls.KEY: serialize_list([config])}
+
# default config
+ linter_name = spec_args['NAME'][0]
config = spec_args.get('CONFIGS')[0]
assert_file_exists(unit, config)
config = get_linter_configs(unit, config)[linter_name]
diff --git a/build/plugins/ytest.py b/build/plugins/ytest.py
index dd540baf82..a8ef930a07 100644
--- a/build/plugins/ytest.py
+++ b/build/plugins/ytest.py
@@ -1061,6 +1061,7 @@ def on_add_py_linter_check(fields, unit, *args):
"PROJECT_TO_CONFIG_MAP": 1,
"FLAKE_MIGRATIONS_CONFIG": 1,
"CUSTOM_CONFIG": 1,
+ "CONFIG_TYPE": 1,
}
_, spec_args = _common.sort_by_keywords(keywords, args)