Skip to content

Commit

Permalink
x
Browse files Browse the repository at this point in the history
  • Loading branch information
xen0n committed Mar 14, 2024
1 parent db4d4c5 commit a0b0497
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions scripts/expand-yaml-anchors.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,30 @@
#
# See: https://github.com/orgs/community/discussions/17245

import sys
import os

import yaml

X_REMOVE_TAG = "x--expand-yaml-anchors--remove"

FILE_HEADER_TEXT = """\
# THIS FILE IS AUTO-GENERATED BY scripts/expand-yaml-anchors.py; DO NOT EDIT
#
# This file is generated from the source file:
#
# {infile}
#
# Please re-run scripts/expand-yaml-anchors.py and commit the result after
# making your changes.
"""

def main(argv: list[str]) -> int:
if len(argv) != 3:
print(f"usage: {argv[0]} <infile> <outfile>", file=sys.stderr)
return 1
FILES_TO_PROCESS: list[tuple[str, str]] = []

process(argv[1], argv[2])
return 0

def main() -> None:
for infile, outfile in FILES_TO_PROCESS:
print(f"expanding {infile} into {outfile}")
process(infile, outfile)


def process(infile: str, outfile: str) -> None:
Expand All @@ -30,8 +40,12 @@ def process(infile: str, outfile: str) -> None:
del obj[X_REMOVE_TAG]

with open(outfile, "wb") as fp:
fp.write(FILE_HEADER_TEXT.format(infile=infile).encode("utf-8"))
yaml.dump(obj, fp)


if __name__ == "__main__":
sys.exit(main(sys.argv))
# cd to project root
os.chdir(os.path.dirname(__file__))

main()

0 comments on commit a0b0497

Please sign in to comment.