Skip to content

Commit

Permalink
Merge pull request #532 from hx2A/fix506
Browse files Browse the repository at this point in the history
Fix506
  • Loading branch information
hx2A authored Oct 28, 2024
2 parents 8e474b8 + c98af2a commit 604719e
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 15 deletions.
6 changes: 3 additions & 3 deletions generate_py5.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand All @@ -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()

Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions generator/codebuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
16 changes: 10 additions & 6 deletions generator/javap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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+)\(([^\)]*)\).*;"
Expand Down Expand Up @@ -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)

Expand All @@ -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 = {}
Expand All @@ -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
5 changes: 5 additions & 0 deletions generator/reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"): [
(
Expand Down
2 changes: 0 additions & 2 deletions py5_docs/Reference/api_en/Py5Graphics_vertex.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 0 additions & 2 deletions py5_docs/Reference/api_en/Sketch_vertex.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 604719e

Please sign in to comment.