This module handles centralized configuration for the pmp_manip project. It allows setting and validating all configuration parameters exactly once, after which they are deeply frozen to prevent further modification.
For field-specific documentation, refer to the table at the bottom.
The configuration system is composed of several modular configuration dataclasses:
ExtInfoGenConfigValidationConfigPlatformMetaConfig
These are composed into a single root config: MasterConfig, which is initialized and accessed globally throughout the project.
Initializes the global configuration with a fully populated MasterConfig. This function must only be called once, ideally at application startup.
- Validates the full config tree via
.validate() - Sets all sub-configs and the master config as immutable
- Subsequent calls to
init_config()will raise an error
Raises:
ConfigurationError – if config has already been initialized
Returns the globally set, frozen configuration. Should be used by all internal modules to access config values.
Raises:
ConfigurationError – if config hasn't been initialized yet
Returns a pre-built MasterConfig with safe, reasonable defaults. This can be used:
- As a base for testing
- To bootstrap the system with minimal input
- For default-based override logic
| argument | type | purpose | default |
|---|---|---|---|
gen_opcode_info_dir |
directory path str | directory used to store the generated extension opcode info files in |
"gen_ext_opcode_info" |
js_fetch_interval |
datetime.timedelta | if the extension is accessed through a link, it will only be fetched again after this interval has passed |
timedelta(days=3) |
node_js_exec_timeout |
float (secs) | if the extension code is directly executed, the timeout secs of the Node.js suprocess |
2.0 (secs) |
is_trusted_extension_origin_handler |
Callable(str -> bool) or None | takes the ext source and returns wether an unknown extension source can be trusted and if it will therefore be directly executed |
None |
| argument | type | purpose | default |
|---|---|---|---|
raise_if_monitor_position_outside_stage |
bool | during validation an ValidationError will be raised if a monitor's position is outside the stage edges |
True |
raise_if_monitor_bigger_then_stage |
bool | during validation an ValidationError will be raised if a list monitor's size is bigger then the stage |
True |
| argument | type | purpose | default |
|---|---|---|---|
scratch_semver |
version no. str | holds up to date version of Scratch for project meta generation |
"3.0.0" |
scratch_vm |
version no. str | holds up to date version of the Scratch VM. " |
"11.1.0" |
penguinmod_vm |
version no. str | holds up to date version of the PenguinMod VM. " |
"0.2.0" |
from pmp_manip import (
init_config, get_config, get_default_config,
)
# Start from defaults
cfg = get_default_config()
# Override only the fields you want to change
cfg.ext_info_gen.gen_opcode_info_dir = "my/overridden/path"
cfg.validation.raise_if_monitor_position_outside_stage = False
# Initialize with modified config
init_config(cfg)
# ... Use the pmp_manip module however you want from herefrom pmp_manip import (
init_config, get_config,
ExtInfoGenConfig, ValidationConfig,
PlatformMetaConfig, MasterConfig,
)
from datetime import timedelta
# Initialize once, early in main
init_config(MasterConfig(
ext_info_gen=ExtInfoGenConfig(
gen_opcode_info_dir="my/output/dir",
js_fetch_interval=timedelta(days=2),
node_js_exec_timeout=3.5,
is_trusted_extension_origin_handler=lambda source: source.startswith("https://example.com/"),
),
validation=ValidationConfig(
raise_if_monitor_position_outside_stage=True,
raise_if_monitor_bigger_then_stage=False,
),
platform_meta=PlatformMetaConfig(
scratch_semver="3.0.0",
scratch_vm="11.1.0",
penguinmod_vm="0.2.0",
),
))
# ... Use the pmp_manip module however you want from here- For a documentation overview and all pages of the tutorial, see docs/index.md
- Next Page: Loading and Creating Projects, see docs/load_create.md