Skip to content

Commit

Permalink
👷‍♂️ This requires hard skills looool
Browse files Browse the repository at this point in the history
Signed-off-by: Pascal Marco Caversaccio <pascal.caversaccio@hotmail.ch>
  • Loading branch information
pcaversaccio committed Aug 15, 2024
1 parent d49e046 commit d4d9603
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions scripts/insert_venom_pragma.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
import os


def add_venom_pragma(filepath):
with open(filepath, "r") as file:
lines = file.readlines()

# Insert `pragma experimental-codegen` in the second line to activate the `venom` backend.
if len(lines) >= 2:
def insert_venom_pragma(filepath):
with open(filepath, "r+") as f:
lines = f.readlines()
if len(lines) < 2:
lines.append("")
# Insert `pragma experimental-codegen` on the second line to activate the `venom` backend.
lines.insert(1, "# pragma experimental-codegen\n")
else:
lines.append("# pragma experimental-codegen\n")

# Write the modified lines back to the file.
with open(filepath, "w") as file:
file.writelines(lines)
# Move the file pointer back to the beginning of the file.
f.seek(0)
f.writelines(lines)


def process_directory(directory):
for root, _, files in os.walk(directory):
for file in files:
if file.endswith(".vy") or file.endswith(".vyi"):
filepath = os.path.join(root, file)
add_venom_pragma(filepath)
if file.endswith((".vy", ".vyi")):
insert_venom_pragma(os.path.join(root, file))


if __name__ == "__main__":
src_directory = "src/snekmate"
process_directory(src_directory)
process_directory("src/snekmate")

0 comments on commit d4d9603

Please sign in to comment.