diff options
author | maxim-yurchuk <maxim-yurchuk@yandex-team.com> | 2024-10-09 12:29:46 +0300 |
---|---|---|
committer | maxim-yurchuk <maxim-yurchuk@yandex-team.com> | 2024-10-09 13:14:22 +0300 |
commit | 9731d8a4bb7ee2cc8554eaf133bb85498a4c7d80 (patch) | |
tree | a8fb3181d5947c0d78cf402aa56e686130179049 /contrib/libs/python/gen_includes.py | |
parent | a44b779cd359f06c3ebbef4ec98c6b38609d9d85 (diff) | |
download | ydb-9731d8a4bb7ee2cc8554eaf133bb85498a4c7d80.tar.gz |
publishFullContrib: true for ydb
<HIDDEN_URL>
commit_hash:c82a80ac4594723cebf2c7387dec9c60217f603e
Diffstat (limited to 'contrib/libs/python/gen_includes.py')
-rwxr-xr-x | contrib/libs/python/gen_includes.py | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/contrib/libs/python/gen_includes.py b/contrib/libs/python/gen_includes.py new file mode 100755 index 0000000000..1a288b8ec3 --- /dev/null +++ b/contrib/libs/python/gen_includes.py @@ -0,0 +1,67 @@ +#!/usr/bin/env python3 + +import sys +import os +import re +import errno +from os import listdir +from os.path import dirname, relpath, join + + +def ensure_dir_exists(path): + try: + os.makedirs(path) + except OSError as e: + if e.errno == errno.EEXIST and os.path.isdir(path): + pass + else: + raise + + +def make_dir(directory): + if not os.path.exists(directory): + os.makedirs(directory) + + +def files(directory): + for dirpath, dirnames, filenames in os.walk(directory): + for name in filenames: + yield relpath(join(dirpath, name), directory) + + +def headers_set(directory): + return { + f for f in files(directory) + if f.endswith('.h') and (not f.startswith('internal/') or f.startswith('internal/pycore_frame.h')) and not re.match(r'^pyconfig[.-].+\.h$', f) + } + + +if __name__ == "__main__": + + python2_path = sys.argv[1] + python3_path = sys.argv[2] + output_path = sys.argv[3] + + ensure_dir_exists(join('.', python2_path)) + ensure_dir_exists(join('.', python3_path)) + + only_headers2 = headers_set(python2_path) + only_headers3 = headers_set(python3_path) + all_headers = only_headers2 | only_headers3 + + for header in all_headers: + path = join(output_path, header) + make_dir(dirname(path)) + f = open(path, 'w') + f.write('#pragma once\n\n') + f.write('#ifdef USE_PYTHON3\n') + if (header in only_headers3): + f.write('#include <' + join(python3_path, header) + '>\n') + else: + f.write('#error "No <' + header + '> in Python3"\n') + f.write('#else\n') + if (header in only_headers2): + f.write('#include <' + join(python2_path, header) + '>\n') + else: + f.write('#error "No <' + header + '> in Python2"\n') + f.write('#endif\n') |