refactor: upgrade code to >=python3.7 (pre-commit)

Part-of: <https://dev.funkwhale.audio/funkwhale/funkwhale/-/merge_requests/2189>
This commit is contained in:
jo 2022-11-23 22:36:56 +01:00 committed by Marge
commit 8d9946d35a
143 changed files with 454 additions and 582 deletions

View file

@ -57,7 +57,7 @@ def contextualize(old_po, new_po, edit=False):
)
matches = match(missing, old)
found = [m for m in matches if m[1] is not None]
print("Found {} matching entries".format(len(found)))
print(f"Found {len(found)} matching entries")
if edit:
print("Applying changes")
for matched, matching in found:

View file

@ -866,8 +866,8 @@ def set_vars(component_name, rules):
replacements = conf[m]
for line in rule["lines"]:
for property, new_value in replacements:
if line.strip().startswith("{}:".format(property)):
new_property = "{}: {};".format(property, new_value)
if line.strip().startswith(f"{property}:"):
new_property = f"{property}: {new_value};"
indentation = " " * (len(line) - len(line.lstrip(" ")))
line = indentation + new_property
break
@ -944,7 +944,7 @@ def iter_components(dir):
def replace_vars(source, dest):
components = list(sorted(iter_components(os.path.join(source, "components"))))
for c in components:
with open(c, "r") as f:
with open(c) as f:
text = f.read()
for s, r in GLOBAL_REPLACES:
@ -955,7 +955,7 @@ def replace_vars(source, dest):
name = c.split("/")[-1].split(".")[0]
updated_rules = set_vars(name, rules)
text = serialize_rules(updated_rules)
with open(os.path.join(dest, "{}.css".format(name)), "w") as f:
with open(os.path.join(dest, f"{name}.css"), "w") as f:
f.write(text)

View file

@ -15,13 +15,13 @@ def print_duplicates(path):
count = collections.Counter([e.msgid for e in pofile])
duplicates = [(k, v) for k, v in count.items() if v > 1]
for k, v in sorted(duplicates, key=lambda r: r[1], reverse=True):
print("{} entries - {}:".format(v, k))
print(f"{v} entries - {k}:")
for ctx in contexts_by_id[k]:
print(" - {}".format(ctx))
print(f" - {ctx}")
print()
total_duplicates = sum([v - 1 for _, v in duplicates])
print("{} total duplicates".format(total_duplicates))
print(f"{total_duplicates} total duplicates")
if __name__ == "__main__":