Skip to content

Commit

Permalink
Merge pull request #66 from niklas2902/dev-build
Browse files Browse the repository at this point in the history
Dev build
  • Loading branch information
niklas2902 authored Sep 16, 2024
2 parents 6ed32a7 + bc7ee20 commit 1810ebc
Show file tree
Hide file tree
Showing 9 changed files with 435 additions and 416 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/nightly-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ jobs:
run: |
python -m pip install -r requirements.txt
python -m pip install flake8
#- name: Lint with flake8
# run: |
# stop the build if there are Python syntax errors or undefined names
#flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
#flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics

- name: Generate cast helpers
run: python meson_scripts/generate_cast_helpers.py
Expand Down
9 changes: 3 additions & 6 deletions generation_files/generate_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os.path, os

from generate_enums import enumize_name
from generation_files.generation_tools import write_if_different

INDENT = " "

Expand Down Expand Up @@ -1456,12 +1457,7 @@ def generate_classes(classes, filename, is_core=False, is_typed_array=False):
res = generate_newline(res)
res += generate_operators_for_class(class_["name"])
text_to_write = "# distutils: language=c++\n"+res
if (os.path.exists(filename)):
with open(filename, "r") as already_existing_file:
if already_existing_file.read() == text_to_write:
return
with open(filename, "w") as f:
f.write(text_to_write)
write_if_different(filename, text_to_write)


def generate_dictionary_set_item():
Expand Down Expand Up @@ -1873,6 +1869,7 @@ def generate_typed_array_name(name):
typed_arrays_names.add(generate_typed_array_name(typed_array))
arrays.append(my_array_cls)

arrays = sorted(arrays, key= lambda key:key["name"])
generate_classes(arrays, f"py4godot/classes/typedarrays.pyx", is_core=False, is_typed_array=True)

generate_classes(obj["builtin_classes"], f"py4godot/classes/core.pyx", is_core=True)
28 changes: 21 additions & 7 deletions generation_files/generate_classes_pxd.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,17 @@ def generate_typed_array_name(name):
pass
return name.split("::")[1] + "TypedArray"

def write_if_different(file_path, text_to_write):
if os.path.exists(file_path):
with open(file_path, 'r') as existing_file:
if existing_file.read() != text_to_write:
with open(file_path, 'w') as file_to_write:
file_to_write.write(text_to_write)
else:
with open(file_path, 'w') as file_to_write:
file_to_write.write(text_to_write)



if __name__ == "__main__":
os.chdir("..")
Expand All @@ -165,7 +176,7 @@ def generate_typed_array_name(name):
obj = json.loads(data)
classes = set([class_['name'] if class_["name"] not in IGNORED_CLASSES else None for class_ in
obj['classes'] + obj["builtin_classes"]])
builtin_classes = set(class_["name"] for class_ in obj["builtin_classes"])
builtin_classes = [class_["name"] for class_ in obj["builtin_classes"]]
res = generate_import()
res = generate_newline(res)
for class_ in builtin_classes:
Expand All @@ -180,8 +191,8 @@ def generate_typed_array_name(name):

res += generate_pxd_class(class_)

with open("py4godot/classes/core.pxd", "w") as f:
f.write("# distutils: language=c++"+res)
text_to_write = "# distutils: language=c++"+res
write_if_different("py4godot/classes/core.pxd", text_to_write)
for class_ in obj["classes"]:
if class_["name"] in IGNORED_CLASSES:
continue
Expand All @@ -194,9 +205,9 @@ def generate_typed_array_name(name):
res += f"from py4godot.classes.core cimport *"
res = generate_newline(res)
res += generate_pxd_class(class_)
with open(f"py4godot/classes/{class_['name']}/{class_['name']}.pxd", "w") as f:
f.write("# distutils: language=c++\n"+res)

text_to_write = "# distutils: language=c++\n"+res
write_if_different(f"py4godot/classes/{class_['name']}/{class_['name']}.pxd", text_to_write)
array_cls = None
arrays = []
for cls in obj["builtin_classes"]:
Expand All @@ -208,6 +219,7 @@ def generate_typed_array_name(name):
my_array_cls["name"] = generate_typed_array_name(typed_array)
typed_arrays_names.add(generate_typed_array_name(typed_array))
arrays.append(my_array_cls)
arrays = sorted(arrays, key = lambda array: array["name"])

res = ""
for class_ in arrays:
Expand All @@ -217,5 +229,7 @@ def generate_typed_array_name(name):
res += f"from libcpp.memory cimport shared_ptr, allocator"
res = generate_newline(res)
res += generate_pxd_class(class_)
with open(f"py4godot/classes/typedarrays.pxd", "w") as f:
f.write("# distutils: language=c++\n"+res)

text_to_write = "# distutils: language=c++\n"+res

write_if_different(f"py4godot/classes/typedarrays.pxd", text_to_write)
7 changes: 3 additions & 4 deletions generation_files/generate_common_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os.path

from generate_enums import enumize_name
from generation_files.generation_tools import write_if_different

INDENT = " "

Expand Down Expand Up @@ -90,7 +91,7 @@ def generate_import():
"from py4godot.classes.core cimport *\n"
"cimport py4godot.classes.Object.Object as py4godot_object\n")

for cls in builtin_classes:
for cls in sorted(list(builtin_classes)):
if cls not in {"Nil", "float", "int", "bool"}:
result += f"cimport py4godot.classes.core as py4godot_{cls.lower()}\n"
return result
Expand Down Expand Up @@ -746,6 +747,4 @@ def untypearray(type_):
for utility_function in obj["utility_functions"]:
res += generate_method(utility_function)
res = generate_newline(res)

with open("py4godot/functions.pyx", "w") as f:
f.write("# distutils: language=c++\n"+res)
write_if_different("py4godot/functions.pyx", "# distutils: language=c++\n"+res)
11 changes: 5 additions & 6 deletions generation_files/generate_enums.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import json
import os

from generation_files.generation_tools import write_if_different


def generate_newline(str_):
return str_ + "\n"
Expand Down Expand Up @@ -42,9 +44,6 @@ def enumize_name(str_):
res_pyi = generate_newline(res_pyi)


with open("py4godot/enums/enums.pyx", "w") as f:
f.write("# distutils: language=c++\n"+"from py4godot.godot_bindings.binding4_godot4 cimport *")
with open("py4godot/enums/enums.pxd", "w") as f:
f.write("# distutils: language=c++\n"+res)
with open("py4godot/enums/enums.pyi", "w") as f:
f.write("# distutils: language=c++\n"+res_pyi)
write_if_different("py4godot/enums/enums.pyx","# distutils: language=c++\n"+"from py4godot.godot_bindings.binding4_godot4 cimport *")
write_if_different("py4godot/enums/enums.pxd", "# distutils: language=c++\n"+res)
write_if_different("py4godot/enums/enums.pyi", "# distutils: language=c++\n"+res_pyi)
14 changes: 2 additions & 12 deletions generation_files/generate_pxd_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from generate_classes import pythonize_boolean_types, unref_type, \
unnull_type
from generate_classes_hpp import has_native_struct, ungodottype
from generation_files.generation_tools import write_if_different

INDENT = " "

Expand Down Expand Up @@ -685,18 +686,7 @@ def generate_classes(classes, filename, is_core=False):
res = generate_newline(res)
res += generate_operators_for_class(class_["name"])
res = generate_newline(res)
if (os.path.exists(filename)):
with open(filename, "r") as already_existing_file:
text = already_existing_file.read()
if text == res:
return
else:
with open("output_already_existing", "w") as existing:
existing.write(text)
with open("output_newly_generated", "w") as new:
new.write(res)
with open(filename, "w") as f:
f.write(res)
write_if_different(filename, res)


def generate_dictionary_set_item():
Expand Down
4 changes: 2 additions & 2 deletions generation_files/generate_pxd_utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from generate_classes import pythonize_boolean_types, unref_type, \
unnull_type
from generate_classes_hpp import has_native_struct, ungodottype
from generation_files.generation_tools import write_if_different

INDENT = " "

Expand Down Expand Up @@ -282,5 +283,4 @@ def graph_to_list(node, liste):
res += generate_method(utility_function)
res = generate_newline(res)

with open("py4godot/functions.pxd", "w") as f:
f.write("# distutils: language=c++\n"+res)
write_if_different("py4godot/functions.pxd", "# distutils: language=c++\n"+res)
13 changes: 13 additions & 0 deletions generation_files/generation_tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import os


def write_if_different(file_path, text_to_write):
if os.path.exists(file_path):
with open(file_path, 'r') as existing_file:
if existing_file.read() != text_to_write:
with open(file_path, 'w') as file_to_write:
file_to_write.write(text_to_write)
else:
with open(file_path, 'w') as file_to_write:
file_to_write.write(text_to_write)

Loading

0 comments on commit 1810ebc

Please sign in to comment.