From 45b1c9b1c6e4912cf981beedacf11c6734f79b4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 2 Dec 2024 10:38:28 +0100 Subject: [PATCH] chore(scripts): use correct formatting directly This avoids need for working pre-commit. --- scripts/generate-license-data | 38 ++++++++++++++--------------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/scripts/generate-license-data b/scripts/generate-license-data index 93df269bc2cc..49c46abbf102 100755 --- a/scripts/generate-license-data +++ b/scripts/generate-license-data @@ -11,7 +11,6 @@ See https://github.com/spdx/license-list-data """ import json -import subprocess HEADER = '''# Copyright © Michal Čihař # @@ -25,13 +24,22 @@ This is an automatically generated file, see scripts/generate-license-data ''' TEMPLATE = """ ( - "{0}", - "{1}", - "{2}", + {0}, + {1}, + {2}, {3}, ), """ + +def escape_string(string: str) -> str: + if '"' in string: + if "'" in string: + return repr(string) + return f"'{string}'" + return f'"{string}"' + + # Some licenses are not classified as libre in SPDX EXCEPTIONS = { # DFSG compatible, see https://wiki.debian.org/DFSGLicenses @@ -63,26 +71,10 @@ with open("weblate/utils/licensedata.py", "w") as output: ) output.write( TEMPLATE.format( - item["licenseId"], - item["name"].replace('"', '\\"'), - item["reference"], + escape_string(item["licenseId"]), + escape_string(item["name"]), + escape_string(item["reference"]), "True" if libre else "False", ) ) output.write(")\n") - -# Apply coding style -subprocess.run( - [ - "uv", - "run", - "--no-sources", - "--only-group", - "pre-commit", - "pre-commit", - "run", - "--files", - "weblate/utils/licensedata.py", - ], - check=False, -)