mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-04-14 13:08:48 +00:00
gnomeExtension: Reformat extension.json
The idea of having one line per extension for diff reasons mostly worked out well. However, especially around major Gnome updates it happens that extensions only change in the set of supported versions. This information is currently a bit hard to track, since such a change would still result in a diff for the entire line, which can be pretty long. Additionally, it may happen that this applies to many extensions at once, and the way git renders diff (first all removals in a hunk, then all additions) makes it even harder to track because now the change is not local in the diff. Having one line per supported version per extension should solve this problem, while still providing a good compromise in overall line count of the file. It shall be noted that GitHub already refuses to render diffs on this file even for comparatively small updates, therefore this change cannot really make it worse here.
This commit is contained in:
parent
cec1751cbd
commit
573f967c39
File diff suppressed because one or more lines are too long
@ -266,15 +266,28 @@ if __name__ == "__main__":
|
||||
processed_extensions.append(processed_extension)
|
||||
logging.debug(f"Processed {num + 1} / {len(raw_extensions)}")
|
||||
|
||||
# We micro-manage a lot of the serialization process to keep the diffs optimal.
|
||||
# We generally want most of the attributes of an extension on one line,
|
||||
# but then each of its supported versions with metadata on a new line.
|
||||
with open(updater_dir_path / "extensions.json", "w") as out:
|
||||
# Manually pretty-print the outer level, but then do one compact line per extension
|
||||
# This allows for the diffs to be manageable (one line of change per extension) despite their quantity
|
||||
for index, extension in enumerate(processed_extensions):
|
||||
# Manually pretty-print the outermost array level
|
||||
if index == 0:
|
||||
out.write("[ ")
|
||||
else:
|
||||
out.write(", ")
|
||||
json.dump(extension, out, ensure_ascii=False)
|
||||
# Dump each extension into a single-line string forst
|
||||
extension = json.dumps(extension, ensure_ascii=False)
|
||||
# Inject line breaks for each supported version
|
||||
for version in supported_versions:
|
||||
# This one only matches the first entry
|
||||
extension = extension.replace(f"{{\"{version}\": {{", f"{{\n \"{version}\": {{")
|
||||
# All other entries
|
||||
extension = extension.replace(f", \"{version}\": {{", f",\n \"{version}\": {{")
|
||||
# One last line break around the closing braces
|
||||
extension = extension.replace("}}}", "}\n }}")
|
||||
|
||||
out.write(extension)
|
||||
out.write("\n")
|
||||
out.write("]\n")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user