Bundle Submodule
SRToolkit.bundle
Bundle sharing utilities for the Symbolic Regression Toolkit.
Provides tools for packing, installing, and using bundles of user-defined Python
code as .srtk archives. Bundles contain code only — configs (the settings
a user chose) are intentionally separate so they can be shared, versioned, and
tweaked independently of the implementation.
Workflow
Author side — pack the code:
from SRToolkit.bundle import pack
pack(
files=["my_approach/approach.py", "my_approach/ops.py"],
out_path="meznar_gp.srtk",
name="meznar-gp",
version="0.1.0",
author="meznar",
python_deps=["torch>=2.0"],
)
Share the .srtk file and a plain JSON config separately.
Recipient side — install and use:
import json
from SRToolkit.bundle import install
install("meznar_gp.srtk") # one-time, interactive
raw = json.load(open("meznar_settings.srtk.json")) # config shared separately
# The config is annotated with _bundle/_version by pack(..., configs=[...]),
# so it can be passed straight to any project `from_dict` consumer
# (SR_dataset, Sampler, the experiment grid, ...) — they call bind_config
# internally to repoint every *_class path at the installed bundle.
benchmark = SR_benchmark.from_dict(raw)
If the config was not annotated by pack (no _bundle key), bind it
explicitly first, passing the bundle name:
Listing and removing:
from SRToolkit.bundle import list_installed, uninstall
for entry in list_installed():
print(entry["name"], entry["version"])
uninstall("meznar-gp", version="0.1.0")
install
Install a .srtk bundle onto this machine.
Steps:
- Unzip to a temporary directory and load the manifest.
- Verify per-file checksums declared in the manifest.
- Check the required
SRToolkitversion. - Check Python dependencies — list missing ones and suggest a
pip installcommand; the user decides whether to continue. - Prompt the user to confirm that arbitrary user code will be executable.
- Copy
src/to the managed bundle directory. - Register the bundle in the local index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
srtk_path
|
Path
|
Path to a |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
On checksum mismatch. |
RuntimeError
|
If the installed SRToolkit is too old. |
Source code in SRToolkit/bundle/_install.py
list_installed
Return a list of all installed bundle index entries.
Each entry is a dict with keys name, version, author,
srtk_min_version, python_deps, path, and import_prefix.
Source code in SRToolkit/bundle/_install.py
read_manifest
Read a .srtk bundle's manifest without installing it.
Reads only the manifest.json entry from the archive — the bundle's source files
are not extracted, no checksums are verified, and the global bundle store is not
touched. Use this to inspect a not-yet-installed bundle's name / version /
import_prefix (e.g. to match referenced class paths against a bundle a user
supplied to ExperimentGrid.export).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
srtk_path
|
Path
|
Path to the |
required |
Returns:
| Type | Description |
|---|---|
BundleManifest
|
The bundle's BundleManifest. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If |
ValueError
|
If the archive is not a valid bundle (no |
Source code in SRToolkit/bundle/_install.py
uninstall
Remove an installed bundle from this machine.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Bundle name. |
required |
version
|
Optional[str]
|
Version to remove. If |
None
|
Source code in SRToolkit/bundle/_install.py
pack
pack(files: Sequence[Union[str, Path]], out_path: Path, name: str, version: str, author: str = '', python_deps: List[str] | None = None, srtk_min_version: str = '', configs: Optional[Sequence[Union[str, Path]]] = None) -> None
Pack a list of Python source files into a .srtk bundle.
Each file is stored flat under src/ using its basename, so all filenames
must be unique. Configs are intentionally excluded from the archive — share
them separately as plain JSON. Class paths are rewritten at use-time by
calling bind_config.
If configs is provided, each JSON config file is annotated with
_bundle and _version metadata and written next to the original with
a .srtk.json suffix (e.g. settings.json → settings.srtk.json).
These annotated copies are the files to share alongside the .srtk bundle;
the originals are left untouched.
The archive layout is::
manifest.json
src/
<basename of each file>
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
files
|
Sequence[Union[str, Path]]
|
Paths to the |
required |
out_path
|
Path
|
Destination path for the |
required |
name
|
str
|
Bundle name (alphanumeric, hyphens allowed). |
required |
version
|
str
|
Semantic version string, e.g. |
required |
author
|
str
|
Optional author identifier. |
''
|
python_deps
|
List[str] | None
|
List of PEP 508 dependency specifiers, e.g. |
None
|
srtk_min_version
|
str
|
Minimum |
''
|
configs
|
Optional[Sequence[Union[str, Path]]]
|
Optional list of JSON config file paths to annotate. Each is
written to |
None
|
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If any source or config file does not exist. |
ValueError
|
If a source file is not |
Source code in SRToolkit/bundle/_pack.py
bind_config
Rewrite *_class paths in config to point at an installed bundle.
Looks up bundle_name in the local bundle index and rewrites every
*_class value so that it resolves to the installed copy's import prefix.
Paths already starting with SRToolkit. are left unchanged.
If bundle_name is not provided, the _bundle and _version keys
embedded in the config by pack are used as
fallbacks. This allows calling bind_config(config) directly when the
config was annotated at pack time.
This is the recipient-side complement to pack for configs:
the author shares the .srtk file (code) and an annotated .srtk.json
config; the recipient installs the bundle once and then calls bind_config
to make the config usable on their machine.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
dict
|
JSON-style configuration dictionary, optionally containing
|
required |
bundle_name
|
Optional[str]
|
Name of an installed bundle. If |
None
|
version
|
Optional[str]
|
Version to bind against. If |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
A new dictionary with rewritten |
dict
|
with |
dict
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
KeyError
|
If the bundle (or requested version) is not installed. |
LookupError
|
If a |
Source code in SRToolkit/bundle/_relocate.py
enable_bundle_imports
Make installed bundles importable in the current Python process.
Adds the bundles-root parent directory to sys.path (if not already
present) so that import srtk_bundles.<safe_name>_<version_slug> works.
Idempotent and safe to call repeatedly.
Called automatically at the end of install and
by bind_config. Call it directly only when
you want to import a bundle's classes by hand in a fresh Python session
without going through from_dict / bind_config.
Source code in SRToolkit/bundle/_store.py
SRToolkit.bundle._manifest.BundleManifest
dataclass
BundleManifest(name: str, version: str, author: str = '', srtk_min_version: str = '', python_deps: List[str] = list(), files: Dict[str, str] = dict())
verify
Raise ValueError if any declared file is missing or has a wrong checksum.