Skip to content

Commit

Permalink
Add a tool to add the builtin attribute to all builtin libary file wh…
Browse files Browse the repository at this point in the history
…ere it's missing
  • Loading branch information
monsieurswag committed May 14, 2024
1 parent cd155ed commit f274849
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tools/add_builtin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import re, os

# This is a temporary tool that adds "builtin: true" to all libraries stored as yaml files under ./backend/library/libraries.

current_path = "/".join(__file__.split("/")[:-1])
library_path = os.path.join(current_path,"..","backend","library","libraries")
fnames = [
fname for fname in os.listdir(library_path)
if fname.endswith(".yaml")
]

for fname in fnames :
lib = os.path.join(library_path,fname)

with open(lib,"r",encoding="utf-8") as f:
content = f.read()
lines = content.split("\n")

if not any(
re.match(r"^builtin.*:.*true",line) is not None
for line in lines
) :
lines.insert(1,"builtin: true")
with open(lib,"w",encoding="utf-8") as f :
f.write("\n".join(lines))
print(f"Library '{fname}' updated.")

0 comments on commit f274849

Please sign in to comment.