diff options
author | spreis <spreis@yandex-team.com> | 2023-10-13 06:41:33 +0300 |
---|---|---|
committer | spreis <spreis@yandex-team.com> | 2023-10-13 07:08:24 +0300 |
commit | 94d77db087cf83003ca0c6f276dbb827099688ad (patch) | |
tree | 1adeb0e4918307588f1fad4898b7d3e2deca69dc | |
parent | 7bf454679ed7688910a47b369875c0ebdd77f53c (diff) | |
download | ydb-94d77db087cf83003ca0c6f276dbb827099688ad.tar.gz |
support dash in Python version of PROTO_LIBRARY
-rw-r--r-- | build/conf/proto.conf | 4 | ||||
-rw-r--r-- | build/plugins/pybuild.py | 2 | ||||
-rw-r--r-- | build/scripts/gen_py_protos.py | 42 |
3 files changed, 32 insertions, 16 deletions
diff --git a/build/conf/proto.conf b/build/conf/proto.conf index 1c2961e626..a840bd2951 100644 --- a/build/conf/proto.conf +++ b/build/conf/proto.conf @@ -427,7 +427,7 @@ macro _PY_PROTO_CMD(File) { # tag:proto tag:python-specific macro _PY_PROTO_CMD_INTERNAL(File) { - .CMD=${cwd;rootdir;input:File} $GEN_PY_PROTOS --suffixes $PY_PROTO_SUFFIXES $PY_PROTO_MYPY_SUFFIX -- $_PY_PROTO_CMD_BASE($File __int___pb2.py $PY_PROTO_OPTS $PY_PROTO_OUTS_INTERNAL ${hide;kv:"ext_out_name_for_${nopath;noext;suf=__int___pb2.py:File} ${nopath;noext;suf=_pb2.py:File}"} $PY_PROTO_MYPY_PLUGIN_INTERNAL) + .CMD=${cwd;rootdir;input:File} $GEN_PY_PROTOS --suffixes $PY_PROTO_SUFFIXES $PY_PROTO_MYPY_SUFFIX --input ${input;rootrel:File} --ns /$PROTO_NAMESPACE -- $_PY_PROTO_CMD_BASE($File __int___pb2.py $PY_PROTO_OPTS $PY_PROTO_OUTS_INTERNAL ${hide;kv:"ext_out_name_for_${nopath;noext;suf=__int___pb2.py:File} ${nopath;noext;suf=_pb2.py:File}"} $PY_PROTO_MYPY_PLUGIN_INTERNAL) } # tag:proto tag:java-specific @@ -503,7 +503,7 @@ macro _PY_EVLOG_CMD(File) { # tag:python-specific tag:proto macro _PY_EVLOG_CMD_INTERNAL(File) { - .CMD=${cwd;rootdir;input:File} $GEN_PY_PROTOS --suffixes $PY_EVLOG_SUFFIXES -- $_PY_EVLOG_CMD_BASE($File __int___ev_pb2.py ${hide;kv:"ext_out_name_for_${nopath;noext;suf=__int___ev_pb2.py:File} ${nopath;noext;suf=_ev_pb2.py:File}"}) + .CMD=${cwd;rootdir;input:File} $GEN_PY_PROTOS --suffixes $PY_EVLOG_SUFFIXES --input ${input;rootrel:File} --ns /$PROTO_NAMESPACE -- $_PY_EVLOG_CMD_BASE($File __int___ev_pb2.py ${hide;kv:"ext_out_name_for_${nopath;noext;suf=__int___ev_pb2.py:File} ${nopath;noext;suf=_ev_pb2.py:File}"}) } # tag:java-specific tag:proto diff --git a/build/plugins/pybuild.py b/build/plugins/pybuild.py index b91fd61a17..1823b82387 100644 --- a/build/plugins/pybuild.py +++ b/build/plugins/pybuild.py @@ -373,6 +373,8 @@ def onpy_srcs(unit, *args): mod_root_path = root_rel_path[: -(len(path) + 1)] py_namespaces.setdefault(mod_root_path, set()).add(ns if ns else '.') mod = ns + mod_name + if in_proto_library: + mod = mod.replace('-', '_') if main_mod: py_main(unit, mod + ":main") diff --git a/build/scripts/gen_py_protos.py b/build/scripts/gen_py_protos.py index 08397472f9..606f50dfb6 100644 --- a/build/scripts/gen_py_protos.py +++ b/build/scripts/gen_py_protos.py @@ -10,9 +10,16 @@ import re OUT_DIR_ARG = '--python_out=' + +def _noext(fname): + return fname[:fname.rfind('.')] + + def main(): parser = argparse.ArgumentParser() parser.add_argument("--suffixes", nargs="*", default=[]) + parser.add_argument("--input") + parser.add_argument("--ns") parser.add_argument("protoc_args", nargs=argparse.REMAINDER) script_args = parser.parse_args() @@ -46,20 +53,27 @@ def main(): retcode = subprocess.call(args) assert not retcode, 'Protoc failed for command {}'.format(' '.join(args)) - for root_temp, dirs, files in os.walk(out_dir_temp): - sub_dir = path.relpath(root_temp, out_dir_temp) - root_orig = path.join(out_dir_orig, sub_dir) - for d in dirs: - d_orig = path.join(root_orig, d) - if not path.exists(d_orig): - os.mkdir(d_orig) - for f in files: - f_orig = f - for suf in script_args.suffixes: - if f.endswith(suf): - f_orig = f[:-len(suf)] + "__int__" + suf - break - os.rename(path.join(root_temp, f), path.join(root_orig, f_orig)) + temp_name = out_dir_temp + orig_name = out_dir_orig + dir_name, file_name = path.split(script_args.input[len(script_args.ns) - 1:]) + for part in dir_name.split('/'): + temp_part = part.replace('-','_') + temp_name = path.join(temp_name, temp_part) + assert(path.exists(temp_name)) + + orig_name = path.join(orig_name, part) + if not path.exists(orig_name): + os.mkdir(orig_name) + + orig_base_name = _noext(file_name) + temp_base_name = orig_base_name.replace('-','_') + for suf in script_args.suffixes: + temp_file_name = path.join(temp_name, temp_base_name + suf) + assert(path.exists(temp_file_name)) + + orig_file_name = path.join(orig_name, orig_base_name + '__int__' + suf) + os.rename(temp_file_name, orig_file_name) + shutil.rmtree(out_dir_temp) |