diff options
author | alevitskii <alevitskii@yandex-team.com> | 2024-09-19 09:23:33 +0300 |
---|---|---|
committer | alevitskii <alevitskii@yandex-team.com> | 2024-09-19 09:36:58 +0300 |
commit | b483c552ab774f1c6dfeb9cd16493caf9a4bd147 (patch) | |
tree | 551f7c280f40305838a00a2315cdcf854f1cb17e /build/plugins/_dart_fields.py | |
parent | 3f4d314c20d9192bdf84f803ca3a30a051c18198 (diff) | |
download | ydb-b483c552ab774f1c6dfeb9cd16493caf9a4bd147.tar.gz |
new STYLE_CPP
new STYLE_CPP
* STYLE_CPP с дефолтным конфигом
* Прокси файлы с линтерными конфигами для python и cpp, чтобы оторвать конфиги от релизных процессов ya-bin
commit_hash:fa75b9b1437d66eda31caf24e9232370d8cce031
Diffstat (limited to 'build/plugins/_dart_fields.py')
-rw-r--r-- | build/plugins/_dart_fields.py | 93 |
1 files changed, 73 insertions, 20 deletions
diff --git a/build/plugins/_dart_fields.py b/build/plugins/_dart_fields.py index 51349aa4ae..34f13579a2 100644 --- a/build/plugins/_dart_fields.py +++ b/build/plugins/_dart_fields.py @@ -259,13 +259,28 @@ def _get_ts_test_data_dirs(unit): ) -@_common.lazy +@_common.cache_by_second_arg def get_linter_configs(unit, config_paths): rel_config_path = _common.rootrel_arc_src(config_paths, unit) arc_config_path = unit.resolve_arc_path(rel_config_path) abs_config_path = unit.resolve(arc_config_path) with open(abs_config_path, 'r') as fd: - return list(json.load(fd).values()) + return json.load(fd) + + +def _reference_group_var(varname: str, extensions: list[str] | None = None) -> str: + if extensions is None: + return f'"${{join=\\;:{varname}}}"' + + return serialize_list(f'${{ext={ext};join=\\;:{varname}}}' for ext in extensions) + + +def assert_file_exists(unit, path): + path = unit.resolve(SOURCE_ROOT_SHORT + path) + if not os.path.exists(path): + message = 'File {} is not found'.format(path) + ymake.report_configure_error(message) + raise DartValueError() class AndroidApkTestActivity: @@ -552,25 +567,56 @@ class LintConfigs: KEY = 'LINT-CONFIGS' @classmethod - def value(cls, unit, flat_args, spec_args): + def python_configs(cls, unit, flat_args, spec_args): resolved_configs = [] - configs = spec_args.get('CONFIGS', []) - for cfg in configs: - filename = unit.resolve(SOURCE_ROOT_SHORT + cfg) - if not os.path.exists(filename): - message = 'Configuration file {} is not found'.format(filename) - raise DartValueError(message) - resolved_configs.append(cfg) - if os.path.splitext(filename)[-1] == '.json': - cfgs = get_linter_configs(unit, cfg) - for c in cfgs: - filename = unit.resolve(SOURCE_ROOT_SHORT + c) - if not os.path.exists(filename): - message = 'Configuration file {} is not found'.format(filename) - raise DartValueError(message) - resolved_configs.append(c) + + 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 + project_to_config_map = project_to_config_map[0] + assert_file_exists(unit, project_to_config_map) + resolved_configs.append(project_to_config_map) + cfgs = get_linter_configs(unit, project_to_config_map).values() + for c in cfgs: + assert_file_exists(unit, c) + 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)} + + 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] + assert_file_exists(unit, cfg) + resolved_configs.append(cfg) + if name in ('flake8', 'py2_flake8'): + resolved_configs.extend(spec_args.get('FLAKE_MIGRATIONS_CONFIG', [])) return {cls.KEY: serialize_list(resolved_configs)} + @classmethod + def cpp_configs(cls, unit, flat_args, spec_args): + custom_config = spec_args.get('CUSTOM_CONFIG') + if custom_config: + config = custom_config[0] + assert_file_exists(unit, config) + else: + # file with default configs + config = spec_args.get('CONFIGS')[0] + assert_file_exists(unit, config) + name = spec_args['NAME'][0] + config = get_linter_configs(unit, config)[name] + assert_file_exists(unit, config) + return {cls.KEY: serialize_list([config])} + class LintExtraParams: KEY = 'LINT-EXTRA-PARAMS' @@ -581,7 +627,8 @@ class LintExtraParams: for arg in extra_params: if '=' not in arg: message = 'Wrong EXTRA_PARAMS value: "{}". Values must have format "name=value".'.format(arg) - raise DartValueError(message) + ymake.report_configure_error(message) + raise DartValueError() return {cls.KEY: serialize_list(extra_params)} @@ -600,7 +647,8 @@ class LintName: def value(cls, unit, flat_args, spec_args): lint_name = spec_args['NAME'][0] if lint_name in ('flake8', 'py2_flake8') and (unit.get('DISABLE_FLAKE8') or 'no') == 'yes': - raise DartValueError('Flake8 linting is disabled by `DISABLE_FLAKE8`') + unit.message(['INFO', 'Flake8 linting is disabled by `DISABLE_FLAKE8`']) + raise DartValueError() return {cls.KEY: lint_name} @@ -1144,6 +1192,11 @@ class TestFiles: test_files = serialize_list(test_files) return {cls.KEY: test_files, cls.KEY2: test_files} + @classmethod + def cpp_linter_files(cls, unit, flat_args, spec_args): + files_dart = _reference_group_var("ALL_SRCS", consts.STYLE_CPP_ALL_EXTS) + return {cls.KEY: files_dart, cls.KEY2: files_dart} + class TestEnv: KEY = 'TEST-ENV' |