Skip to main content

Python bindings for Endless Sky C++ code

Project description

Endless Sky bindings for Python

$ pip install endless-sky-bindings

This library does not include the Endless Sky data, so you'll need to find that on your system or clone the Endless Sky repo to get it. The code samples below assume a checkout of endless-sky at ~/endless-sky.

Command line use

Loading data files:

% echo -e 'ship Rocket\n\tattributes\n\t\tdrag 10' > myData.txt
$ python -m endless_sky load --empty-resources myData.txt  # only prints ships atm
'Rocket': {'drag': 10.0, 'gun ports': 0.0, 'turret mounts': 0.0},
$ python -m endless_sky load -- --resources ~/endless-sky
{'Aerie': {'bunks': 28.0,
           'capture attack': 1.8000000000000003,
           'capture defense': 2.4000000000000004,
           'cargo space': 50.0,
...
$ # In order to parse a file with vanilla outfits defined, use --resources
$ python -m endless_sky load --resources ~/endless-sky myData.txt
{'Aerie': {'bunks': 28.0,
...
<'Rocket' is somewhere in here>
...

Runing the game and a Python interpreter at the same time:

$ python -m endless_sky run --resources ~/endless-sky --default-config

Library

Once you get a handle on the endless_sky.bindings module (bound to 'es' variable here), C++ classes are exposed to Python pretty directly; for documentation, see the header files in Endless Sky.

>>> from endless_sky.loader import load_data
>>> es = load_data(resources="/Users/tomb/endless-sky")
>>> ships = es.GameData.Ships() # these objects correspond to 
>>> ships.<tab><tab>
ships.Find(  ships.Has(   ships.size(
>>> shuttle = ships.Find("Shuttle")
<endless_sky.bindings.Ship object at 0x1087391b0>
>>> ship = es.Ship(shuttle)  # make a copy to avoid modifying the template
>>> ship.<tab><tab>
ship.Acceleration(          ship.Hull(                  ship.Mass(
ship.AddCrew(               ship.HyperdriveFuel(        ship.MaxReverseVelocity(
ship.Attributes(            ship.IdleHeat(              ship.MaxVelocity(
ship.BaseAttributes(        ship.IsBoarding(            ship.MaximumHeat(
... and many more, see header files for documentation
>>> ship.Attributes().Attributes()
<endless_sky.bindings.Dictionary object at 0x1087392f0>
>>> dict(ship.Attributes().Attributes())
{'bunks': 6.0, 'cargo space': 20.0, 'drag': 1.7000000000000002, ...}
>>> ship.SetName("Summer Breeze")
>>> x.Name()
'Summer Breeze'

Warning: endless_sky.bindings contains non-resetable singletons like GameData, so once you load some data (directly with GameData.BeginLoad(), with a load_data, or indirectly with a parser function) you can't unload that data without exiting Python.

Installation

Mac

brew install libmad libpng SDL2
pip install endless-sky-bindings

Linux

sudo apt-get install libsdl2-dev libpng-dev libjpeg-turbo8-dev libopenal-dev libmad0-dev libglew-dev libgl1-mesa-dev libegl1-mesa-dev libgles2-mesa-dev uuid-dev
pip install endless-sky-bindings

Windows

pip install endless-sky-bindings

Building from source

git clone git@github.com:thomasballinger/endless-sky-bindings-python.git
cd endless-sky-bindings-python

Mac

brew install libmad libpng jpeg-turbo SDL2 openal-soft

Linux

sudo apt-get install libsdl2-dev libpng-dev libjpeg-turbo8-dev libopenal-dev libmad0-dev libglew-dev libgl1-mesa-dev libegl1-mesa-dev libgles2-mesa-dev uuid-dev

Windows

Invoke-WebRequest https://endless-sky.github.io/win64-dev.zip -OutFile win64-dev.zip
Expand-Archive win64-dev.zip -DestinationPath . -Force
Remove-Item win64-dev.zip

cd endless_sky/endless-sky
patch -p1 < ../../patch.diff
cd ../..
pip install 

Dev notes

Updating the Endless Sky patch

These bindings use a patched version of Endless Sky to patch out threads and make a few other changes.

To update the patch:

  • make changes in the submodule at endless_sky/endless-sky
  • with that directory as the working directory, run git diff > ../../patch.diff

This is likely to be necessary after updating the version of Endless Sky used.

This patch is intended to be the minimum to make Python bindings work; if this repo is combined with Emscripten-compiled JavaScript bindings at a later date it will need to be expanded.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

endless-sky-bindings-0.0.10.tar.gz (684.8 kB view details)

Uploaded Source

Built Distributions

endless_sky_bindings-0.0.10-cp39-cp39-win_amd64.whl (4.1 MB view details)

Uploaded CPython 3.9 Windows x86-64

endless_sky_bindings-0.0.10-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

endless_sky_bindings-0.0.10-cp39-cp39-macosx_10_15_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.9 macOS 10.15+ x86-64

endless_sky_bindings-0.0.10-cp38-cp38-win_amd64.whl (4.1 MB view details)

Uploaded CPython 3.8 Windows x86-64

endless_sky_bindings-0.0.10-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

endless_sky_bindings-0.0.10-cp38-cp38-macosx_10_15_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.8 macOS 10.15+ x86-64

File details

Details for the file endless-sky-bindings-0.0.10.tar.gz.

File metadata

  • Download URL: endless-sky-bindings-0.0.10.tar.gz
  • Upload date:
  • Size: 684.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for endless-sky-bindings-0.0.10.tar.gz
Algorithm Hash digest
SHA256 00f04435591bec0e8ef110ee784ba35007e3778259d7b5ef46973936544ad8e8
MD5 fe9c5efc8c4c818a13b030a16f32a5f0
BLAKE2b-256 38b953dd19f67fe24c8757092635a1bb7754cc5572f4ca72cfc8c41ba4318b91

See more details on using hashes here.

File details

Details for the file endless_sky_bindings-0.0.10-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: endless_sky_bindings-0.0.10-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 4.1 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for endless_sky_bindings-0.0.10-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 60764910b3e2c4cd3c6c77ef13337df0f55d04d31494baff31d511ad381cc0ac
MD5 7972474f74d3914421ee18c422dc2d96
BLAKE2b-256 f0ca5f9672da9e3612083382894286bcf0eee551583484f05c47d73dfc49eeed

See more details on using hashes here.

File details

Details for the file endless_sky_bindings-0.0.10-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for endless_sky_bindings-0.0.10-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f00230179deba3bf7a8fcf842f0941139af1614ebd4ac13a28c9f36571c3746b
MD5 98fec2b4cecfea80a942e98782cad941
BLAKE2b-256 7066573420c2a0431c4fa50cb5c536ae61057894cf8b9d9245e8d716b904bfc2

See more details on using hashes here.

File details

Details for the file endless_sky_bindings-0.0.10-cp39-cp39-macosx_10_15_x86_64.whl.

File metadata

  • Download URL: endless_sky_bindings-0.0.10-cp39-cp39-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 2.2 MB
  • Tags: CPython 3.9, macOS 10.15+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for endless_sky_bindings-0.0.10-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 dcad557fb59ccaad85af1c9a601586ac240f4a4eeb6eec1c3c112875aff9a855
MD5 e1b8b1b7466d0e2d533eace2bbb4b367
BLAKE2b-256 f81bc209687e4fd7decb9b1a00e7eeaa5f31062b8293a9007088d4fb1262aee7

See more details on using hashes here.

File details

Details for the file endless_sky_bindings-0.0.10-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: endless_sky_bindings-0.0.10-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 4.1 MB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for endless_sky_bindings-0.0.10-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 8e6bbdcef3d634f2cf550cd384fac06ff305af4cc9338c7b43bf9f03bdf365d2
MD5 f6fe0c15c395d8b6c5f1fd075561a50e
BLAKE2b-256 7a3c0a8b9669155f768703c851496692888be0e746f781fe091bad3889c00ee4

See more details on using hashes here.

File details

Details for the file endless_sky_bindings-0.0.10-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for endless_sky_bindings-0.0.10-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 28c71dfaffaa5200179ce2013a5076df24838bbfa10231dd8b31c257ae552962
MD5 7793a661c9a9d18397ad67873fff6e25
BLAKE2b-256 99cdd2920c9f1107030b530caa0a58c6a0211b6674d7e7f0292c5d02c2cb4e36

See more details on using hashes here.

File details

Details for the file endless_sky_bindings-0.0.10-cp38-cp38-macosx_10_15_x86_64.whl.

File metadata

  • Download URL: endless_sky_bindings-0.0.10-cp38-cp38-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 2.2 MB
  • Tags: CPython 3.8, macOS 10.15+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for endless_sky_bindings-0.0.10-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 963874198d3fe0cde0b7ca4c74278d0d4388d4adce53738243edb0dddba46aaa
MD5 fd8b542aeb7545a5a1455548d1eceefe
BLAKE2b-256 8430756e130e8a5c60dffebffb0c0c51669609d91e0bcd848b63a27e9d083a4f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page