diff --git a/generate_py5.py b/generate_py5.py index 404e2167..02080f80 100644 --- a/generate_py5.py +++ b/generate_py5.py @@ -101,7 +101,7 @@ def find_jar(jar_name): logger.critical(msg) raise RuntimeError(msg) - javap.classpath = f"{py5_jar_path}:{core_jar_path}" + classpath = f"{py5_jar_path}:{core_jar_path}" logger.info("creating Sketch code") sketch_data = ( @@ -111,7 +111,7 @@ def find_jar(jar_name): ) # these CodeBuilder objects write the code fragments for the methods and fields. - sketch_builder = CodeBuilder("py5.core.Sketch", "Sketch", sketch_data) + sketch_builder = CodeBuilder(classpath, "py5.core.Sketch", "Sketch", sketch_data) sketch_builder.code_module_members("_py5sketch") sketch_builder.run_builder() @@ -134,7 +134,7 @@ def run_code_builder(name, clsname, class_name=None): .set_index("java_name") ) - builder = CodeBuilder(clsname, name, data) + builder = CodeBuilder(classpath, clsname, name, data) builder.run_builder() return builder diff --git a/generator/codebuilder.py b/generator/codebuilder.py index c31c3c52..3db30304 100644 --- a/generator/codebuilder.py +++ b/generator/codebuilder.py @@ -90,12 +90,12 @@ def _param_annotation(varname: str, jtype: str) -> str: class CodeBuilder: - def __init__(self, clsname, class_name, class_data): + def __init__(self, classpath, clsname, class_name, class_data): ( self._constant_field_data, self._field_data, self._method_data, - ) = javap.get_class_information(clsname) + ) = javap.get_class_information(classpath, clsname) self._class_name = class_name self._py5_names = class_data["py5_name"] self._py5_decorators = class_data["decorator"] diff --git a/generator/javap.py b/generator/javap.py index a590c9c9..8d6fb4c0 100644 --- a/generator/javap.py +++ b/generator/javap.py @@ -26,7 +26,7 @@ import subprocess from collections import defaultdict -classpath = "" +from .reference import SKIP_METHOD_SIGNATURES FUNCTION_REGEX = re.compile( r"[\w\s]*?\s+(static)?[\w\s]*?([\w\[\]\.]+) (\w+)\(([^\)]*)\).*;" @@ -88,7 +88,7 @@ def process_block(block, is_interface): return data -def process_class(classname, data): +def process_class(classpath, classname, data): command = f"javap -classpath {classpath} -constants -public -l {classname}" result = subprocess.run(command.split(), capture_output=True) @@ -108,23 +108,23 @@ def process_class(classname, data): m = IMPLEMENTS_REGEX.match(class_signature) if m: for interface in m.group(1).split(","): - process_class(interface.strip(), data) + process_class(classpath, interface.strip(), data) m = EXTENDS_REGEX.match(class_signature) if m: - process_class(m.group(1).strip(), data) + process_class(classpath, m.group(1).strip(), data) blocks = content.split("\n\n") data.extend([process_block(b, is_interface) for b in blocks if b]) -def get_class_information(classname): +def get_class_information(classpath, classname): """parse the output of `javap` to get info on a class's methods and fields Java classes need to have been compiled with debug information for this to work. """ data = [] - process_class(classname, data) + process_class(classpath, classname, data) constant_field_data = {} field_data = {} @@ -150,4 +150,8 @@ def get_class_information(classname): if key in method_data: del constant_field_data[key] + for method_name, sig in SKIP_METHOD_SIGNATURES.get(classname, []): + if method_name in method_data and sig in method_data[method_name]: + del method_data[method_name][sig] + return constant_field_data, field_data, method_data diff --git a/generator/reference.py b/generator/reference.py index b592c7b5..bf4da771 100644 --- a/generator/reference.py +++ b/generator/reference.py @@ -101,6 +101,11 @@ "mpl_cmaps", } +SKIP_METHOD_SIGNATURES = { + "py5.core.Sketch": [("vertex", "float[]")], + "py5.core.Py5Graphics": [("vertex", "float[]")], +} + EXTRA_METHOD_SIGNATURES = { ("Sketch", "run_sketch"): [ ( diff --git a/py5_docs/Reference/api_en/Py5Graphics_vertex.txt b/py5_docs/Reference/api_en/Py5Graphics_vertex.txt index d67dc9ad..e2d5b7dc 100644 --- a/py5_docs/Reference/api_en/Py5Graphics_vertex.txt +++ b/py5_docs/Reference/api_en/Py5Graphics_vertex.txt @@ -7,7 +7,6 @@ pclass = PGraphics processing_name = vertex @@ signatures -vertex(v: npt.NDArray[np.floating], /) -> None vertex(x: float, y: float, /) -> None vertex(x: float, y: float, u: float, v: float, /) -> None vertex(x: float, y: float, z: float, /) -> None @@ -16,7 +15,6 @@ vertex(x: float, y: float, z: float, u: float, v: float, /) -> None @@ variables u: float - horizontal coordinate for the texture mapping v: float - vertical coordinate for the texture mapping -v: npt.NDArray[np.floating] - vertical coordinate data for the texture mapping x: float - x-coordinate of the vertex y: float - y-coordinate of the vertex z: float - z-coordinate of the vertex diff --git a/py5_docs/Reference/api_en/Sketch_vertex.txt b/py5_docs/Reference/api_en/Sketch_vertex.txt index dd9e8d8c..13166d28 100644 --- a/py5_docs/Reference/api_en/Sketch_vertex.txt +++ b/py5_docs/Reference/api_en/Sketch_vertex.txt @@ -7,7 +7,6 @@ pclass = PApplet processing_name = vertex @@ signatures -vertex(v: npt.NDArray[np.floating], /) -> None vertex(x: float, y: float, /) -> None vertex(x: float, y: float, u: float, v: float, /) -> None vertex(x: float, y: float, z: float, /) -> None @@ -16,7 +15,6 @@ vertex(x: float, y: float, z: float, u: float, v: float, /) -> None @@ variables u: float - horizontal coordinate for the texture mapping v: float - vertical coordinate for the texture mapping -v: npt.NDArray[np.floating] - vertical coordinate data for the texture mapping x: float - x-coordinate of the vertex y: float - y-coordinate of the vertex z: float - z-coordinate of the vertex