Skip to content

Commit

Permalink
chore(scripts): use correct formatting directly
Browse files Browse the repository at this point in the history
This avoids need for working pre-commit.
  • Loading branch information
nijel committed Dec 2, 2024
1 parent 33f3460 commit 45b1c9b
Showing 1 changed file with 15 additions and 23 deletions.
38 changes: 15 additions & 23 deletions scripts/generate-license-data
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ See https://github.com/spdx/license-list-data
"""

import json
import subprocess

HEADER = '''# Copyright © Michal Čihař <[email protected]>
#
Expand All @@ -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
Expand Down Expand Up @@ -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,
)

0 comments on commit 45b1c9b

Please sign in to comment.