forked from espressif/esp-idf
fix(ldgen): use format specifiers instead of percent format
Resolve ruff's UP031 errors related to the use of percent formatting for strings. Signed-off-by: Frantisek Hrbata <frantisek.hrbata@espressif.com>
This commit is contained in:
@@ -139,7 +139,7 @@ def main():
|
||||
# ParseException is raised on incorrect grammar
|
||||
# ParseFatalException is raised on correct grammar, but inconsistent contents (ex. duplicate
|
||||
# keys, key unsupported by fragment, unexpected number of values, etc.)
|
||||
raise LdGenFailure('failed to parse %s\n%s' % (fragment_file, str(e)))
|
||||
raise LdGenFailure(f'failed to parse {fragment_file}\n{e}')
|
||||
generation_model.add_fragments_from_file(fragment_file)
|
||||
|
||||
non_contiguous_sram = sdkconfig.evaluate_expression('SOC_MEM_NON_CONTIGUOUS_SRAM')
|
||||
@@ -164,7 +164,7 @@ def main():
|
||||
) as f: # only create output file after generation has succeeded
|
||||
f.write(output.read())
|
||||
except LdGenFailure as e:
|
||||
print('linker script generation failed for %s\nERROR: %s' % (input_file.name, e))
|
||||
print(f'linker script generation failed for {input_file.name}\nERROR: {e}')
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
|
||||
@@ -359,7 +359,7 @@ class ObjectNode(EntityNode):
|
||||
|
||||
if obj_sections:
|
||||
symbol = entity.symbol
|
||||
remove_sections = [s.replace('.*', '.%s' % symbol) for s in sections if '.*' in s]
|
||||
remove_sections = [s.replace('.*', f'.{symbol}') for s in sections if '.*' in s]
|
||||
filtered_sections = [s for s in obj_sections if s not in remove_sections]
|
||||
|
||||
if set(filtered_sections) != set(obj_sections):
|
||||
@@ -542,7 +542,7 @@ class Generation:
|
||||
and mapping.name not in self.check_mapping_exceptions
|
||||
):
|
||||
if not entities.check_exists(entity):
|
||||
message = "'%s' not found" % str(entity)
|
||||
message = f"'{entity}' not found"
|
||||
raise GenerationException(message, mapping)
|
||||
|
||||
if (obj, symbol, scheme_name) in mapping.flags.keys():
|
||||
@@ -553,7 +553,7 @@ class Generation:
|
||||
if flag.target not in scheme_dictionary[scheme_name].keys() or flag.section not in [
|
||||
_s.name for _s in scheme_dictionary[scheme_name][flag.target]
|
||||
]:
|
||||
message = "%s->%s not defined in scheme '%s'" % (flag.section, flag.target, scheme_name)
|
||||
message = f"{flag.section}->{flag.target} not defined in scheme '{scheme_name}'"
|
||||
raise GenerationException(message, mapping)
|
||||
else:
|
||||
flags = None
|
||||
@@ -648,7 +648,7 @@ class Generation:
|
||||
if fragment.name in dict_to_append_to:
|
||||
stored = dict_to_append_to[fragment.name].path
|
||||
new = fragment.path
|
||||
message = "Duplicate definition of fragment '%s' found in %s and %s." % (fragment.name, stored, new)
|
||||
message = f"Duplicate definition of fragment '{fragment.name}' found in {stored} and {new}."
|
||||
raise GenerationException(message)
|
||||
|
||||
dict_to_append_to[fragment.name] = fragment
|
||||
@@ -668,6 +668,6 @@ class GenerationException(LdGenFailure):
|
||||
|
||||
def __str__(self):
|
||||
if self.fragment:
|
||||
return "%s\nIn fragment '%s' defined in '%s'." % (self.message, self.fragment.name, self.fragment.path)
|
||||
return f"{self.message}\nIn fragment '{self.fragment.name}' defined in '{self.fragment.path}'."
|
||||
else:
|
||||
return self.message
|
||||
|
||||
@@ -84,7 +84,7 @@ class LinkerScript:
|
||||
# Add information that this is a generated file.
|
||||
output_file.write('/* Automatically generated file; DO NOT EDIT */\n')
|
||||
output_file.write('/* Espressif IoT Development Framework Linker Script */\n')
|
||||
output_file.write('/* Generated from: %s */\n' % self.file)
|
||||
output_file.write(f'/* Generated from: {self.file} */\n')
|
||||
output_file.write('\n')
|
||||
|
||||
# Do the text replacement
|
||||
|
||||
@@ -25,7 +25,7 @@ class AlignAtAddress:
|
||||
self.mutable = mutable
|
||||
|
||||
def __str__(self):
|
||||
return '. = ALIGN(%d);' % self.alignment
|
||||
return f'. = ALIGN({self.alignment});'
|
||||
|
||||
def __eq__(self, other):
|
||||
return isinstance(other, AlignAtAddress) and self.alignment == other.alignment
|
||||
@@ -49,7 +49,7 @@ class SymbolAtAddress:
|
||||
self.mutable = mutable
|
||||
|
||||
def __str__(self):
|
||||
return '%s = ABSOLUTE(.);' % self.symbol
|
||||
return f'{self.symbol} = ABSOLUTE(.);'
|
||||
|
||||
def __eq__(self, other):
|
||||
return isinstance(other, SymbolAtAddress) and self.symbol == other.symbol
|
||||
@@ -97,56 +97,56 @@ class InputSectionDesc:
|
||||
|
||||
for exc in sorted(self.exclusions):
|
||||
if exc.specificity == Entity.Specificity.ARCHIVE:
|
||||
exc_string = '*%s' % (exc.archive)
|
||||
exc_string = f'*{exc.archive}'
|
||||
else:
|
||||
exc_string = '*%s:%s.*' % (exc.archive, exc.obj)
|
||||
exc_string = f'*{exc.archive}:{exc.obj}.*'
|
||||
|
||||
exclusion_strings.append(exc_string)
|
||||
|
||||
section_strings = []
|
||||
|
||||
if exclusion_strings:
|
||||
exclusion_string = 'EXCLUDE_FILE(%s)' % ' '.join(exclusion_strings)
|
||||
exclusion_string = 'EXCLUDE_FILE({})'.format(' '.join(exclusion_strings))
|
||||
|
||||
for section in sorted(self.sections):
|
||||
section_strings.append('%s %s' % (exclusion_string, section))
|
||||
section_strings.append(f'{exclusion_string} {section}')
|
||||
else:
|
||||
for section in sorted(self.sections):
|
||||
section_strings.append(section)
|
||||
|
||||
if self.sort:
|
||||
if self.sort == (None, None):
|
||||
pattern = 'SORT(%s)'
|
||||
pattern = 'SORT({})'
|
||||
elif self.sort == ('name', None):
|
||||
pattern = 'SORT_BY_NAME(%s)'
|
||||
pattern = 'SORT_BY_NAME({})'
|
||||
elif self.sort == ('alignment', None):
|
||||
pattern = 'SORT_BY_ALIGNMENT(%s)'
|
||||
pattern = 'SORT_BY_ALIGNMENT({})'
|
||||
elif self.sort == ('init_priority', None):
|
||||
pattern = 'SORT_BY_INIT_PRIORITY(%s)'
|
||||
pattern = 'SORT_BY_INIT_PRIORITY({})'
|
||||
elif self.sort == ('name', 'alignment'):
|
||||
pattern = 'SORT_BY_NAME(SORT_BY_ALIGNMENT(%s))'
|
||||
pattern = 'SORT_BY_NAME(SORT_BY_ALIGNMENT({}))'
|
||||
elif self.sort == ('alignment', 'name'):
|
||||
pattern = 'SORT_BY_ALIGNMENT(SORT_BY_NAME(%s))'
|
||||
pattern = 'SORT_BY_ALIGNMENT(SORT_BY_NAME({}))'
|
||||
elif self.sort == ('name', 'name'):
|
||||
pattern = 'SORT_BY_NAME(SORT_BY_NAME(%s))'
|
||||
pattern = 'SORT_BY_NAME(SORT_BY_NAME({}))'
|
||||
elif self.sort == ('alignment', 'alignment'):
|
||||
pattern = 'SORT_BY_ALIGNMENT(SORT_BY_ALIGNMENT(%s))'
|
||||
pattern = 'SORT_BY_ALIGNMENT(SORT_BY_ALIGNMENT({}))'
|
||||
else:
|
||||
raise Exception('Invalid sort arguments')
|
||||
|
||||
section_strings = [(pattern % s) for s in section_strings]
|
||||
section_strings = [pattern.format(s) for s in section_strings]
|
||||
|
||||
sections_string = '(%s)' % ' '.join(section_strings)
|
||||
sections_string = '({})'.format(' '.join(section_strings))
|
||||
|
||||
if self.entity.specificity == Entity.Specificity.NONE:
|
||||
entry = '*%s' % (sections_string)
|
||||
entry = f'*{sections_string}'
|
||||
elif self.entity.specificity == Entity.Specificity.ARCHIVE:
|
||||
entry = '*%s:%s' % (self.entity.archive, sections_string)
|
||||
entry = f'*{self.entity.archive}:{sections_string}'
|
||||
else:
|
||||
entry = '*%s:%s.*%s' % (self.entity.archive, self.entity.obj, sections_string)
|
||||
entry = f'*{self.entity.archive}:{self.entity.obj}.*{sections_string}'
|
||||
|
||||
if self.keep:
|
||||
res = 'KEEP(%s)' % entry
|
||||
res = f'KEEP({entry})'
|
||||
else:
|
||||
res = entry
|
||||
|
||||
|
||||
Reference in New Issue
Block a user