diff options
author | alevitskii <alevitskii@yandex-team.com> | 2024-12-11 09:19:53 +0300 |
---|---|---|
committer | alevitskii <alevitskii@yandex-team.com> | 2024-12-11 09:43:10 +0300 |
commit | 782ee12dcd41268c49cdcfd427a33f8a05142b01 (patch) | |
tree | ff73c4926a154b0f96aad6acb4639ee8e0081676 /build/plugins/_dart_fields.py | |
parent | 4746be4e7d8a883476160a3756105393f9d5b4f6 (diff) | |
download | ydb-782ee12dcd41268c49cdcfd427a33f8a05142b01.tar.gz |
Support python custom linter configs during configuration
Lookup custom linter config
commit_hash:364d26435b2794b125199732eb055678b7e96026
Diffstat (limited to 'build/plugins/_dart_fields.py')
-rw-r--r-- | build/plugins/_dart_fields.py | 90 |
1 files changed, 52 insertions, 38 deletions
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] |