-
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
👷♂️ This requires hard skills looool
Signed-off-by: Pascal Marco Caversaccio <pascal.caversaccio@hotmail.ch>
- Loading branch information
1 parent
d49e046
commit d4d9603
Showing
1 changed file
with
12 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |