def run(self): """ Go, go, go! """ # This portion will be covered by the CLI if not self.cli: self.validate() if not have_bindtool: logger.error( "Bindtool required to generate bindings ... Aborting") return with warnings.catch_warnings(): warnings.filterwarnings("ignore", category=DeprecationWarning) blocknames_to_process = [] if self.info['blockname']: # A complete block name was given blocknames_to_process.append(self.info['blockname']) elif self.info['pattern']: # A regex resembling one or several blocks were given blocknames_to_process = get_block_names( self.info['pattern'], self.info['modname']) else: raise ModToolException("No block name or regex was specified!") bg = BindingGenerator(prefix=gr.prefix(), namespace=['gr', self.info['modname']], prefix_include_root=self.info['modname'], output_dir=os.path.join(self.dir, 'python'), define_symbols=self.info['define_symbols'], addl_includes=self.info['addl_includes']) files_to_process = [ os.path.join(self.dir, self.info['includedir'], f'{blockname}.h') for blockname in blocknames_to_process ] for file_to_process in files_to_process: bg.gen_file_binding(file_to_process)
def run(self): """ Go, go, go! """ # This portion will be covered by the CLI if not self.cli: self.validate() if not have_bindtool: logger.error( "Bindtool required to generate bindings ... Aborting") return with warnings.catch_warnings(): warnings.filterwarnings("ignore", category=DeprecationWarning) file_to_process = os.path.join(self.dir, self.info['includedir'], self.info['blockname'] + '.h') bg = BindingGenerator(prefix=gr.prefix(), namespace=['gr', self.info['modname']], prefix_include_root=self.info['modname'], output_dir=os.path.join(self.dir, 'python')) bg.gen_file_binding(file_to_process)
parser.add_argument('--flag_pygccxml', default='0') args = parser.parse_args() prefix = args.prefix output_dir = args.output_dir defines = tuple(','.join(args.defines).split(',')) includes = ','.join(args.include) name = args.module namespace = ['gr', name] prefix_include_root = name with warnings.catch_warnings(): warnings.filterwarnings("ignore", category=DeprecationWarning) bg = BindingGenerator(prefix, namespace, prefix_include_root, output_dir, define_symbols=defines, addl_includes=includes, catch_exceptions=False, write_json_output=False, status_output=args.status, flag_automatic=True if args.flag_automatic.lower() in ['1', 'true'] else False, flag_pygccxml=True if args.flag_pygccxml.lower() in ['1', 'true'] else False) bg.gen_file_binding(args.filename)
def _run_pybind(self): """ Do everything that needs doing in the python bindings subdir. - add blockname_python.cc - add reference and call to bind_blockname() - include them into CMakeLists.txt """ bindings_dir = os.path.join(self.info['pydir'], 'bindings') # Generate bindings cc file fname_cc = self.info['blockname'] + '_python.cc' fname_pydoc_h = os.path.join( 'docstrings', self.info['blockname'] + '_pydoc_template.h') # Update python_bindings.cc ed = CPPFileEditor(self._file['ccpybind']) ed.append_value( '// BINDING_FUNCTION_PROTOTYPES(', '// ) END BINDING_FUNCTION_PROTOTYPES', 'void bind_' + self.info['blockname'] + '(py::module& m);') ed.append_value('// BINDING_FUNCTION_CALLS(', '// ) END BINDING_FUNCTION_CALLS', 'bind_' + self.info['blockname'] + '(m);') ed.write() self.scm.mark_files_updated((self._file['ccpybind'])) if self.info['version'] in ['310']: prefix_include_root = '/'.join(('gnuradio', self.info['modname'])) else: prefix_include_root = self.info['modname'] bg = BindingGenerator(prefix=gr.prefix(), namespace=['gr', self.info['modname']], prefix_include_root=prefix_include_root) block_base = "" if self.info['blocktype'] in ('source', 'sink', 'sync', 'decimator', 'interpolator', 'general', 'hier', 'tagged_stream'): block_base = code_generator.GRTYPELIST[self.info['blocktype']] import hashlib header_file = self.info['blockname'] + '.h' hasher = hashlib.md5() with open(os.path.join(self.info['includedir'], header_file), 'rb') as file_in: buf = file_in.read() hasher.update(buf) md5hash = hasher.hexdigest() header_info = { "module_name": self.info['modname'], "filename": header_file, "md5hash": md5hash, "namespace": { "name": "::".join(['gr', self.info['modname']]), "enums": [], "variables": [], "classes": [{ "name": self.info['blockname'], "member_functions": [{ "name": "make", "return_type": "::".join(("gr", self.info['modname'], self.info['blockname'], "sptr")), "has_static": "1", "arguments": [] }], "bases": ["::", "gr", block_base], "constructors": [{ "name": self.info['blockname'], "arguments": [] }] }], "free_functions": [], "namespaces": [] } } # def gen_pybind_cc(self, header_info, base_name): pydoc_txt = bg.gen_pydoc_h(header_info, self.info['blockname']) path_to_file = os.path.join(bindings_dir, fname_pydoc_h) logger.info("Adding file '{}'...".format(path_to_file)) with open(path_to_file, 'w') as f: f.write(pydoc_txt) self.scm.add_files((path_to_file, )) cc_txt = bg.gen_pybind_cc(header_info, self.info['blockname']) path_to_file = os.path.join(bindings_dir, fname_cc) logger.info("Adding file '{}'...".format(path_to_file)) with open(path_to_file, 'w') as f: f.write(cc_txt) self.scm.add_files((path_to_file, )) if not self.skip_cmakefiles: ed = CMakeFileEditor(self._file['cmpybind']) cmake_list_var = 'APPEND {}_python_files'.format( self.info['modname']) ed.append_value('list', fname_cc, to_ignore_start=cmake_list_var, to_ignore_end='python_bindings.cc') ed.write() self.scm.mark_files_updated((self._file['cmpybind']))
output_dir = args.output_dir includes = args.include for name in args.names: if name not in ['gr', 'pmt']: namespace = ['gr', name.replace("-", "_")] module_dir = os.path.abspath( os.path.join(args.src, 'gr-' + name, 'include')) prefix_include_root = 'gnuradio/' + name # pmt, gnuradio/digital, etc. else: namespace = [name] module_dir = os.path.abspath( os.path.join(args.src, 'gnuradio-runtime', 'include')) if name == 'gr': prefix_include_root = 'gnuradio' module_dir = os.path.join(module_dir, 'gnuradio') elif name == 'pmt': prefix_include_root = 'pmt' module_dir = os.path.join(module_dir, 'pmt') import warnings with warnings.catch_warnings(): warnings.filterwarnings("ignore", category=DeprecationWarning) bg = BindingGenerator(prefix, namespace, prefix_include_root, output_dir, addl_includes=includes, match_include_structure=True, write_json_output=True) bg.gen_bindings(module_dir)
import argparse import os from gnuradio.bindtool import BindingGenerator import pathlib parser = argparse.ArgumentParser(description='Bind a GR header file from the generated json') parser.add_argument('pathnames', type=str, nargs='+', help='Json files to bind') args = parser.parse_args() bg = BindingGenerator() for p in args.pathnames: bg.bind_from_json(p)