From 999c0e723240ee783bca17942f77a9d05bbfc168 Mon Sep 17 00:00:00 2001 From: Josh Morman <mormjb@gmail.com> Date: Thu, 23 Apr 2020 15:03:55 -0400 Subject: utils: add functionality to generate bindings This currently exists in two places 1) Bindtool (longevity TBD) which calls blocktool to parse the public header file in the include directory 2) Modtool - binding of headers added to add and bind. rm, update, info, etc still TODO --- gr-utils/modtool/core/rename.py | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'gr-utils/modtool/core/rename.py') diff --git a/gr-utils/modtool/core/rename.py b/gr-utils/modtool/core/rename.py index ac6f07215a..161d714143 100644 --- a/gr-utils/modtool/core/rename.py +++ b/gr-utils/modtool/core/rename.py @@ -70,17 +70,6 @@ class ModToolRename(ModTool): self._run_include(self.info['modname'], oldname, newname) return - def _run_swig_rename(self, swigfilename, old, new): - """ Rename SWIG includes and block_magic """ - nsubs = self._run_file_replace(swigfilename, old, new) - if nsubs < 1: - logger.info(f"Couldn't find '{old}' in file '{swigfilename}'.") - if nsubs == 2: - logger.info("Changing 'noblock' type file") - if nsubs > 3: - logger.warning(f"Hm, changed more then expected while editing {swigfilename}.") - return False - def _run_lib(self, module, old, new): ccfile = './lib/' + old + '_impl.cc' if not os.path.isfile(ccfile): # in case it is a 'noblock' -- cgit v1.2.3 From 13b6fc6435e21926977f33e90d93f6fb9530931c Mon Sep 17 00:00:00 2001 From: Josh Morman <mormjb@gmail.com> Date: Fri, 29 May 2020 10:11:43 -0400 Subject: pybind: clean up unused script and modtool tests --- gr-utils/bindtool/scripts/batch_gen_gr_modules.py | 25 ----------------------- gr-utils/modtool/core/rename.py | 1 - gr-utils/modtool/tests/test_modtool.py | 23 ++++++++++++++------- 3 files changed, 16 insertions(+), 33 deletions(-) delete mode 100644 gr-utils/bindtool/scripts/batch_gen_gr_modules.py (limited to 'gr-utils/modtool/core/rename.py') diff --git a/gr-utils/bindtool/scripts/batch_gen_gr_modules.py b/gr-utils/bindtool/scripts/batch_gen_gr_modules.py deleted file mode 100644 index a133b18cb3..0000000000 --- a/gr-utils/bindtool/scripts/batch_gen_gr_modules.py +++ /dev/null @@ -1,25 +0,0 @@ -from gnuradio.bindtool import BindingGenerator - -prefix = '/share/gnuradio/grnext' -output_dir = '/share/tmp/test_pybind' -namespace = ['gr'] -module_dir = '/share/gnuradio/grnext/src/gnuradio/gnuradio-runtime/include/gnuradio' -prefix_include_root = 'gnuradio' #pmt, gnuradio/digital, etc. - -prefix = '/share/gnuradio/grnext' -output_dir = '/share/tmp/test_pybind' -namespace = ['gr','digital'] -module_dir = '/share/gnuradio/grnext/src/gnuradio/gr-digital/include' -prefix_include_root = 'gnuradio/digital' #pmt, gnuradio/digital, etc. - -prefix = '/share/gnuradio/grnext' -output_dir = '/share/tmp/test_pybind' -namespace = ['gr','fft'] -module_dir = '/share/gnuradio/grnext/src/gnuradio/gr-fft/include' -prefix_include_root = 'gnuradio/fft' #pmt, gnuradio/digital, etc. - -import warnings -with warnings.catch_warnings(): - warnings.filterwarnings("ignore", category=DeprecationWarning) - bg = BindingGenerator(prefix, namespace, prefix_include_root, output_dir) - bg.gen_bindings(module_dir) \ No newline at end of file diff --git a/gr-utils/modtool/core/rename.py b/gr-utils/modtool/core/rename.py index 161d714143..5888f8b1b8 100644 --- a/gr-utils/modtool/core/rename.py +++ b/gr-utils/modtool/core/rename.py @@ -62,7 +62,6 @@ class ModToolRename(ModTool): oldname = self.info['oldname'] newname = self.info['newname'] logger.info(f"In module '{module}' rename block '{oldname}' to '{newname}'") - self._run_swig_rename(self._file['swig'], oldname, newname) self._run_grc_rename(self.info['modname'], oldname, newname) self._run_python_qa(self.info['modname'], oldname, newname) self._run_python(self.info['modname'], oldname, newname) diff --git a/gr-utils/modtool/tests/test_modtool.py b/gr-utils/modtool/tests/test_modtool.py index c233337b55..c118fe83bc 100644 --- a/gr-utils/modtool/tests/test_modtool.py +++ b/gr-utils/modtool/tests/test_modtool.py @@ -23,13 +23,22 @@ try: except: skip_pylint_test = True -from modtool.core import ModToolNewModule -from modtool.core import ModToolAdd -from modtool.core import ModToolDisable -from modtool.core import ModToolException -from modtool.core import ModToolMakeYAML -from modtool.core import ModToolRename -from modtool.core import ModToolRemove +try: # for debugging, full path must be given + from gnuradio.modtool.core import ModToolNewModule + from gnuradio.modtool.core import ModToolAdd + from gnuradio.modtool.core import ModToolDisable + from gnuradio.modtool.core import ModToolException + from gnuradio.modtool.core import ModToolMakeYAML + from gnuradio.modtool.core import ModToolRename + from gnuradio.modtool.core import ModToolRemove +except: + from modtool.core import ModToolNewModule + from modtool.core import ModToolAdd + from modtool.core import ModToolDisable + from modtool.core import ModToolException + from modtool.core import ModToolMakeYAML + from modtool.core import ModToolRename + from modtool.core import ModToolRemove class TestModToolCore(unittest.TestCase): """ The tests for the modtool core """ -- cgit v1.2.3 From 2af07cba8038587bc74abb0d9328a9284351f51c Mon Sep 17 00:00:00 2001 From: Josh Morman <mormjb@gmail.com> Date: Fri, 29 May 2020 13:27:54 -0400 Subject: pybind: update modtool rename --- gr-utils/modtool/core/rename.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'gr-utils/modtool/core/rename.py') diff --git a/gr-utils/modtool/core/rename.py b/gr-utils/modtool/core/rename.py index 5888f8b1b8..61f98b3722 100644 --- a/gr-utils/modtool/core/rename.py +++ b/gr-utils/modtool/core/rename.py @@ -67,6 +67,7 @@ class ModToolRename(ModTool): self._run_python(self.info['modname'], oldname, newname) self._run_lib(self.info['modname'], oldname, newname) self._run_include(self.info['modname'], oldname, newname) + self._run_pybind(self.info['modname'], oldname, newname) return def _run_lib(self, module, old, new): @@ -117,6 +118,35 @@ class ModToolRename(ModTool): else: logger.info("Not a Python block, nothing to do here...") + def _run_pybind(self, module, old, new): + path = './python/bindings/' + filename = path + old + '_python.cc' + self._run_file_replace(filename, old, new) + self._run_file_rename(path, old, new) + self._run_cmakelists(path, old, new) + # update the hash in the new file + import hashlib + hasher = hashlib.md5() + header_filename = './include/' + module + '/' + new + '.h' # note this requires _run_pybind to be called after _run_include + with open(header_filename, 'rb') as file_in: + buf = file_in.read() + hasher.update(buf) + newhash = hasher.hexdigest() + newfilename = path + new + '_python.cc' + with open(newfilename) as f: + file_txt = f.read() + m = re.search(r'BINDTOOL_HEADER_FILE_HASH\(([^\s]*)\)', file_txt) + if (m): + oldhash = m.group(1) + file_txt = re.sub(oldhash, newhash, file_txt) + with open(newfilename, "w") as f: + f.write(file_txt) + + path = './python/bindings/docstrings/' + filename = path + old + '_pydoc_template.h' + self._run_file_replace(filename, old, new) + self._run_file_rename(path, old, new) + def _run_python_qa(self, module, old, new): new = 'qa_' + new old = 'qa_' + old -- cgit v1.2.3