baenv module

Manage Ballistica execution environment.

This module is used to set up and/or check the global Python environment before running a Ballistica app. This includes things such as paths, logging, and app-dirs. Because these things are global in nature, this should be done before any Ballistica modules are imported.

This module can also be exec’ed directly to set up a default environment and then run the app.

Ballistica can be used without explicitly configuring the environment in order to integrate it in arbitrary Python environments, but this may cause some features to be disabled or behave differently than expected.

class baenv.EnvConfig(config_dir: str, data_dir: str, app_python_dir: str | None, standard_app_python_dir: str, site_python_dir: str | None, user_python_dir: str | None, is_user_app_python_dir: bool, log_handler: LogHandler | None, initial_app_config: Any, launch_time: float)[source]

Bases: object

Final config values we provide to the engine.

app_python_dir: str | None

Where the app’s built-in Python stuff lives.

config_dir: str

Where app config/state data lives.

data_dir: str

Directory containing ba_data and any other platform-specific data.

initial_app_config: Any

Initial data from the config.json file in the config dir. The config file is parsed by

is_user_app_python_dir: bool

We have a mechanism allowing app scripts to be overridden by placing a specially named directory in a user-scripts dir. This is true if that is enabled.

launch_time: float

Timestamp when we first started doing stuff.

log_handler: LogHandler | None

Our fancy app log handler. This handles feeding logs, stdout, and stderr into the engine so they show up on in-app consoles, etc.

site_python_dir: str | None

Where the app’s bundled third party Python stuff lives.

standard_app_python_dir: str

Where the app’s built-in Python stuff lives in the default case.

user_python_dir: str | None

Custom Python provided by the user (mods).

baenv.config_exists() bool[source]

Has a config been created?

baenv.configure(*, config_dir: str | None = None, data_dir: str | None = None, user_python_dir: str | None = None, app_python_dir: str | None = None, site_python_dir: str | None = None, contains_python_dist: bool = False, setup_logging: bool = True) None[source]

Set up the environment for running a Ballistica app.

This includes things such as Python path wrangling and app directory creation. This must be called before any actual Ballistica modules are imported; the environment is locked in as soon as that happens.

baenv.did_paths_set_fail() bool[source]

Did we try to set paths and fail?

baenv.extract_arg(args: list[str], names: list[str], is_dir: bool) str | None[source]

Given a list of args and an arg name, returns a value.

The arg flag and value are removed from the arg list. We also check to make sure the path exists.

raises CleanErrors on any problems.

baenv.get_config() EnvConfig[source]

Return the active config, creating a default if none exists.