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.11.tar.gz (685.8 kB view details)

Uploaded Source

Built Distributions

endless_sky_bindings-0.0.11-cp39-cp39-win_amd64.whl (4.2 MB view details)

Uploaded CPython 3.9 Windows x86-64

endless_sky_bindings-0.0.11-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.11-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.11-cp38-cp38-win_amd64.whl (4.1 MB view details)

Uploaded CPython 3.8 Windows x86-64

endless_sky_bindings-0.0.11-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.11-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.11.tar.gz.

File metadata

  • Download URL: endless-sky-bindings-0.0.11.tar.gz
  • Upload date:
  • Size: 685.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.11.tar.gz
Algorithm Hash digest
SHA256 4b1e692d15c1a26406bc4ae4e040313b1b430dc7aace400555c1174d587bcd34
MD5 2905d7a1b976f8ec1e5c63b1346ffd66
BLAKE2b-256 3d5a3e52f1ef32799d526aa7bba80fc7bf7a41a6fdf19695101d9df14e3c1e78

See more details on using hashes here.

File details

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

File metadata

  • Download URL: endless_sky_bindings-0.0.11-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 4.2 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.11-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 f2ec66bf30579306fba70ab25dc8dc7e2869de8db9bee75ec643f8c1b65647e1
MD5 a40300fcc706b146be9c06598d97a53b
BLAKE2b-256 42163399af930c06813719c89fbe0408d085afa8f5a106c85cd53a05fa19e092

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for endless_sky_bindings-0.0.11-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c42ae8ea11a55e2b9a920cf7524743bb7910d950decea8deed7c4181dcbcabc7
MD5 e6197c2757d81671bae81c709598442d
BLAKE2b-256 c66079db0d0ac173dd263f0955a1d718f8d62a07059b04b0e978df874ae0c94a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: endless_sky_bindings-0.0.11-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.11-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 f72eadbcb8b2ca02ee4fd5d998c1406010a77fe368f8f294b52cbc223439bb43
MD5 3cdc12a542d906eb04c522fe78b91d10
BLAKE2b-256 f05db6cd57e5c471d2026fbb1a7d0cecd6f77b2e431d5844c97ad29d8399bfec

See more details on using hashes here.

File details

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

File metadata

  • Download URL: endless_sky_bindings-0.0.11-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.11-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 fb6da7932a24f6b8205804693143f9afa55b3761966d6c3c25fae0fd8b0b5a90
MD5 a97c26e1be1a32958e36b2c53df4bb02
BLAKE2b-256 50f30e7ca799f91e9fc92307f04951f52749909f02f0d083571530744863421a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for endless_sky_bindings-0.0.11-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a3212d3ee8ff4c918585a57bedd15cea7f41835cc7ff8091e96ef8152361a09e
MD5 d3171db0bb09c8357111b12cd17c5990
BLAKE2b-256 22f0f9841e946b492720d7d6458e544aa5ac8778d2eaddff2710b1906388d113

See more details on using hashes here.

File details

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

File metadata

  • Download URL: endless_sky_bindings-0.0.11-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.11-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 fcb778f3c9748958f2b5f7ba497ae48de516afd4aa4fd4df34c221c1b013078a
MD5 76ef84d8abfc0635a2b0aec4b5c0ad0e
BLAKE2b-256 6367d265a6a10e1d36dd6f8393306e81cb38dfcad8c6a37c1a855ca8d2c1eca2

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