libretro.builder¶
Fluent builder for assembling a configured Session from drivers and a core.
See also
libretro.sessionThe
Sessionproduced by this builder.
Module Attributes
A placeholder that indicates the default value for one of |
Functions
|
Construct a |
Classes
A builder class for constructing a |
Exceptions
Raised by |
- class SessionBuilder[source]¶
Bases:
objectA builder class for constructing a
Session.At minimum, a
Sessionrequires aCore, anAudioDriver, anInputDriver, and aVideoDriver; eachwith_method sets an argument (mostly drivers) for theSession.- __init__()[source]¶
Initialize a new
SessionBuilderwith no arguments, not even the required ones.Calling
build()before setting any of the required arguments will raise aRequiredError.
- classmethod defaults(core)[source]¶
Alias to
defaults().- Return type:
- with_core(core)[source]¶
Set the core to use for the session.
- with_content(content)[source]¶
Set the content to use for this session.
Will be loaded and managed by this builder’s assigned
ContentDriver.- Parameters:
content (
TypeAliasType) –The content to use for this session. May be one of the following:
str,PathLikeWill load a single content file without enabling a subsystem.
zipfile.PathWill load a single content file within a ZIP archive without enabling a subsystem.
bytes,bytearray,memoryview,BufferWill expose a single unnamed content buffer without enabling a subsystem.
SubsystemContentWill enable a subsystem and load multiple associated content files.
retro_game_infoWill be passed to the core as-is without enabling a subsystem.
NoneWill load the core without using any content or enabling a subsystem; if not supported by the core, this will raise an error in
build(). Note thatretro_load_gamewill be called.Callable() ->Content|SubsystemContent|NoneZero-argument function that returns one of the above. Will be called in
build().
- Return type:
Self- Returns:
This
SessionBuilderobject.- Raises:
TypeError – If
contentis not one of the permitted types.- See:
ContentDriver.load()for details on how loaded content is exposed to the core.
- with_audio(audio)[source]¶
Set the audio driver for this session.
- Parameters:
audio (
TypeAliasType) –The audio driver to use for this session. May be one of the following:
AudioDriverWill be used by the built
Sessionas-is.DEFAULTWill use an
ArrayAudioDriverwith its default configuration.Callable() ->AudioDriverZero-argument function that returns an
AudioDriver. Will be called inbuild().
- Return type:
Self- Returns:
This
SessionBuilderobject.- Raises:
TypeError – If
audiois not one of the permitted types.ValueError – If
audioisNone.
- with_input(input)[source]¶
Set the input driver for this session.
- Parameters:
input (
TypeAliasType) –The input driver to use for this session. May be one of the following:
InputDriverWill be used by the built
Sessionas-is.Generator,Iterable,IteratorWill be wrapped in an
IterableInputDriverthat yieldsInputPollResultvalues.DEFAULTWill use an
IterableInputDriverwith its default configuration.Callable() ->InputDriver| iterableZero-argument function that returns either an
InputDriveror an iterable/iterator/generator ofInputPollResultvalues. Will be called inbuild().
- Return type:
Self- Returns:
This
SessionBuilderobject.- Raises:
TypeError – If
input(or the value returned by a callableinput) is not one of the permitted types.ValueError – If
inputisNone.
- with_rumble(rumble)[source]¶
Configure the rumble driver for this session’s input driver.
- Parameters:
rumble (
TypeAliasType) –The rumble driver to use for this session. May be one of the following:
RumbleDriverWill be used by the built
Sessionas-is.NoneNo rumble driver will be used, and any rumble interfaces that the core exposes will not function.
DEFAULTWill use a
DictRumbleDriverwith no initial state.Callable() ->RumbleDriver|NoneZero-argument function that returns a
RumbleDriverorNone. Will be called inbuild().
- Return type:
Self- Returns:
This
SessionBuilderobject.- Raises:
TypeError – If
rumbleis not one of the aforementioned types.
- with_video(video)[source]¶
Set the video driver for this session.
- Parameters:
video (
TypeAliasType) –The video driver to use for this session. May be one of the following:
VideoDriverUsed by the built
Sessionas-is.DEFAULTUses a
MultiVideoDriverwith its default configuration. See its documentation for more details.Mapping[HardwareContext,Callable() ->VideoDriver]Uses a
MultiVideoDriverwith the provided driver map.Callable() ->VideoDriverZero-argument function that returns a
VideoDriver. Called inbuild().
- Return type:
Self- Returns:
This
SessionBuilderobject.- Raises:
TypeError – If
videois not one of the aforementioned types.ValueError – If
videodoes not contain a mapping forHardwareContext.NONE.
- with_content_driver(content)[source]¶
Set the content driver for this session.
- Parameters:
content (
TypeAliasType) –The content driver to use for this session. May be one of the following:
ContentDriverWill be used by the built
Sessionas-is.DEFAULTWill use a
StandardContentDriverwith its default configuration.NoneNo content driver will be used; content set via
with_content()will not be loaded.Callable() ->ContentDriver|NoneZero-argument function that returns a
ContentDriverorNone. Will be called inbuild().
- Return type:
Self- Returns:
This
SessionBuilderobject.- Raises:
TypeError – If
contentis not one of the permitted types.
- with_overscan(overscan)[source]¶
Set whether the loaded core should render overscan regions.
- Parameters:
overscan (
TypeAliasType) –The overscan flag to expose to the core. May be one of the following:
- Return type:
Self- Returns:
This
SessionBuilderobject.- Raises:
TypeError – If
overscanis not one of the permitted types.
- with_message(message)[source]¶
Set the message driver for this session.
- Parameters:
message (
TypeAliasType) –The message driver to use for this session. May be one of the following:
MessageDriverWill be used by the built
Sessionas-is.LoggerWill be wrapped in a
LoggerMessageDriverthat forwards messages to the given logger.DEFAULTWill use a
LoggerMessageDriverwith its default configuration.NoneThe environment calls that
MessageDrivernormally implements will be unavailable to the loadedCore.Callable() ->MessageDriver|NoneZero-argument function that returns a
MessageDriverorNone. Will be called inbuild().
- Return type:
Self- Returns:
This
SessionBuilderobject.- Raises:
TypeError – If
messageis not one of the permitted types.
- with_options(options)[source]¶
Configure the options driver for this session.
- Parameters:
options (
TypeAliasType) –May be one of the following:
OptionDriverWill be used by the built
Sessionas-is.Mapping[AnyStr,AnyStr]Will be used to initialize a
DictOptionDriverwith the provided options and with API version 2. All keys and values must be eitherstrorbytes; mixing the two is not allowed.0,1, or2Will be used to initialize a
DictOptionDriverwith no initial options using the provided API version.DEFAULTWill use a
DictOptionDriverwith API version 2 and no initial options.NoneAll environment calls that
OptionDrivernormally implements will be unavailable to the loadedCore.Callable() ->OptionDriver|NoneZero-argument function that returns an
OptionDriverorNone. Will be called inbuild().
- Return type:
Self- Returns:
This
SessionBuilderobject.- Raises:
TypeError – If
optionsis not one of the aforementioned types.ValueError – If
optionsis aMappingwhose keys and values are not allstrorbytes.
- with_paths(path)[source]¶
Configure the path driver for this session.
- Parameters:
path (
TypeAliasType) –May be one of the following:
PathDriverWill be used by the built
Sessionas-is.DEFAULTWill use a
TempDirPathDriverconfigured with an unspecified temporary directory and the providedCore’s path.Callable(Core) ->PathDriver|NoneOne-argument function that accepts a
Coreand returns aPathDriverorNone. Will be called inbuild()with the configuredCoreas the argument.NoneAll environment calls that
PathDrivernormally implements will be unavailable to the loadedCore.
- Return type:
Self- Returns:
This
SessionBuilderobject.- Raises:
TypeError – If
pathis not one of the aforementioned types.
- with_sensor(sensor)[source]¶
Configure the sensor driver for this session.
- Parameters:
sensor (
TypeAliasType) –May be one of the following:
SensorDriverWill be used by the built
Sessionas-is.NoneAll environment calls and interfaces that
SensorDrivernormally implements will be unavailable to the loadedCore.DEFAULTWill use an
IterableSensorDriverwhose sensor state can be configured, but does not produce any nonzero readings.Callable() ->SensorDriverZero-argument function that returns the
SensorDriverthat the builtSessionwill use.Callable() ->Iterable|IteratorZero-argument function that returns an iterator or generator that yields elements as described in
IterableSensorDriver. AnIterableSensorDriverwill be created from this iterator.Iterable|IteratorAn iterator, iterable, or generator function that yields elements as described in
IterableSensorDriver. AnIterableSensorDriverwill be created from this iterator.
- Return type:
Self- Returns:
This
SessionBuilderobject.
- with_log(log)[source]¶
Set the log driver for this session.
- Parameters:
log (
TypeAliasType) –The log driver to use for this session. May be one of the following:
LogDriverWill be used by the built
Sessionas-is.LoggerWill be wrapped in an
UnformattedLogDriverthat forwards core log messages to the given logger.DEFAULTWill use an
UnformattedLogDriverwith its default configuration.NoneThe log interface will be unavailable to the loaded
Core.Callable() ->LogDriver|NoneZero-argument function that returns a
LogDriverorNone. Will be called inbuild().
- Return type:
Self- Returns:
This
SessionBuilderobject.- Raises:
TypeError – If
logis not one of the permitted types.
- with_perf(perf)[source]¶
Set the performance driver for this session.
- Parameters:
perf (
TypeAliasType) –The performance driver to use for this session. May be one of the following:
PerfDriverWill be used by the built
Sessionas-is.DEFAULTWill use a
DefaultPerfDriverwith its default configuration.NoneThe performance interface will be unavailable to the loaded
Core.Callable() ->PerfDriver|NoneZero-argument function that returns a
PerfDriverorNone. Will be called inbuild().
- Return type:
Self- Returns:
This
SessionBuilderobject.- Raises:
TypeError – If
perfis not one of the permitted types.
- with_location(location)[source]¶
Set the location driver for this session.
- Parameters:
location (
TypeAliasType) –The location driver to use for this session. May be one of the following:
LocationDriverWill be used by the built
Sessionas-is.DEFAULTNo location driver will be used; equivalent to passing
None.NoneThe location interface will be unavailable to the loaded
Core.Callable() ->LocationDriver|NoneZero-argument function that returns a
LocationDriverorNone. Will be called inbuild().
- Return type:
Self- Returns:
This
SessionBuilderobject.- Raises:
TypeError – If
locationis not one of the permitted types.
- with_user(user)[source]¶
Set the user driver for this session.
- Parameters:
user (
TypeAliasType) –The user driver to use for this session. May be one of the following:
UserDriverWill be used by the built
Sessionas-is.DEFAULTWill use a
DefaultUserDriverwith its default configuration.NoneThe environment calls that
UserDrivernormally implements will be unavailable to the loadedCore.Callable() ->UserDriver|NoneZero-argument function that returns a
UserDriverorNone. Will be called inbuild().
- Return type:
Self- Returns:
This
SessionBuilderobject.- Raises:
TypeError – If
useris not one of the permitted types.
- with_vfs(vfs)[source]¶
Set the virtual filesystem driver for this session.
- Parameters:
vfs (
TypeAliasType) –The filesystem driver to use for this session. May be one of the following:
FileSystemDriverWill be used by the built
Sessionas-is.1,2, or3Will use a
DefaultFileSystemDriverwith the given API version.DEFAULTWill use a
DefaultFileSystemDriverwith its default configuration.NoneThe VFS interface will be unavailable to the loaded
Core.Callable() ->FileSystemDriver|NoneZero-argument function that returns a
FileSystemDriverorNone. Will be called inbuild().
- Return type:
Self- Returns:
This
SessionBuilderobject.- Raises:
TypeError – If
vfsis not one of the permitted types.
- with_led(led)[source]¶
Set the LED driver for this session.
- Parameters:
led (
TypeAliasType) –The LED driver to use for this session. May be one of the following:
- Return type:
Self- Returns:
This
SessionBuilderobject.- Raises:
TypeError – If
ledis not one of the permitted types.
- with_av_mask(av_mask)[source]¶
Set the audio/video enable mask for this session.
- Parameters:
av_mask (
TypeAliasType) –The
AvEnableFlagsto expose to the core. May be one of the following:AvEnableFlagsWill be reported to the core as-is.
DEFAULTReports
AvEnableFlags.ALLto the core.NoneThe corresponding environment call will be unavailable to the core.
Callable() ->AvEnableFlags|NoneZero-argument function that returns an
AvEnableFlagsorNone. Will be called inbuild().
- Return type:
Self- Returns:
This
SessionBuilderobject.- Raises:
TypeError – If
av_maskis not one of the permitted types.
- with_midi(midi)[source]¶
Set the MIDI driver for this session.
- Parameters:
midi (
TypeAliasType) –The MIDI driver to use for this session. May be one of the following:
MidiDriverWill be used by the built
Sessionas-is.DEFAULTWill use a
GeneratorMidiDriverwith its default configuration.NoneThe MIDI interface will be unavailable to the loaded
Core.Callable() ->MidiDriver|NoneZero-argument function that returns a
MidiDriverorNone. Will be called inbuild().
- Return type:
Self- Returns:
This
SessionBuilderobject.- Raises:
TypeError – If
midiis not one of the permitted types.
- with_timing(timing)[source]¶
Set the timing driver for this session.
- Parameters:
timing (
TypeAliasType) –The timing driver to use for this session. May be one of the following:
TimingDriverWill be used by the built
Sessionas-is.DEFAULTWill use a
DefaultTimingDriverrunning unblocked at 60 FPS.NoneThe corresponding environment calls will be unavailable to the core.
Callable() ->TimingDriver|NoneZero-argument function that returns a
TimingDriverorNone. Will be called inbuild().
- Return type:
Self- Returns:
This
SessionBuilderobject.- Raises:
TypeError – If
timingis not one of the permitted types.
- with_preferred_hw(hw)[source]¶
Set the preferred hardware context to report to the core.
- Parameters:
hw (
TypeAliasType) –The preferred hardware context to expose to the core. May be one of the following:
HardwareContextWill be reported to the core as-is.
DEFAULTThe corresponding environment call will be unavailable to the core.
NoneThe corresponding environment call will be unavailable to the core.
Callable() ->HardwareContext|NoneZero-argument function that returns a
HardwareContextorNone. Will be called inbuild().
- Return type:
Self- Returns:
This
SessionBuilderobject.- Raises:
TypeError – If
hwis not one of the permitted types.
- with_driver_switch_enable(enable)[source]¶
Set whether the core may switch hardware rendering drivers at runtime.
- Parameters:
enable (
TypeAliasType) –The driver-switch flag to expose to the core. May be one of the following:
- Return type:
Self- Returns:
This
SessionBuilderobject.- Raises:
TypeError – If
enableis not one of the permitted types.
- with_savestate_context(context)[source]¶
Set the savestate context to report to the core.
- Parameters:
context (
TypeAliasType) –The
SavestateContextto expose to the core. May be one of the following:SavestateContextWill be reported to the core as-is.
DEFAULTReports
SavestateContext.NORMALto the core.NoneThe corresponding environment call will be unavailable to the core.
Callable() ->SavestateContext|NoneZero-argument function that returns a
SavestateContextorNone. Will be called inbuild().
- Return type:
Self- Returns:
This
SessionBuilderobject.- Raises:
TypeError – If
contextis not one of the permitted types.
- with_jit_capable(capable)[source]¶
Set whether the host environment is JIT-capable.
- Parameters:
capable (
TypeAliasType) –The JIT-capable flag to expose to the core. May be one of the following:
- Return type:
Self- Returns:
This
SessionBuilderobject.- Raises:
TypeError – If
capableis not one of the permitted types.
- with_mic(mic)[source]¶
Set the microphone driver for this session.
- Parameters:
mic (
TypeAliasType) –The microphone driver to use for this session. May be one of the following:
MicrophoneDriverWill be used by the built
Sessionas-is.DEFAULTWill use a
GeneratorMicrophoneDriverwith its default configuration.NoneThe microphone interface will be unavailable to the loaded
Core.Callable() ->MicrophoneDriver|NoneZero-argument function that returns a
MicrophoneDriverorNone. Will be called inbuild().
- Return type:
Self- Returns:
This
SessionBuilderobject.- Raises:
TypeError – If
micis not one of the permitted types.
- with_power(power)[source]¶
Set the power driver for this session.
- Parameters:
power (
TypeAliasType) –The power driver to use for this session. May be one of the following:
PowerDriverWill be used by the built
Sessionas-is.retro_device_powerWill be wrapped in a
ConstantPowerDriverthat always reports this state.DEFAULTWill use a
ConstantPowerDriverreporting a fully charged, plugged-in device.NoneThe power interface will be unavailable to the loaded
Core.Callable() ->PowerDriver|NoneZero-argument function that returns a
PowerDriverorNone. Will be called inbuild().
- Return type:
Self- Returns:
This
SessionBuilderobject.- Raises:
TypeError – If
poweris not one of the permitted types.
- build()[source]¶
Construct a
Sessionwith the provided arguments.- Raises:
RequiredError – If a
Core,AudioDriver,InputDriver, orVideoDriveris not set.Exception – Any exception raised by a registered driver factory or initializer.
- Return type:
TypeAliasType- Returns:
A
Sessionobject.
- static __new__(*args, **kwargs)¶
- DEFAULT = _DefaultType.DEFAULT¶
A placeholder that indicates the default value for one of
SessionBuilder’s arguments. When passed to one ofSessionBuilder’swith_methods, it will use the default driver or argument configuration unless otherwise noted.
- defaults(core)[source]¶
Construct a
SessionBuilderwith the recommended drivers and their default values.Does not build the session, so these defaults may still be overridden.
- Parameters:
core (
Core|str|PathLike[str] |PathLike[bytes] |CDLL|GenericAlias[Core]) – The core to use for the session.- Return type:
Examples:
builder = SessionBuilder.defaults(core) with builder.with_log(None).build() as session: pass
- exception RequiredError[source]¶
Bases:
RuntimeErrorRaised by
SessionBuilder.build()when a required argument has not been set.- __init__(*args, **kwargs)¶
- classmethod __new__(*args, **kwargs)¶
- add_note(note, /)¶
Add a note to the exception
- args¶
- with_traceback(tb, /)¶
Set self.__traceback__ to tb and return self.
- type AnySession = Session[AudioDriver, InputDriver, VideoDriver, ContentDriver | None, MessageDriver | None, OptionDriver | None, PathDriver | None, RumbleDriver | None, SensorDriver | None, CameraDriver | None, LogDriver | None, PerfDriver | None, LocationDriver | None, UserDriver | None, FileSystemDriver | None, LedDriver | None, MidiDriver | None, TimingDriver | None, MicrophoneDriver | None, PowerDriver | None]¶