diff options
author | Martin Braun <martin.braun@ettus.com> | 2019-02-03 11:37:30 +0100 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2019-02-22 16:56:52 -0800 |
commit | 51bbf548c9b442d0b53b6c8de5f89403de274424 (patch) | |
tree | 67bc4c4ffb5192afa958d92ae2679706aead9884 /host/lib/deps/pybind11/remove_comments.py | |
parent | 435a1f13b8b38e325bf46cd6bec9061ee9f0172d (diff) | |
download | uhd-51bbf548c9b442d0b53b6c8de5f89403de274424.tar.gz uhd-51bbf548c9b442d0b53b6c8de5f89403de274424.tar.bz2 uhd-51bbf548c9b442d0b53b6c8de5f89403de274424.zip |
deps: Add PyBind11
Diffstat (limited to 'host/lib/deps/pybind11/remove_comments.py')
-rw-r--r-- | host/lib/deps/pybind11/remove_comments.py | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/host/lib/deps/pybind11/remove_comments.py b/host/lib/deps/pybind11/remove_comments.py new file mode 100644 index 000000000..987c41e9d --- /dev/null +++ b/host/lib/deps/pybind11/remove_comments.py @@ -0,0 +1,55 @@ +#!/usr/bin/python3 +""" +Simple program to remove all comments from pybind11 files. +It will retain the copyright header. +""" +import re +import os + +# Note: This is the default header of the PyBind11 files, not of this file! +DEFAULT_HEADER="""/* + Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch> + + All rights reserved. Use of this source code is governed by a + BSD-style license that can be found in the LICENSE file. +*/ +""" + +def comment_remover(text): + """ + From: + https://stackoverflow.com/questions/241327/python-snippet-to-remove-c-and-c-comments + """ + def replacer(match): + s = match.group(0) + if s.startswith('/'): + return " " # note: a space and not an empty string + else: + return s + pattern = re.compile( + r'//.*?$|/\*.*?\*/|\'(?:\\.|[^\\\'])*\'|"(?:\\.|[^\\"])*"', + re.DOTALL | re.MULTILINE + ) + return re.sub(pattern, replacer, text) + +def remove_trailing_whitespace(text): + """ Remove, uh, trailing whitespace. """ + pattern = re.compile(r' +$', + re.DOTALL | re.MULTILINE + ) + return re.sub(pattern, '', text) + + +def main(): + """ Go Go Go! """ + for root, _, files in os.walk("include/pybind11"): + for fname in files: + path = os.path.join(root, fname) + print("Modifying {}...".format(path)) + new_file = comment_remover(open(os.path.join(root, fname)).read()) + new_file = remove_trailing_whitespace(new_file) + open(os.path.join(root, fname), 'w').write( + DEFAULT_HEADER + new_file) + +if __name__ == "__main__": + main() |