diff options
author | alexv-smirnov <alex@ydb.tech> | 2023-06-13 11:05:01 +0300 |
---|---|---|
committer | alexv-smirnov <alex@ydb.tech> | 2023-06-13 11:05:01 +0300 |
commit | bf0f13dd39ee3e65092ba3572bb5b1fcd125dcd0 (patch) | |
tree | 1d1df72c0541a59a81439842f46d95396d3e7189 /build/plugins/docs.py | |
parent | 8bfdfa9a9bd19bddbc58d888e180fbd1218681be (diff) | |
download | ydb-bf0f13dd39ee3e65092ba3572bb5b1fcd125dcd0.tar.gz |
add ymake export to ydb
Diffstat (limited to 'build/plugins/docs.py')
-rw-r--r-- | build/plugins/docs.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/build/plugins/docs.py b/build/plugins/docs.py new file mode 100644 index 0000000000..92371a4c4f --- /dev/null +++ b/build/plugins/docs.py @@ -0,0 +1,53 @@ +import json + + +def extract_macro_calls(unit, macro_value_name): + if not unit.get(macro_value_name): + return [] + + return filter(None, unit.get(macro_value_name).replace('$' + macro_value_name, '').split()) + + +def macro_calls_to_dict(unit, calls): + def split_args(arg): + if arg is None: + return None + + kv = filter(None, arg.split('=')) + if len(kv) != 2: + unit.message( + [ + 'error', + 'Invalid variables specification "{}": value expected to be in form %name%=%value% (with no spaces)'.format( + arg + ), + ] + ) + return None + + return kv + + return dict(filter(None, map(split_args, calls))) + + +def get_variables(unit): + orig_variables = macro_calls_to_dict(unit, extract_macro_calls(unit, '_DOCS_VARS_VALUE')) + return {k: unit.get(k) or v for k, v in orig_variables.items()} + + +def onprocess_docs(unit, *args): + if unit.enabled('_DOCS_USE_PLANTUML'): + unit.on_docs_yfm_use_plantuml([]) + + if unit.get('_DOCS_DIR_VALUE') == '': + unit.on_yfm_docs_dir([unit.get('_YFM_DOCS_DIR_DEFAULT_VALUE')]) + + variables = get_variables(unit) + if variables: + unit.set(['_DOCS_VARS_FLAG', '--vars {}'.format(json.dumps(json.dumps(variables, sort_keys=True)))]) + + +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 variables.items()])]) |