diff --git a/MANIFEST.in b/MANIFEST.in index 7d666e4..6c6394e 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -10,6 +10,7 @@ exclude raylib/*.c exclude raylib/*.o include version.py exclude tests/* - +include raylib/py.typed +include pyray/py.typed diff --git a/create_stub_pyray.py b/create_stub_pyray.py index b49fe4f..3db8fc6 100644 --- a/create_stub_pyray.py +++ b/create_stub_pyray.py @@ -30,6 +30,12 @@ for filename in (Path("raylib.json"), Path("raymath.json"), Path("rlgl.json"), P for st in js["structs"]: if st["name"] not in known_structs: known_structs[st["name"]] = st + for e in js['enums']: + if e['name'] and e['values']: + print ("class "+e['name']+"(int):") + for value in e['values']: + print(" "+value['name']+" = "+str(value['value'])) + print("") def ctype_to_python_type(t): @@ -43,27 +49,39 @@ def ctype_to_python_type(t): return "int" elif t == "uint64_t": return "int" + elif t == "short": + return "int" + elif t == "unsigned short": + return "int" elif t == "double": return "float" elif "char * *" in t: return "list[str]" elif "char *" in t: return "str" - elif "char" in t: + elif t == "char": return "str" # not sure about this one + elif t == "unsigned char": + return "int" elif "*" in t: return "Any" + elif "[" in t: + return "list" # TODO FIXME type of items in the list elif t.startswith("struct"): return t.replace("struct ", "") elif t.startswith("unsigned"): return t.replace("unsigned ", "") + elif t.startswith("enum"): + return t.replace("enum ", "") else: return t print("""from typing import Any +import _cffi_backend # type: ignore +ffi: _cffi_backend.FFI """) # These words can be used for c arg names, but not in python @@ -89,6 +107,8 @@ for name, attr in getmembers(rl): if param_name in reserved_words: param_name = param_name + "_" + str(i) param_type = ctype_to_python_type(arg.cname) + if "struct" in arg.cname: + param_type += "|list|tuple" sig += f"{param_name}: {param_type}," return_type = ffi.typeof(attr).result.cname @@ -127,11 +147,14 @@ for struct in ffi.list_types()[0]: print(f' """ struct """') sig = "" for arg in ffi.typeof(struct).fields: - sig += ", " + arg[0] + ptype = ctype_to_python_type(arg[1].type.cname) + if arg[1].type.kind == "struct": + ptype += "|list|tuple" + sig += f", {arg[0]}: {ptype}|None = None" print(f" def __init__(self{sig}):") for arg in ffi.typeof(struct).fields: - print(f" self.{arg[0]}={arg[0]}") + print(f" self.{arg[0]}:{ctype_to_python_type(arg[1].type.cname)} = {arg[0]} # type: ignore") # elif ffi.typeof(struct).kind == "enum": # print(f"{struct}: int") diff --git a/create_stub_static.py b/create_stub_static.py index 1a61104..8134912 100644 --- a/create_stub_static.py +++ b/create_stub_static.py @@ -42,27 +42,35 @@ def ctype_to_python_type(t): return "int" elif t == "uint64_t": return "int" + elif t == "short": + return "int" + elif t == "unsigned short": + return "int" elif t == "double": return "float" elif "char * *" in t: - return "list[str]" + return "list[bytes]" elif "char *" in t: - return "str" + return "bytes" elif "char" in t: - return "str" # not sure about this one + return "bytes" # not sure about this one elif "*" in t: return "Any" + elif "[" in t: + return "list" # TODO FIXME type of items in the list elif t.startswith("struct"): return t.replace("struct ", "") elif t.startswith("unsigned"): return t.replace("unsigned ", "") + elif t.startswith("enum"): + return t.replace("enum ", "") else: return t print("""from typing import Any -import _cffi_backend +import _cffi_backend # type: ignore ffi: _cffi_backend.FFI rl: _cffi_backend.Lib @@ -96,6 +104,8 @@ for name, attr in getmembers(rl): if param_name in reserved_words: param_name = param_name + "_" + str(i) param_type = ctype_to_python_type(arg.cname) + if "struct" in arg.cname: + param_type += "|list|tuple" sig += f"{param_name}: {param_type}," return_type = ffi.typeof(attr).result.cname @@ -121,17 +131,22 @@ for struct in ffi.list_types()[0]: # if ffi.typeof(struct).fields is None: # print("weird empty struct, skipping", file=sys.stderr) # continue - print(f"{struct}: struct") + print(f"class {struct}:") # sig = "" - # for arg in ffi.typeof(struct).fields: - # sig += ", " + arg[0] + fields = ffi.typeof(struct).fields + if fields is not None: + #print(ffi.typeof(struct).fields) + #print(f" {arg}: {arg}") # print(f" def __init__(self{sig}):") # - # for arg in ffi.typeof(struct).fields: + for arg in ffi.typeof(struct).fields: + print(f" {arg[0]}: {ctype_to_python_type(arg[1].type.cname)}") + else: + print(" ...") # print(f" self.{arg[0]}={arg[0]}") elif ffi.typeof(struct).kind == "enum": - print(f"{struct}: int") + print(f"{struct} = int") else: print("WARNING: SKIPPING UNKNOWN TYPE", ffi.typeof(struct), file=sys.stderr) diff --git a/docs/genindex.html b/docs/genindex.html index 8d598c9..1f5d889 100644 --- a/docs/genindex.html +++ b/docs/genindex.html @@ -119,15 +119,37 @@ + -
@@ -181,7 +205,11 @@ - +
  • bindPose (pyray.Model attribute) + +
  • BLACK (in module pyray)
  • -
  • buffer (pyray.AudioStream attribute) + +
  • bufferCount (pyray.rlRenderBatch attribute) + +
  • BUTTON (in module raylib)
  • +
  • buttons (raylib.GLFWgamepadstate attribute) +
  • C

  • contacts (pyray.PhysicsManifoldData attribute) + +
  • contactsCount (pyray.PhysicsManifoldData attribute) + +
  • controlId (pyray.GuiStyleProp attribute) + +
  • count (pyray.AutomationEventList attribute)
  • create_physics_body_circle() (in module pyray) @@ -735,9 +863,17 @@
  • CreatePhysicsBodyRectangle() (in module raylib)
  • ctxData (pyray.Music attribute) + +
  • ctxType (pyray.Music attribute) + +
  • CUBEMAP_LAYOUT_AUTO_DETECT (in module raylib)
  • currentBuffer (pyray.rlRenderBatch attribute) + +
  • currentDepth (pyray.rlRenderBatch attribute) + +
  • @@ -824,8 +962,14 @@ +
  • deallocate (raylib.GLFWallocator attribute) +
  • decode_data_base64() (in module pyray)
  • DecodeDataBase64() (in module raylib) @@ -841,7 +985,13 @@
  • depth (pyray.RenderTexture attribute) + +
  • destroy_physics_body() (in module pyray)
  • DestroyPhysicsBody() (in module raylib) @@ -855,7 +1005,11 @@
  • DetachAudioStreamProcessor() (in module raylib)
  • direction (pyray.Ray attribute) + +
  • directory_exists() (in module pyray)
  • DirectoryExists() (in module raylib) @@ -869,7 +1023,11 @@
  • DisableEventWaiting() (in module raylib)
  • distance (pyray.RayCollision attribute) + +
  • draw_billboard() (in module pyray)
  • draw_billboard_pro() (in module pyray) @@ -1029,11 +1187,11 @@
  • draw_text_ex() (in module pyray)
  • draw_text_pro() (in module pyray) -
  • -
  • draw_texture() (in module pyray)
  • @@ -1281,7 +1451,11 @@
    @@ -1384,8 +1570,12 @@
  • Fade() (in module raylib)
  • -
  • ffi (in module raylib) +
  • ffi (in module pyray) + +
  • file_exists() (in module pyray)
  • FileExists() (in module raylib) @@ -1393,7 +1583,7 @@
  • FilePathList (class in pyray)
  • FLAG_BORDERLESS_WINDOWED_MODE (in module raylib) @@ -1474,8 +1664,6 @@
  • (pyray.ConfigFlags attribute)
  • - - @@ -1575,7 +1803,11 @@ - + - + + -
  • layout (pyray.NPatchInfo attribute) + +
  • left (pyray.NPatchInfo attribute) + +
  • leftLensCenter (pyray.VrStereoConfig attribute) + +
  • leftScreenCenter (pyray.VrStereoConfig attribute) + +
  • lensDistortionValues (pyray.VrDeviceInfo attribute) + +
  • lensSeparationDistance (pyray.VrDeviceInfo attribute) + +
  • lerp() (in module pyray)
  • Lerp() (in module raylib) @@ -6034,12 +6380,12 @@
  • load_texture_from_image() (in module pyray)
  • +
    @@ -6193,49 +6547,121 @@ + - @@ -6657,12 +7131,20 @@
  • normal (pyray.PhysicsManifoldData attribute)
  • normalize() (in module pyray) @@ -6675,6 +7157,12 @@
  • (pyray.PhysicsVertexData attribute)
  • (pyray.rlVertexBuffer attribute) +
  • +
  • (raylib.Mesh attribute) +
  • +
  • (raylib.PhysicsVertexData attribute) +
  • +
  • (raylib.rlVertexBuffer attribute)
  • @@ -6700,7 +7188,7 @@
  • NPatchInfo (class in pyray)
  • NPatchLayout (class in pyray) @@ -6716,15 +7204,27 @@
  • materials (pyray.Model attribute) + +
  • Matrix (class in pyray)
  • Matrix2x2 (class in pyray)
  • matrix_add() (in module pyray) @@ -6398,6 +6840,8 @@
  • matrix_translate() (in module pyray)
  • +
  • mode (pyray.rlDrawCall attribute) + +
  • Model (class in pyray)
  • ModelAnimation (class in pyray)
  • @@ -6644,7 +7118,7 @@
  • Music (class in pyray)
  • orient (pyray.PhysicsBodyData attribute) + +
  • @@ -6745,12 +7249,24 @@
  • parent (pyray.BoneInfo attribute) + +
  • paths (pyray.FilePathList attribute) + +
  • pause_audio_stream() (in module pyray)
  • pause_music_stream() (in module pyray) @@ -6764,7 +7280,11 @@
  • PauseSound() (in module raylib)
  • penetration (pyray.PhysicsManifoldData attribute) + +
  • physics_add_force() (in module pyray)
  • physics_add_torque() (in module pyray) @@ -6782,19 +7302,19 @@
  • PhysicsBodyData (class in pyray)
  • PhysicsManifoldData (class in pyray)
  • PhysicsShape (class in pyray)
  • PhysicsShapeType (in module raylib) @@ -6804,7 +7324,7 @@
  • PhysicsVertexData (class in pyray)
  • PINK (in module pyray) @@ -6885,8 +7405,6 @@
  • (pyray.PixelFormat attribute)
  • - - +
  • positions (pyray.PhysicsVertexData attribute) + +
  • processor (pyray.AudioStream attribute) + +
  • PROGRESS_PADDING (in module raylib)