From ec51b6cca9dd99701e8b8e5783396ad61e29174c Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Sun, 25 Dec 2016 15:44:45 +0100 Subject: [PATCH] Switch from cheetah to mako and six --- .../volk_gnsssdr_module/volk_gnsssdr/CMakeLists.txt | 10 ++++++++-- .../volk_gnsssdr/cmake/Modules/VolkPython.cmake | 9 +++++---- .../volk_gnsssdr/gen/volk_gnsssdr_arch_defs.py | 8 ++++++-- .../volk_gnsssdr/gen/volk_gnsssdr_compile_utils.py | 8 +++++--- .../volk_gnsssdr/gen/volk_gnsssdr_kernel_defs.py | 10 ++++++---- .../volk_gnsssdr/gen/volk_gnsssdr_machine_defs.py | 7 +++++-- .../volk_gnsssdr/gen/volk_gnsssdr_tmpl_utils.py | 4 +++- .../volk_gnsssdr/python/volk_gnsssdr_modtool/cfg.py | 10 +++------- .../volk_gnsssdr_modtool_generate.py | 9 +++++---- 9 files changed, 46 insertions(+), 29 deletions(-) diff --git a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/CMakeLists.txt b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/CMakeLists.txt index 1b6bb6067..1c455b99e 100644 --- a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/CMakeLists.txt +++ b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/CMakeLists.txt @@ -74,17 +74,23 @@ SET(CROSSCOMPILE_MULTILIB ${CROSSCOMPILE_MULTILIB} CACHE STRING "Define \"true\" # Python include(VolkPython) #sets PYTHON_EXECUTABLE and PYTHON_DASH_B -VOLK_PYTHON_CHECK_MODULE("python >= 2.5" sys "sys.version.split()[0] >= '2.5'" PYTHON_MIN_VER_FOUND) +VOLK_PYTHON_CHECK_MODULE("python >= 2.7" sys "sys.version.split()[0] >= '2.7'" PYTHON_MIN_VER_FOUND) VOLK_PYTHON_CHECK_MODULE("Cheetah >= 2.0.0" Cheetah "Cheetah.Version >= '2.0.0'" CHEETAH_FOUND) +VOLK_PYTHON_CHECK_MODULE("six - python 2 and 3 compatibility library" six "True" SIX_FOUND) if(NOT PYTHON_MIN_VER_FOUND) - message(FATAL_ERROR "Python 2.5 or greater required to build VOLK_GNSSSDR") + message(FATAL_ERROR "Python 2.7 or greater required to build VOLK_GNSSSDR") endif() # Cheetah if(NOT CHEETAH_FOUND) message(FATAL_ERROR "Cheetah templates required to build VOLK_GNSSSDR") endif() +# Six +if(NOT SIX_FOUND) + message(FATAL_ERROR "six - python 2 and 3 compatibility library required to build VOLK") +endif() + # Boost if(MSVC) diff --git a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cmake/Modules/VolkPython.cmake b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cmake/Modules/VolkPython.cmake index 0b8d07de8..dc6571e93 100644 --- a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cmake/Modules/VolkPython.cmake +++ b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cmake/Modules/VolkPython.cmake @@ -36,11 +36,12 @@ if(PYTHON_EXECUTABLE) else(PYTHON_EXECUTABLE) #use the built-in find script + set(Python_ADDITIONAL_VERSIONS 3.4 3.5 3.6) find_package(PythonInterp 2) #and if that fails use the find program routine if(NOT PYTHONINTERP_FOUND) - find_program(PYTHON_EXECUTABLE NAMES python python2 python2.7 python2.6 python2.5) + find_program(PYTHON_EXECUTABLE NAMES python python2 python2.7 python3) if(PYTHON_EXECUTABLE) set(PYTHONINTERP_FOUND TRUE) endif(PYTHON_EXECUTABLE) @@ -100,7 +101,7 @@ endmacro(VOLK_PYTHON_CHECK_MODULE) if(NOT DEFINED VOLK_PYTHON_DIR) execute_process(COMMAND ${PYTHON_EXECUTABLE} -c " from distutils import sysconfig -print sysconfig.get_python_lib(plat_specific=True, prefix='') +print(sysconfig.get_python_lib(plat_specific=True, prefix='')) " OUTPUT_VARIABLE VOLK_PYTHON_DIR OUTPUT_STRIP_TRAILING_WHITESPACE ) endif() @@ -113,7 +114,7 @@ file(TO_CMAKE_PATH ${VOLK_PYTHON_DIR} VOLK_PYTHON_DIR) function(VOLK_UNIQUE_TARGET desc) file(RELATIVE_PATH reldir ${PROJECT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}) execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import re, hashlib -unique = hashlib.md5('${reldir}${ARGN}').hexdigest()[:5] +unique = hashlib.md5(b'${reldir}${ARGN}').hexdigest()[:5] print(re.sub('\\W', '_', '${desc} ${reldir} ' + unique))" OUTPUT_VARIABLE _target OUTPUT_STRIP_TRAILING_WHITESPACE) add_custom_target(${_target} ALL DEPENDS ${ARGN}) @@ -230,7 +231,7 @@ endfunction(VOLK_PYTHON_INSTALL) file(WRITE ${PROJECT_BINARY_DIR}/python_compile_helper.py " import sys, py_compile files = sys.argv[1:] -srcs, gens = files[:len(files)/2], files[len(files)/2:] +srcs, gens = files[:len(files)//2], files[len(files)//2:] for src, gen in zip(srcs, gens): py_compile.compile(file=src, cfile=gen, doraise=True) ") diff --git a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/gen/volk_gnsssdr_arch_defs.py b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/gen/volk_gnsssdr_arch_defs.py index 0285cb957..d1e656d70 100644 --- a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/gen/volk_gnsssdr_arch_defs.py +++ b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/gen/volk_gnsssdr_arch_defs.py @@ -18,6 +18,10 @@ # along with GNSS-SDR. If not, see . # +from __future__ import print_function + +import six + archs = list() arch_dict = dict() @@ -81,8 +85,8 @@ for arch_xml in archs_xml: if not flags.has_key(name): flags[name] = list() flags[name].append(flag_xml.firstChild.data) #force kwargs keys to be of type str, not unicode for py25 - kwargs = dict((str(k), v) for k, v in kwargs.iteritems()) + kwargs = dict((str(k), v) for k, v in six.iteritems(kwargs)) register_arch(flags=flags, checks=checks, **kwargs) if __name__ == '__main__': - print archs + print(archs) diff --git a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/gen/volk_gnsssdr_compile_utils.py b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/gen/volk_gnsssdr_compile_utils.py index 70eea8ab6..3ddc204d3 100644 --- a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/gen/volk_gnsssdr_compile_utils.py +++ b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/gen/volk_gnsssdr_compile_utils.py @@ -18,6 +18,8 @@ # along with GNSS-SDR. If not, see . # +from __future__ import print_function + import optparse import volk_gnsssdr_arch_defs import volk_gnsssdr_machine_defs @@ -28,7 +30,7 @@ def do_arch_flags_list(compiler): if not arch.is_supported(compiler): continue fields = [arch.name] + arch.get_flags(compiler) output.append(','.join(fields)) - print ';'.join(output) + print(';'.join(output)) def do_machines_list(arch_names): output = list() @@ -36,14 +38,14 @@ def do_machines_list(arch_names): machine_arch_set = set(machine.arch_names) if set(arch_names).intersection(machine_arch_set) == machine_arch_set: output.append(machine.name) - print ';'.join(output) + print(';'.join(output)) def do_machine_flags_list(compiler, machine_name): output = list() machine = volk_gnsssdr_machine_defs.machine_dict[machine_name] for arch in machine.archs: output.extend(arch.get_flags(compiler)) - print ' '.join(output) + print(' '.join(output)) def main(): parser = optparse.OptionParser() diff --git a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/gen/volk_gnsssdr_kernel_defs.py b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/gen/volk_gnsssdr_kernel_defs.py index d6beb370c..5e457e6af 100644 --- a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/gen/volk_gnsssdr_kernel_defs.py +++ b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/gen/volk_gnsssdr_kernel_defs.py @@ -19,6 +19,8 @@ # +from __future__ import print_function + import os import re import sys @@ -98,9 +100,9 @@ def split_into_nested_ifdef_sections(code): def print_sections(sections, indent = ' '): for header, body in sections: if header == 'text': - print indent, ('\n'+indent).join(body.splitlines()) + print(indent, ('\n'+indent).join(body.splitlines())) continue - print indent.replace(' ', '-') + '>', header + print(indent.replace(' ', '-') + '>', header) print_sections(body, indent + ' ') ######################################################################## @@ -136,7 +138,7 @@ class impl_class: arg_type, arg_name = m.groups() self.args.append((arg_type, arg_name)) except Exception as ex: - raise Exception, 'I cant parse the function prototype from: %s in %s\n%s'%(kern_name, body, ex) + raise Exception('I cant parse the function prototype from: %s in %s\n%s'%(kern_name, body, ex)) assert self.name self.is_aligned = self.name.startswith('a_') @@ -206,4 +208,4 @@ kernel_files = glob.glob(os.path.join(srcdir, "kernels", "volk_gnsssdr", "*.h")) kernels = map(kernel_class, kernel_files) if __name__ == '__main__': - print kernels + print(kernels) diff --git a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/gen/volk_gnsssdr_machine_defs.py b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/gen/volk_gnsssdr_machine_defs.py index 7833b0a95..bd68c2326 100644 --- a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/gen/volk_gnsssdr_machine_defs.py +++ b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/gen/volk_gnsssdr_machine_defs.py @@ -17,6 +17,9 @@ # You should have received a copy of the GNU General Public License # along with GNSS-SDR. If not, see . # +from __future__ import print_function + +import six from volk_gnsssdr_arch_defs import arch_dict @@ -70,8 +73,8 @@ for machine_xml in machines_xml: except: pass kwargs['archs'] = kwargs['archs'].split() #force kwargs keys to be of type str, not unicode for py25 - kwargs = dict((str(k), v) for k, v in kwargs.iteritems()) + kwargs = dict((str(k), v) for k, v in six.iteritems(kwargs)) register_machine(**kwargs) if __name__ == '__main__': - print machines + print(machines) diff --git a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/gen/volk_gnsssdr_tmpl_utils.py b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/gen/volk_gnsssdr_tmpl_utils.py index 337387766..af3147ee3 100644 --- a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/gen/volk_gnsssdr_tmpl_utils.py +++ b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/gen/volk_gnsssdr_tmpl_utils.py @@ -18,6 +18,8 @@ # along with GNSS-SDR. If not, see . # +from __future__ import print_function + import os import re import sys @@ -67,7 +69,7 @@ def main(): output = __parse_tmpl(open(opts.input).read(), args=args) if opts.output: open(opts.output, 'w').write(output) - else: print output + else: print(output) if __name__ == '__main__': main() diff --git a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/python/volk_gnsssdr_modtool/cfg.py b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/python/volk_gnsssdr_modtool/cfg.py index 9128535ea..899950354 100644 --- a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/python/volk_gnsssdr_modtool/cfg.py +++ b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/python/volk_gnsssdr_modtool/cfg.py @@ -19,6 +19,8 @@ # # +from __future__ import print_function + import ConfigParser import sys import os @@ -70,7 +72,7 @@ class volk_gnsssdr_modtool_config: elif os.path.exists(default): icfg.read(default) else: - print "Initializing config file..." + print("Initializing config file...") icfg.add_section(self.config_name) for kn in self.config_defaults: rv = raw_input("%s: "%(kn)) @@ -95,9 +97,3 @@ class volk_gnsssdr_modtool_config: retval[i[0]] = i[1] return retval - - - - - - diff --git a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/python/volk_gnsssdr_modtool/volk_gnsssdr_modtool_generate.py b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/python/volk_gnsssdr_modtool/volk_gnsssdr_modtool_generate.py index 8928e7c5c..31a48e500 100644 --- a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/python/volk_gnsssdr_modtool/volk_gnsssdr_modtool_generate.py +++ b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/python/volk_gnsssdr_modtool/volk_gnsssdr_modtool_generate.py @@ -18,6 +18,7 @@ # the Free Software Foundation, Inc., 51 Franklin Street, # Boston, MA 02110-1301, USA. # +from __future__ import print_function import os import glob @@ -225,14 +226,14 @@ class volk_gnsssdr_modtool: for kernel in search_kernels: infile = os.path.join(inpath, 'kernels/' + top[:-1] + '/' + top + kernel.pattern + '.h'); - print "Removing kernel %s"%(kernel.pattern) + print("Removing kernel %s" % kernel.pattern) if os.path.exists(infile): os.remove(infile); # remove the orc proto-kernels if they exist. There are no puppets here # so just need to glob for files matching kernel name - print glob.glob(inpath + '/orc/' + top + name + '*.orc'); + print(glob.glob(inpath + '/kernel/volk/asm/orc/' + top + name + '*.orc')) for orcfile in glob.glob(inpath + '/orc/' + top + name + '*.orc'): - print orcfile + print(orcfile) if(os.path.exists(orcfile)): os.remove(orcfile); @@ -294,7 +295,7 @@ class volk_gnsssdr_modtool: open(dest, 'a').write(otherline); for kernel in search_kernels: - print "Adding kernel %s from module %s"%(kernel.pattern,base) + print("Adding kernel %s from module %s" % (kernel.pattern, base)) infile = open(os.path.join(inpath, 'lib/testqa.cc')); otherinfile = open(os.path.join(self.my_dict['destination'], 'volk_gnsssdr_' + self.my_dict['name'], 'lib/testqa.cc'));