diff options
author | alekhgupta1441 <alekhgupta1441@gmail.com> | 2020-03-14 07:04:54 +0530 |
---|---|---|
committer | Michael Dickens <michael.dickens@ettus.com> | 2020-04-19 15:33:41 -0400 |
commit | cb4f4648815c005788a1879bdb10c58228736808 (patch) | |
tree | 1b2a7b3acfc4dab769897934da3f86d72a3af079 /gr-utils/modtool/core/add.py | |
parent | b28220713221c811fc31662472976e0d8a3dc959 (diff) |
modtool: Replaced str.format() by Python f'strings in all codes
Diffstat (limited to 'gr-utils/modtool/core/add.py')
-rw-r--r-- | gr-utils/modtool/core/add.py | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/gr-utils/modtool/core/add.py b/gr-utils/modtool/core/add.py index adacb1ef90..7be04fcfd3 100644 --- a/gr-utils/modtool/core/add.py +++ b/gr-utils/modtool/core/add.py @@ -110,7 +110,7 @@ class ModToolAdd(ModTool): def _write_tpl(self, tpl, path, fname): """ Shorthand for writing a substituted template to a file""" path_to_file = os.path.join(path, fname) - logger.info("Adding file '{}'...".format(path_to_file)) + logger.info(f"Adding file '{path_to_file}'...") with open(path_to_file, 'w') as f: f.write(render_template(tpl, **self.info)) self.scm.add_files((path_to_file,)) @@ -143,23 +143,24 @@ class ModToolAdd(ModTool): def _run_cc_qa(self): " Add C++ QA files for 3.7 API if intructed from _run_lib" - fname_qa_h = 'qa_{}.h'.format(self.info['blockname']) - fname_qa_cc = 'qa_{}.cc'.format(self.info['blockname']) + blockname_=self.info['blockname'] + fname_qa_h = f'qa_{blockname_}.h' + fname_qa_cc = f'qa_{blockname_}.cc' self._write_tpl('qa_cpp', 'lib', fname_qa_cc) self._write_tpl('qa_h', 'lib', fname_qa_h) + modname_= self.info['modname'] if self.skip_cmakefiles: return try: append_re_line_sequence(self._file['cmlib'], - r'list\(APPEND test_{}_sources.*\n'.format(self.info['modname']), - 'qa_{}.cc'.format(self.info['blockname'])) + fr'list\(APPEND test_{modname_}_sources.*\n', + f'qa_{blockname_}.cc') append_re_line_sequence(self._file['qalib'], '#include.*\n', - '#include "{}"'.format(fname_qa_h)) + f'#include "{fname_qa_h}"') append_re_line_sequence(self._file['qalib'], '(addTest.*suite.*\n|new CppUnit.*TestSuite.*\n)', - ' s->addTest(gr::{}::qa_{}::suite());'.format(self.info['modname'], - self.info['blockname']) + f' s->addTest(gr::{modname_}::qa_{blockname_}::suite());' ) self.scm.mark_files_updated((self._file['qalib'],)) except IOError: @@ -167,14 +168,16 @@ class ModToolAdd(ModTool): def _run_cc_qa_boostutf(self): " Add C++ QA files for 3.8 API if intructed from _run_lib" - fname_qa_cc = 'qa_{}.cc'.format(self.info['blockname']) + blockk_=self.info['blockname'] + fname_qa_cc = f'qa_{blockk_}.cc' self._write_tpl('qa_cpp_boostutf', 'lib', fname_qa_cc) + modd_=self.info['modname'] if self.skip_cmakefiles: return try: append_re_line_sequence(self._file['cmlib'], - r'list\(APPEND test_{}_sources.*\n'.format(self.info['modname']), - 'qa_{}.cc'.format(self.info['blockname'])) + fr'list\(APPEND test_{modd_}_sources.*\n', + f'qa_{blockk_}.cc') self.scm.mark_files_updated((self._file['cmlib'],)) except IOError: logger.warning("Can't add C++ QA files.") @@ -229,17 +232,17 @@ class ModToolAdd(ModTool): if self._get_mainswigfile() is None: logger.warning('Warning: No main swig file found.') return - logger.info("Editing {}...".format(self._file['swig'])) + swig_info=self._file['swig'] + logger.info(f"Editing {swig_info}...") mod_block_sep = '/' if self.info['version'] == '36': mod_block_sep = '_' swig_block_magic_str = render_template('swig_block_magic', **self.info) with open(self._file['swig'], 'a') as f: f.write(swig_block_magic_str) - include_str = '#include "{}{}{}.h"'.format( - {True: 'gnuradio/' + self.info['modname'], False: self.info['modname']}[self.info['is_component']], - mod_block_sep, - self.info['blockname']) + is_component = {True: 'gnuradio/' + self.info['modname'], False: self.info['modname']}[self.info['is_component']] + blockn=self.info['blockname'] + include_str = f'#include "{is_component}{mod_block_sep}{blockn}.h"' with open(self._file['swig'], 'r') as f: oldfile = f.read() if re.search('#include', oldfile): @@ -263,7 +266,8 @@ class ModToolAdd(ModTool): self.scm.mark_files_updated((os.path.join(self.info['pydir'], fname_py_qa),)) if self.skip_cmakefiles or CMakeFileEditor(self._file['cmpython']).check_for_glob('qa_*.py'): return - logger.info("Editing {}/CMakeLists.txt...".format(self.info['pydir'])) + pydir_=self.info['pydir'] + logger.info(f"Editing {pydir_}/CMakeLists.txt...") with open(self._file['cmpython'], 'a') as f: f.write( 'GR_ADD_TEST(qa_%s ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/%s)\n' % \ @@ -278,10 +282,11 @@ class ModToolAdd(ModTool): - include in __init__.py """ fname_py = self.info['blockname'] + '.py' + blockname_=self.info['blockname'] self._write_tpl('block_python', self.info['pydir'], fname_py) append_re_line_sequence(self._file['pyinit'], '(^from.*import.*\n|# import any pure.*\n)', - 'from .{} import {}'.format(self.info['blockname'], self.info['blockname'])) + f'from .{blockname_} import {blockname_}') self.scm.mark_files_updated((self._file['pyinit'],)) if self.skip_cmakefiles: return |