This commit is contained in:
Electron Studio 2019-06-07 01:16:29 +01:00
commit 4a7462313a
3 changed files with 70 additions and 22 deletions

9
MANIFEST.in Normal file
View file

@ -0,0 +1,9 @@
include raylib/static/*.so
include raylib/static/*.pyd
exclude raylib/static/*.a
include raylib/*.h
exclude raylib/static/*.c
exclude raylib/static/*.o
include raylib/dynamic/*.dylib
include raylib/dynamic/*.dll
include raylib/dynamic/*.so

View file

@ -1,51 +1,87 @@
# Python Bindings for Raylib # Python Bindings for Raylib 2.5
This uses CFFI API static bindings rather than ctypes. Hopefully this will be faster, the static type knowledge from the C New CFFI API static bindings. Faster, fewer bugs and easier to maintain than ctypes.
headers will result in fewer bugs, and using the original headers will make it easier to maintain.
# Install # Install
**MacOS: Python 3.7**: we distribute a statically linked Raylib library, so in theory the only thing you need to do is install **Windows 10 (64 bit): Python 3.6 - 3.7**
us from Pypi.
**MacOS: Python 3.5 - 3.7**
We distribute a statically linked Raylib library, install from Pypi.
pip3 install raylib pip3 install raylib
**Linux: Python 3.6**: we dont distribute Raylib, so you must have Raylib 2.5dev already installed on your system. Currently we are building from the github version, specifically https://github.com/raysan5/raylib/commit/f325978b26ea934095f74ac628e6578ebbc2b7a0 although I guess any 2.5 build should work. First follow the instructions here: https://github.com/raysan5/raylib/wiki/Working-on-GNU-Linux Then do: If you're using **Linux**, or a different version of Python, or maybe Windows/Mac with incompatible libraries
then you can either *use the dynamic binding only* or else you will have to build from source. Download, compile
and install Raylib 2.5 then
pip3 install raylib cd raylib/static
**Windows 10 (64 bit): Python 3.7**: we distribute a statically linked Raylib library, thanks to https://github.com/Pebaz, so in theory the only thing you need to do is install us from Pypi.
pip3 install raylib
If you're using a different version of Python, or maybe a Linux/Mac with incompatible libraries
you will have to build. The specific version we built against is https://github.com/raysan5/raylib/commit/f325978b26ea934095f74ac628e6578ebbc2b7a0 but we should soon try to synchronize with a proper released version of Raylib.
cd raylib
python3 build_linux.py python3 build_linux.py
python3 build_mac.py
# Use # Use
## raylib.static ## raylib.static
Currently the goal is make usage as similar to the original C as CFFI will allow. There are a few differences Goal is make usage as similar to the original C as CFFI will allow. There are a few differences
you can see in the examples. See test_static.py and examples/*.py for how to use. you can see in the examples. See test_static.py and examples/*.py for how to use.
```
from raylib.static import *
InitWindow(800, 450, b"Hello Raylib")
SetTargetFPS(60)
camera = ffi.new("struct Camera3D *", [[18.0, 16.0, 18.0], [0.0, 0.0, 0.0], [0.0, 1.0, 0.0], 45.0, 0])
SetCameraMode(camera[0], CAMERA_ORBITAL)
while not WindowShouldClose():
UpdateCamera(camera)
BeginDrawing()
ClearBackground(RAYWHITE)
DrawText(b"Hellow World", 190, 200, 20, VIOLET)
EndDrawing()
CloseWindow()
```
## raylib.dynamic ## raylib.dynamic
In addition to the API static bindings I have attempted to do CFFI ABI dynamic bindings in order to avoid the need to compile a C extension module. In addition to the API static bindings we have CFFI ABI dynamic bindings in order to avoid the need to compile a C extension module.
There have been some weird failures with dynamic bindings and ctypes bindings before and often the failures are silent There have been some weird failures with dynamic bindings and ctypes bindings before and often the failures are silent
so you dont even know. Also the static bindings should be faster. Therefore I recommend the static ones... so you dont even know. Also the static bindings should be faster. Therefore I recommend the static ones...
BUT the dynamic bindings have the big advantage that you don't need to compile anything to install. BUT the dynamic bindings have the big advantage that you don't need to compile anything to install. You just need a Raylib DLL,
which we supply for Windows/Mac/Linux.
See test_dynamic.py for how to use them. See test_dynamic.py for how to use.
## raylib.static.pyray ## raylib.static.pyray
Wrapper around the static bindings. Makes the names snakecase and converts strings to bytes automatically. See test_pyray.py. Wrapper around the static bindings. Makes the names snakecase and converts strings to bytes automatically. See test_pyray.py.
```
from raylib.static.pyray import pyray as prl
from raylib.colors import *
prl.init_window(800, 450, "Hello Pyray")
prl.set_target_fps(60)
camera = prl.Camera3D([18.0, 16.0, 18.0], [0.0, 0.0, 0.0], [0.0, 1.0, 0.0], 45.0, 0)
image = prl.load_image("examples/models/resources/heightmap.png")
prl.set_camera_mode(camera, prl.CAMERA_ORBITAL)
while not prl.window_should_close():
prl.update_camera(prl.pointer(camera))
prl.begin_drawing()
prl.clear_background(RAYWHITE)
prl.draw_text("Hello world", 190, 200, 20, VIOLET)
prl.end_drawing()
prl.close_window()
```
## raylib.richlib ## raylib.richlib
A very easy to use library on top of static bindings, modelled after Pygame Zero. A very easy to use library on top of static bindings, modelled after Pygame Zero.
@ -60,4 +96,5 @@ A very easy to use library on top of static bindings, modelled after Pygame Zero
* converting more examples from C to python * converting more examples from C to python
* testing and building on more platforms * testing and building on more platforms
* sorting out binary wheel distribution for Mac/Win and compile-from-source distributtion for Linux

View file

@ -10,7 +10,7 @@ README = (HERE / "README.md").read_text()
# This call to setup() does all the work # This call to setup() does all the work
setup( setup(
name="raylib", name="raylib",
version="2.5.0", version="2.5.0.post1",
description="Python CFFI bindings for Raylib", description="Python CFFI bindings for Raylib",
long_description=README, long_description=README,
long_description_content_type="text/markdown", long_description_content_type="text/markdown",
@ -21,6 +21,8 @@ setup(
classifiers=[ classifiers=[
"License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)", "License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)",
"Programming Language :: Python :: 3", "Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.7",
], ],
packages=["raylib", "raylib.dynamic", "raylib.static", "raylib.richlib"], packages=["raylib", "raylib.dynamic", "raylib.static", "raylib.richlib"],