diff options
author | iaz1607 <iaz1607@yandex-team.com> | 2023-11-27 13:50:15 +0300 |
---|---|---|
committer | iaz1607 <iaz1607@yandex-team.com> | 2023-11-27 14:20:03 +0300 |
commit | f2bebe45e16d892b620cc073279faaa1bf550a92 (patch) | |
tree | f8b87603f9c7f8372a7e4d49b352e1ab1b8fc61f /build/plugins | |
parent | 9b07404a4c0075cda0fcf2ee078cf81c51c05fd2 (diff) | |
download | ydb-f2bebe45e16d892b620cc073279faaa1bf550a92.tar.gz |
`build/plugins` ya style --py
Diffstat (limited to 'build/plugins')
-rw-r--r-- | build/plugins/_xsyn_includes.py | 2 | ||||
-rw-r--r-- | build/plugins/create_init_py.py | 2 | ||||
-rw-r--r-- | build/plugins/docs.py | 4 | ||||
-rw-r--r-- | build/plugins/ios_app_settings.py | 1 | ||||
-rw-r--r-- | build/plugins/java.py | 29 | ||||
-rw-r--r-- | build/plugins/large_files.py | 18 | ||||
-rw-r--r-- | build/plugins/lib/proxy/ya.make | 2 | ||||
-rw-r--r-- | build/plugins/lib/test_const/__init__.py | 2 | ||||
-rw-r--r-- | build/plugins/lib/test_const/proxy/ya.make | 2 | ||||
-rw-r--r-- | build/plugins/lib/test_const/ya.make | 2 | ||||
-rw-r--r-- | build/plugins/lib/ya.make | 2 | ||||
-rw-r--r-- | build/plugins/lj_archive.py | 16 | ||||
-rw-r--r-- | build/plugins/llvm_bc.py | 2 | ||||
-rw-r--r-- | build/plugins/pybuild.py | 22 | ||||
-rw-r--r-- | build/plugins/tests/fake_ymake/ya.make | 2 | ||||
-rw-r--r-- | build/plugins/ya.make | 28 | ||||
-rw-r--r-- | build/plugins/ytest.py | 19 |
17 files changed, 105 insertions, 50 deletions
diff --git a/build/plugins/_xsyn_includes.py b/build/plugins/_xsyn_includes.py index d458679da0..575edcee71 100644 --- a/build/plugins/_xsyn_includes.py +++ b/build/plugins/_xsyn_includes.py @@ -14,7 +14,7 @@ def get_include_callback(): res = [] if element.nodeType == element.ELEMENT_NODE and element.nodeName == "parse:include": attrs = element.attributes - for i in xrange(attrs.length): + for i in range(attrs.length): attr = attrs.item(i) if attr.nodeName == "path": include_filename = attr.nodeValue diff --git a/build/plugins/create_init_py.py b/build/plugins/create_init_py.py index c5fc119fc9..c054155a08 100644 --- a/build/plugins/create_init_py.py +++ b/build/plugins/create_init_py.py @@ -1,7 +1,5 @@ import os -from _common import sort_by_keywords - def oncreate_init_py_structure(unit, *args): if unit.get('DISTBUILD') or unit.get('AUTOCHECK'): diff --git a/build/plugins/docs.py b/build/plugins/docs.py index f68b7231ea..85bdfdcbc1 100644 --- a/build/plugins/docs.py +++ b/build/plugins/docs.py @@ -51,4 +51,6 @@ def onprocess_docs(unit, *args): def onprocess_mkdocs(unit, *args): variables = get_variables(unit) if variables: - unit.set(['_DOCS_VARS_FLAG', ' '.join(['--var {}={}'.format(k, v) for k, v in sorted(six.iteritems(variables))])]) + unit.set( + ['_DOCS_VARS_FLAG', ' '.join(['--var {}={}'.format(k, v) for k, v in sorted(six.iteritems(variables))])] + ) diff --git a/build/plugins/ios_app_settings.py b/build/plugins/ios_app_settings.py index 0d5b233eea..8ae01b0ea0 100644 --- a/build/plugins/ios_app_settings.py +++ b/build/plugins/ios_app_settings.py @@ -1,6 +1,5 @@ import _common as common import ymake -import os def onios_app_settings(unit, *args): diff --git a/build/plugins/java.py b/build/plugins/java.py index b7ec7908eb..ebf4af8f1c 100644 --- a/build/plugins/java.py +++ b/build/plugins/java.py @@ -18,9 +18,12 @@ def extract_macro_calls(unit, macro_value_name, macro_calls_delim): if not unit.get(macro_value_name): return [] - return list(filter( - None, map(split_args, unit.get(macro_value_name).replace('$' + macro_value_name, '').split(macro_calls_delim)) - )) + return list( + filter( + None, + map(split_args, unit.get(macro_value_name).replace('$' + macro_value_name, '').split(macro_calls_delim)), + ) + ) def extract_macro_calls2(unit, macro_value_name): @@ -69,7 +72,9 @@ def on_run_jbuild_program(unit, *args): args += ['FAKE_OUT', fake_out] prev = unit.get(['RUN_JAVA_PROGRAM_VALUE']) or '' - new_val = (prev + ' ' + six.ensure_str(base64.b64encode(six.ensure_binary(json.dumps(list(args)), encoding='utf-8')))).strip() + new_val = ( + prev + ' ' + six.ensure_str(base64.b64encode(six.ensure_binary(json.dumps(list(args)), encoding='utf-8'))) + ).strip() unit.set(['RUN_JAVA_PROGRAM_VALUE', new_val]) @@ -83,7 +88,9 @@ def ongenerate_script(unit, *args): if len(kv.get('TEMPLATE', [])) > len(kv.get('OUT', [])): ymake.report_configure_error('To many arguments for TEMPLATE parameter') prev = unit.get(['GENERATE_SCRIPT_VALUE']) or '' - new_val = (prev + ' ' + six.ensure_str(base64.b64encode(six.ensure_binary(json.dumps(list(args)), encoding='utf-8')))).strip() + new_val = ( + prev + ' ' + six.ensure_str(base64.b64encode(six.ensure_binary(json.dumps(list(args)), encoding='utf-8'))) + ).strip() unit.set(['GENERATE_SCRIPT_VALUE', new_val]) @@ -138,7 +145,7 @@ def onjava_module(unit, *args): '18', '19', '20', - '21' + '21', ): data['ENABLE_PREVIEW'] = extract_macro_calls(unit, 'ENABLE_PREVIEW_VALUE', args_delim) @@ -208,7 +215,6 @@ def onjava_module(unit, *args): data['WITH_JDK'] = extract_macro_calls(unit, 'WITH_JDK_VALUE', args_delim) if not data['EXTERNAL_JAR']: - has_processor = extract_macro_calls(unit, 'GENERATE_VCS_JAVA_INFO_NODEP', args_delim) # IMPORTANT before switching vcs_info.py to python3 the value was always evaluated to $YMAKE_PYTHON but no # code in java dart parser extracts its value only checks this key for existance. data['EMBED_VCS'] = [['yes']] @@ -241,7 +247,7 @@ def onjava_module(unit, *args): if external: unit.onpeerdir(external) - data = {k:v for k, v in six.iteritems(data) if v} + data = {k: v for k, v in six.iteritems(data) if v} dart = 'JAVA_DART: ' + six.ensure_str(base64.b64encode(six.ensure_binary(json.dumps(data)))) + '\n' + DELIM + '\n' unit.set_property(['JAVA_DART_DATA', dart]) @@ -288,7 +294,7 @@ def on_check_java_srcdir(unit, *args): if 'SKIP_CHECK_SRCDIR' in args: return for arg in args: - if not '$' in arg: + if '$' not in arg: arc_srcdir = os.path.join(unit.get('MODDIR'), arg) abs_srcdir = unit.resolve(os.path.join("$S/", arc_srcdir)) if not os.path.exists(abs_srcdir) or not os.path.isdir(abs_srcdir): @@ -352,7 +358,7 @@ def extract_words(words, keys): if w in keys: k = w else: - if not k in kv: + if k not in kv: kv[k] = [] kv[k].append(w) @@ -361,7 +367,7 @@ def extract_words(words, keys): def parse_words(words): kv = extract_words(words, {'OUT', 'TEMPLATE'}) - if not 'TEMPLATE' in kv: + if 'TEMPLATE' not in kv: kv['TEMPLATE'] = ['template.tmpl'] ws = [] for item in ('OUT', 'TEMPLATE'): @@ -438,6 +444,7 @@ def _maven_coords_for_project(unit, project_dir): pom_path = unit.resolve(os.path.join('$S', project_dir, 'pom.xml')) if os.path.exists(pom_path): import xml.etree.ElementTree as et + with open(pom_path, 'rb') as f: root = et.fromstring(f.read()) for xpath in ('./{http://maven.apache.org/POM/4.0.0}artifactId', './artifactId'): diff --git a/build/plugins/large_files.py b/build/plugins/large_files.py index 308dc82075..0e0aaca854 100644 --- a/build/plugins/large_files.py +++ b/build/plugins/large_files.py @@ -1,7 +1,7 @@ import json import os import ymake -from _common import strip_roots, resolve_common_const +from _common import resolve_common_const PLACEHOLDER_EXT = "external" @@ -35,7 +35,9 @@ def onlarge_files(unit, *args): external = "{}.{}".format(arg, PLACEHOLDER_EXT) rel_placeholder = resolve_common_const(unit.resolve_arc_path(external)) if not rel_placeholder.startswith("$S"): - ymake.report_configure_error('LARGE_FILES: neither actual data nor placeholder is found for "{}"'.format(arg)) + ymake.report_configure_error( + 'LARGE_FILES: neither actual data nor placeholder is found for "{}"'.format(arg) + ) return try: abs_placeholder = unit.resolve(rel_placeholder) @@ -43,8 +45,10 @@ def onlarge_files(unit, *args): res_desc = json.load(f) storage = res_desc["storage"] res_id = res_desc["resource_id"] - except e: - ymake.report_configure_error('LARGE_FILES: error processing placeholder file "{}.": {}'.format(external, e)) + except Exception as e: + ymake.report_configure_error( + 'LARGE_FILES: error processing placeholder file "{}.": {}'.format(external, e) + ) return from_cmd = ['FILE', '{}'.format(res_id), 'OUT_NOAUTO', arg, 'EXTERNAL_FILE', external] @@ -55,4 +59,8 @@ def onlarge_files(unit, *args): if method: method(from_cmd) else: - ymake.report_configure_error('LARGE_FILES: error processing placeholder file "{}.": unknown storage kind "{}"'.format(external, storage)) + ymake.report_configure_error( + 'LARGE_FILES: error processing placeholder file "{}.": unknown storage kind "{}"'.format( + external, storage + ) + ) diff --git a/build/plugins/lib/proxy/ya.make b/build/plugins/lib/proxy/ya.make index b342c75504..4bf76a7d14 100644 --- a/build/plugins/lib/proxy/ya.make +++ b/build/plugins/lib/proxy/ya.make @@ -2,6 +2,8 @@ OWNER(g:ymake) PY23_LIBRARY() +STYLE_PYTHON() + PY_SRCS( _metric_resolvers.py=lib._metric_resolvers ) diff --git a/build/plugins/lib/test_const/__init__.py b/build/plugins/lib/test_const/__init__.py index a06fec239e..a4b162cde7 100644 --- a/build/plugins/lib/test_const/__init__.py +++ b/build/plugins/lib/test_const/__init__.py @@ -447,7 +447,6 @@ class Status(object): class _Colors(object): - _NAMES = [ "blue", "cyan", @@ -480,7 +479,6 @@ Colors = _Colors() class _Highlight(object): - _MARKERS = { # special "RESET": "rst", diff --git a/build/plugins/lib/test_const/proxy/ya.make b/build/plugins/lib/test_const/proxy/ya.make index 37d459cc00..1f01ef9e13 100644 --- a/build/plugins/lib/test_const/proxy/ya.make +++ b/build/plugins/lib/test_const/proxy/ya.make @@ -2,6 +2,8 @@ OWNER(g:ymake) PY23_LIBRARY() +STYLE_PYTHON() + PY_SRCS( __init__.py=lib.test_const ) diff --git a/build/plugins/lib/test_const/ya.make b/build/plugins/lib/test_const/ya.make index fa5b3b184b..1d5c87e041 100644 --- a/build/plugins/lib/test_const/ya.make +++ b/build/plugins/lib/test_const/ya.make @@ -2,6 +2,8 @@ OWNER(g:ymake) PY23_LIBRARY() +STYLE_PYTHON() + PY_SRCS( __init__.py ) diff --git a/build/plugins/lib/ya.make b/build/plugins/lib/ya.make index e018b2dc1d..f2a8fbf0ab 100644 --- a/build/plugins/lib/ya.make +++ b/build/plugins/lib/ya.make @@ -2,6 +2,8 @@ OWNER(g:ymake) PY23_LIBRARY() +STYLE_PYTHON() + PY_SRCS( _metric_resolvers.py ) diff --git a/build/plugins/lj_archive.py b/build/plugins/lj_archive.py index 9f071f3d87..4af43d80d5 100644 --- a/build/plugins/lj_archive.py +++ b/build/plugins/lj_archive.py @@ -4,13 +4,13 @@ def onlj_archive(unit, *args): Precompile .lua files using LuaJIT and archive both sources and results using sources names as keys """ - def iter_luas(l): - for a in l: + def iter_luas(data): + for a in data: if a.endswith('.lua'): yield a - def iter_objs(l): - for a in l: + def iter_objs(data): + for a in data: s = a[:-3] + 'raw' unit.on_luajit_objdump(['OUT', s, a]) yield s @@ -28,13 +28,13 @@ def onlj_21_archive(unit, *args): Precompile .lua files using LuaJIT 2.1 and archive both sources and results using sources names as keys """ - def iter_luas(l): - for a in l: + def iter_luas(data): + for a in data: if a.endswith('.lua'): yield a - def iter_objs(l): - for a in l: + def iter_objs(data): + for a in data: s = a[:-3] + 'raw' unit.on_luajit_21_objdump(['OUT', s, a]) yield s diff --git a/build/plugins/llvm_bc.py b/build/plugins/llvm_bc.py index ab548a3999..ded53673c9 100644 --- a/build/plugins/llvm_bc.py +++ b/build/plugins/llvm_bc.py @@ -1,5 +1,3 @@ -import sys - from _common import rootrel_arc_src, sort_by_keywords, skip_build_root diff --git a/build/plugins/pybuild.py b/build/plugins/pybuild.py index c6a8662742..b9a4343acf 100644 --- a/build/plugins/pybuild.py +++ b/build/plugins/pybuild.py @@ -16,11 +16,12 @@ DEFAULT_FLAKE8_FILE_PROCESSING_TIME = "1.5" # in seconds def _split_macro_call(macro_call, data, item_size, chunk_size=1024): index = 0 length = len(data) - offset = item_size*chunk_size + offset = item_size * chunk_size while index + 1 < length: - macro_call(data[index:index+offset]) + macro_call(data[index : index + offset]) index += offset + def is_arc_src(src, unit): return ( src.startswith('${ARCADIA_ROOT}/') @@ -82,7 +83,8 @@ def mangle(name): def parse_pyx_includes(filename, path, source_root, seen=None): - normpath = lambda *x: os.path.normpath(os.path.join(*x)) + def normpath(*args): + return os.path.normpath(os.path.join(*args)) abs_path = normpath(source_root, filename) seen = seen or set() @@ -145,7 +147,6 @@ def add_python_lint_checks(unit, py_ver, files): no_lint_value = get_no_lint_value(unit) if no_lint_value == "none": - no_lint_allowed_paths = ( "contrib/", "devtools/", @@ -195,9 +196,7 @@ def add_python_lint_checks(unit, py_ver, files): if files and unit.get('STYLE_PYTHON_VALUE') == 'yes' and is_py3(unit): resolved_files = get_resolved_files() if resolved_files: - black_cfg = ( - unit.get('STYLE_PYTHON_PYPROJECT_VALUE') or 'build/config/tests/py_style/config.toml' - ) + black_cfg = unit.get('STYLE_PYTHON_PYPROJECT_VALUE') or 'build/config/tests/py_style/config.toml' params = ['black', 'tools/black_linter/black_linter'] params += ['FILES'] + resolved_files params += ['CONFIGS', black_cfg] @@ -233,11 +232,14 @@ def onpy_srcs(unit, *args): """ @usage PY_SRCS({| CYTHONIZE_PY} {| CYTHON_C} { | TOP_LEVEL | NAMESPACE ns} Files...) - PY_SRCS() - is rule to build extended versions of Python interpreters and containing all application code in its executable file. It can be used to collect only the executables but not shared libraries, and, in particular, not to collect the modules that are imported using import directive. + PY_SRCS() - is rule to build extended versions of Python interpreters and containing all application code in its executable file. + It can be used to collect only the executables but not shared libraries, and, in particular, not to collect the modules that are imported using import directive. The main disadvantage is the lack of IDE support; There is also no readline yet. The application can be collect from any of the sources from which the C library, and with the help of PY_SRCS .py , .pyx,.proto and .swg files. - At the same time extensions for Python on C language generating from .pyx and .swg, will be registered in Python's as built-in modules, and sources on .py are stored as static data: when the interpreter starts, the initialization code will add a custom loader of these modules to sys.meta_path. - You can compile .py files as Cython sources with CYTHONIZE_PY directive (Use carefully, as build can get too slow). However, with it you won't have profiling info by default. To enable it, add "# cython: profile=True" line to the beginning of every cythonized source. + At the same time extensions for Python on C language generating from .pyx and .swg, will be registered in Python's as built-in modules, and sources on .py are stored as static data: + when the interpreter starts, the initialization code will add a custom loader of these modules to sys.meta_path. + You can compile .py files as Cython sources with CYTHONIZE_PY directive (Use carefully, as build can get too slow). However, with it you won't have profiling info by default. + To enable it, add "# cython: profile=True" line to the beginning of every cythonized source. By default .pyx files are collected as C++-extensions. To collect them as C (similar to BUILDWITH_CYTHON_C, but with the ability to specify namespace), you must specify the Directive CYTHON_C. Building with pyx automatically registers modules, you do not need to call PY_REGISTER for them __init__.py never required, but if present (and specified in PY_SRCS), it will be imported when you import package modules with __init__.py Oh. diff --git a/build/plugins/tests/fake_ymake/ya.make b/build/plugins/tests/fake_ymake/ya.make index 16de1baaac..500755e223 100644 --- a/build/plugins/tests/fake_ymake/ya.make +++ b/build/plugins/tests/fake_ymake/ya.make @@ -2,6 +2,8 @@ OWNER(g:ymake) PY23_LIBRARY() +STYLE_PYTHON() + PY_SRCS( __init__.py=ymake ) diff --git a/build/plugins/ya.make b/build/plugins/ya.make index fc69260f97..117d1918c6 100644 --- a/build/plugins/ya.make +++ b/build/plugins/ya.make @@ -1,12 +1,36 @@ OWNER(g:ymake) -PY2_LIBRARY() +PY23_LIBRARY() + +STYLE_PYTHON() PY_SRCS( TOP_LEVEL - _common.py _requirements.py + _xsyn_includes.py + bundle.py + coverage.py + cp.py + cpp_style.py + create_init_py.py + credits.py + docs.py + files.py + gobuild.py + ios_app_settings.py + ios_assets.py + java.py + large_files.py + linker_script.py + lj_archive.py + llvm_bc.py + macros_with_error.py + pybuild.py + res.py + suppressions.py + yql_python_udf.py + ytest.py ) PEERDIR( diff --git a/build/plugins/ytest.py b/build/plugins/ytest.py index 6f2cea5bec..edf060c8ae 100644 --- a/build/plugins/ytest.py +++ b/build/plugins/ytest.py @@ -11,6 +11,7 @@ import shlex import _common import lib.test_const as consts import _requirements as reqs + try: from StringIO import StringIO except ImportError: @@ -151,7 +152,9 @@ def validate_test(unit, kw): if tag.startswith('sb:'): sb_tags.append(tag) elif ':' in tag and not tag.startswith('ya:') and tag.split(':')[0] not in skip_set: - errors.append("Only [[imp]]sb:[[rst]] and [[imp]]ya:[[rst]] prefixes are allowed in system tags: {}".format(tag)) + errors.append( + "Only [[imp]]sb:[[rst]] and [[imp]]ya:[[rst]] prefixes are allowed in system tags: {}".format(tag) + ) if is_fat: if size != consts.TestSize.Large: @@ -450,7 +453,14 @@ def onadd_ytest(unit, *args): } flat_args, spec_args = _common.sort_by_keywords(keywords, args) - is_implicit_data_needed = flat_args[1] in ("unittest.py", "gunittest", "g_benchmark", "go.test", "boost.test", "fuzz.test") + is_implicit_data_needed = flat_args[1] in ( + "unittest.py", + "gunittest", + "g_benchmark", + "go.test", + "boost.test", + "fuzz.test", + ) if is_implicit_data_needed and unit.get('ADD_SRCDIR_TO_TEST_DATA') == "yes": unit.ondata_files(_common.get_norm_unit_path(unit)) @@ -641,10 +651,10 @@ def onadd_check(unit, *args): fork_mode = unit.get('TEST_FORK_MODE') or '' elif check_type == "ktlint": test_timeout = '120' - ktlint_binary = '$(KTLINT_OLD)/run.bat' if unit.get('_USE_KTLINT_OLD') == 'yes' else '$(KTLINT)/run.bat' + ktlint_binary = '$(KTLINT_OLD)/run.bat' if unit.get('_USE_KTLINT_OLD') == 'yes' else '$(KTLINT)/run.bat' extra_test_dart_data['KTLINT_BINARY'] = ktlint_binary elif check_type == "JAVA_STYLE": - if ymake_java_test and not unit.get('ALL_SRCDIRS') or '': + if ymake_java_test and not unit.get('ALL_SRCDIRS'): return if len(flat_args) < 2: raise Exception("Not enough arguments for JAVA_STYLE check") @@ -1084,7 +1094,6 @@ def _dump_test( yt_spec=None, data_files=None, ): - if test_type == "PY_TEST": script_rel_path = "py.test" else: |