Setuptools Examples

These examples freeze Python games by hand, with a setup.py or setup.cfg (see Building Python Games for how build_apps finds the engine). In a launcher project the same options go into [tool.acron.build_apps] in pyproject.toml, and acronmanager dist writes the setup.py itself.

Simple Console Application

The most basic and simplest application to package is a simple console app with no dependencies:

print("Hello world")

Assuming this is saved as main.py, we can use the following requirements.txt file, which names the engine’s version:

acron==1.11.0.post60

The corresponding setup.py file could look like so:

from setuptools import setup

setup(
    name="hello_world",
    version="1.0.0",
    options={
        'build_apps': {
            'console_apps': {'hello_world': 'main.py'},
            'platforms': [
                'win_amd64',
                'macosx_11_0_arm64',
                'linux_x86_64',
            ],
        }
    }
)

Then, we can build the binaries using python setup.py build_apps.

A build directory will be created and contain a directory for each platform that binaries were built for. Drop the platforms you do not need from the list to build faster.

Asteroids Sample

Below is an example of a setup.py that can be used to build the Asteroids sample program.

from setuptools import setup

setup(
    name="asteroids",
    version="1.0.0",
    options={
        'build_apps': {
            'include_patterns': [
                '**/*.png',
                '**/*.jpg',
                '**/*.egg',
            ],
            'gui_apps': {
                'asteroids': 'main.py',
            },
            'log_filename': '$USER_APPDATA/Asteroids/output.log',
            'plugins': [
                'acrongl',
                'p3openal_audio',
            ],
            'platforms': [
                'win_amd64',
                'macosx_11_0_arm64',
                'linux_x86_64',
            ],
        }
    }
)

With the setup.py in place, it can be run with: python setup.py bdist_apps

The name field and options dictionary in the above setup.py can also be replaced by the following setup.cfg file:

[metadata]
name = asteroids
version = 1.0.0

[build_apps]
include_patterns =
    **/*.png
    **/*.jpg
    **/*.egg
gui_apps =
    asteroids = main.py
log_filename = $USER_APPDATA/Asteroids/output.log
plugins =
    acrongl
    p3openal_audio
platforms =
    win_amd64
    macosx_11_0_arm64
    linux_x86_64

The same in a launcher project’s pyproject.toml, where acronmanager supplies the name, the version and the main file:

[project]
name = "asteroids"
version = "1.0.0"
dependencies = ["acron==1.11.0.post60"]

[tool.acron]
main_file = "main.py"

[tool.acron.build_apps]
include_patterns = ["**/*.png", "**/*.jpg", "**/*.egg"]
log_filename = "$USER_APPDATA/Asteroids/output.log"
plugins = ["acrongl", "p3openal_audio"]
platforms = ["win_amd64", "macosx_11_0_arm64", "linux_x86_64"]

The Same Game for the Web and Android

One set of options serves every platform of a game; the web and Android add a few of their own:

'build_apps': {
    'gui_apps': {'asteroids': 'main.py'},
    'include_patterns': ['**/*.png', '**/*.jpg', '**/*.egg'],
    'plugins': ['acrongl', 'acrongles2', 'p3openal_audio'],
    'platforms': ['win_amd64'],
    'web_title': 'Asteroids',
    'application_id': 'com.example.asteroids',
    'android_abis': ['arm64-v8a'],
    'android_min_sdk_version': 24,
}

Build one platform at a time, naming it on the command line:

python setup.py bdist_apps -p win_amd64
python setup.py build_apps -p emscripten_wasm32
python setup.py bdist_apps -p android

The web takes its renderer and audio from the web runtime and ignores plugins; Android uses acrongles2, the desktop acrongl, and a plug-in a platform’s wheel does not have is left out. With acronmanager, dist, dist --web and dist --android do the same, and fill in the web and Android options from the project.