From 6b7ba7da85eea87cdd21a5bcf280f758e46d396c Mon Sep 17 00:00:00 2001 From: Nick Morrott Date: Thu, 8 Feb 2024 18:40:06 +0000 Subject: [PATCH] Use raw strings in re.match due to invalid escape sequences in Python >= 3.6 --- project_generator/tools/coide.py | 4 ++-- project_generator/tools/iar.py | 11 +++++------ project_generator/tools/uvision.py | 4 ++-- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/project_generator/tools/coide.py b/project_generator/tools/coide.py index 61652689..b148fc1e 100644 --- a/project_generator/tools/coide.py +++ b/project_generator/tools/coide.py @@ -148,7 +148,7 @@ def _export_single_project(self): if expanded_dic['template']: for template in expanded_dic['template']: template = join(getcwd(), template) - if splitext(template)[1] == '.coproj' or re.match('.*\.coproj.tmpl$', template): + if splitext(template)[1] == '.coproj' or re.match(r".*\.coproj.tmpl$", template): try: coproj_dic = xmltodict.parse(open(template)) except IOError: @@ -161,7 +161,7 @@ def _export_single_project(self): # template overrides what is set in the yaml files for template in self.env_settings.templates['coide']: template = join(getcwd(), template) - if splitext(template)[1] == '.coproj' or re.match('.*\.coproj.tmpl$', template): + if splitext(template)[1] == '.coproj' or re.match(r".*\.coproj.tmpl$", template): try: coproj_dic = xmltodict.parse(open(template)) except IOError: diff --git a/project_generator/tools/iar.py b/project_generator/tools/iar.py index 4d7f3c18..99875a9c 100644 --- a/project_generator/tools/iar.py +++ b/project_generator/tools/iar.py @@ -372,14 +372,14 @@ def _export_single_project(self): for template in expanded_dic['template']: template = join(getcwd(), template) # we support .ewp or .ewp.tmpl templates - if os.path.splitext(template)[1] == '.ewp' or re.match('.*\.ewp.tmpl$', template): + if os.path.splitext(template)[1] == '.ewp' or re.match(r".*\.ewp.tmpl$", template): try: ewp_dic = xmltodict.parse(open(template,'rb'), dict_constructor=dict) template_ewp = True except IOError: logger.info("Template file %s not found" % template) ewp_dic = xmltodict.parse(open(self.ewp_file,'rb').read()) - if os.path.splitext(template)[1] == '.ewd' or re.match('.*\.ewd.tmpl$', template): + if os.path.splitext(template)[1] == '.ewd' or re.match(r".*\.ewd.tmpl$", template): try: ewd_dic = xmltodict.parse(open(template,'rb'), dict_constructor=dict) template_ewd = True @@ -399,14 +399,14 @@ def _export_single_project(self): # template overrides what is set in the yaml files for template in self.env_settings.templates['iar']: template = join(getcwd(), template) - if os.path.splitext(template)[1] == '.ewp' or re.match('.*\.ewp.tmpl$', template): + if os.path.splitext(template)[1] == '.ewp' or re.match(r".*\.ewp.tmpl$", template): try: ewp_dic = xmltodict.parse(open(template,'rb'), dict_constructor=dict) template_ewp = True except IOError: logger.info("Template file %s not found" % template) ewp_dic = xmltodict.parse(open(self.ewp_file,'rb').read()) - if os.path.splitext(template)[1] == '.ewd' or re.match('.*\.ewd.tmpl$', template): + if os.path.splitext(template)[1] == '.ewd' or re.match(r".*\.ewd.tmpl$", template): # get ewd template try: ewd_dic = xmltodict.parse(open(template,'rb'), dict_constructor=dict) @@ -518,9 +518,8 @@ def _generate_eww_file(self): def _parse_subprocess_output(self, output): num_errors = 0 lines = output.split("\n") - error_re = '\s*Total number of errors:\s*(\d+)\s*' for line in lines: - m = re.match(error_re, line) + m = re.match(r"\s*Total number of errors:\s*(\d+)\s*", line) if m is not None: num_errors = m.group(1) return int(num_errors) diff --git a/project_generator/tools/uvision.py b/project_generator/tools/uvision.py index aae0cb12..58b5fde5 100644 --- a/project_generator/tools/uvision.py +++ b/project_generator/tools/uvision.py @@ -403,7 +403,7 @@ def _export_single_project(self, tool_name): for template in expanded_dic['template']: template = join(getcwd(), template) if os.path.splitext(template)[1] == '.uvproj' or os.path.splitext(template)[1] == '.uvprojx' or \ - re.match('.*\.uvproj.tmpl$', template) or re.match('.*\.uvprojx.tmpl$', template): + re.match(r".*\.uvproj.tmpl$", template) or re.match(r".*\.uvprojx.tmpl$", template): try: uvproj_dic = xmltodict.parse(open(template, encoding="utf8").read()) except IOError: @@ -417,7 +417,7 @@ def _export_single_project(self, tool_name): for template in self.env_settings.templates['uvision']: template = join(getcwd(), template) if os.path.splitext(template)[1] == '.uvproj' or os.path.splitext(template)[1] == '.uvprojx' or \ - re.match('.*\.uvproj.tmpl$', template) or re.match('.*\.uvprojx.tmpl$', template): + re.match(r".*\.uvproj.tmpl$", template) or re.match(r".*\.uvprojx.tmpl$", template): try: uvproj_dic = xmltodict.parse(open(template, encoding="utf8").read()) except IOError: