🚚 migrate#
stewbeet migrate [minimal|basic] [--dry-run] [--yes]: turn an existing datapack or resource pack into a StewBeet project.
- MIGRATION_TEMPLATES: tuple[str, ...] = ('minimal', 'basic')[source]#
Templates a pack can be migrated onto. The extensive one ships example content that would mix with the pack’s.
- migrate_command() None[source]#
Parse the command line, then migrate the packs found in the working directory.
- select_packs(
- working_dir: Path,
The datapack and the resource pack to migrate, or None after telling the user why there is nothing to migrate.
- download_template(template_name: str) bytes | None[source]#
The template archive matching the installed StewBeet version, or None after reporting why it could not be fetched.
- run_migration(
- working_dir: Path,
- template: ZipFile,
- datapack: FoundPack | None,
- resource_pack: FoundPack | None,
- *,
- dry_run: bool,
- assume_yes: bool,
Show the plan, then apply it unless this is a dry run or the user declines.
- Returns:
The plan when it could run (applied, unless
dry_run), None when it was refused or cancelled.
packs#
Find the datapacks and resource packs a folder holds, before stewbeet migrate turns it into a project.
- SKIPPED_FOLDERS: frozenset[str] = frozenset({'__pycache__', 'build', 'node_modules'})[source]#
Folders never searched, on top of hidden ones: they hold outputs and dependencies, not sources.
- PLAIN_PACK_KEYS: frozenset[str] = frozenset({'description', 'pack_format'})[source]#
Keys of the “pack” object that beet.yml and StewBeet already produce, so a pack.mcmeta holding only these can go.
- class FoundPack(
- root: Path,
- has_data: bool,
- has_assets: bool,
- mcmeta: JsonDict,
Bases:
objectA folder holding a pack.mcmeta next to a data/ folder, an assets/ folder, or both.
- static read(
- folder: Path,
The pack in
folder, or None when it holds no pack.mcmeta or neither data/ nor assets/.
- property is_plain: bool[source]#
Whether pack.mcmeta holds nothing beyond a description and a pack format.
>>> FoundPack(Path("."), True, False, {"pack": {"pack_format": 61, "description": "Hi"}}).is_plain True >>> FoundPack(Path("."), True, False, {"pack": {"pack_format": 61}, "overlays": {}}).is_plain False
- property description_yaml: str | None[source]#
The description as a YAML value for beet.yml, None when pack.mcmeta has none. JSON is valid YAML, which keeps a text component description intact.
>>> FoundPack(Path("."), True, False, {"pack": {"description": "Épée"}}).description_yaml '"Épée"'
plan#
Everything stewbeet migrate will do, worked out before anything on disk changes.
A dry run prints the plan, a real run prints it and then applies it, so --dry-run shows exactly what happens.
- TEMPLATE_ICONS: tuple[str, ...] = ('src/pack.png', 'assets/pack.png')[source]#
Where a template may keep its pack.png. The migrated icon goes wherever the chosen template has it.
- RESOURCE_PACK_CONFIG: str = '\n# Loads src/assets/, where `stewbeet migrate` moved your resource pack\nresource_pack:\n name: "resource_pack"\n load: ["src"]\n'[source]#
Appended to a template’s beet.yml that only builds a datapack, when a resource pack is migrated.
- class WriteConfig(text: str, changes: tuple[str, ...])[source]#
Bases:
objectThe template’s beet.yml, filled in from the migrated packs.
- class MigrationPlan(
- working_dir: pathlib.Path,
- steps: tuple[stewbeet.core.migrate.plan.Move | stewbeet.core.migrate.plan.Extract | stewbeet.core.migrate.plan.Skip | stewbeet.core.migrate.plan.Delete | stewbeet.core.migrate.plan.RemoveFolder | stewbeet.core.migrate.plan.WriteConfig, ...],
- warnings: tuple[str, ...],
Bases:
object- steps: tuple[Move | Extract | Skip | Delete | RemoveFolder | WriteConfig, ...][source]#
In the order they are applied.
- build_plan( ) MigrationPlan[source]#
Everything moving these packs into the template takes, without touching the disk.
- Parameters:
datapack – The pack whose data/ is migrated, possibly the same folder as
resource_pack.resource_pack – The pack whose assets/ is migrated.
- plan_template_files(
- working_dir: Path,
- template: ZipFile,
- datapack: FoundPack | None,
- resource_pack: FoundPack | None,
- replaced_icon: str | None,
Which template files are written, and why the others are not. The template never writes over a file.
- plan_config( ) tuple[WriteConfig, list[str]][source]#
The template’s beet.yml with the migrated project’s own values, and what is still left to fill in by hand.
- fill_identity(
- text: str,
- main_pack: FoundPack | None,
- namespaces: list[str],
Replace the template’s name and id with the pack’s, for the templates that set them.
- Returns:
The new config text, the changes made, and the warnings about what could not be filled in.
- plan_moves(
- working_dir: Path,
- packs: list[FoundPack],
- icon: Path | None,
- icon_destination: Path,
data/ and assets/ into src/, and the icon to where the template keeps its own.
- plan_mcmeta(
- working_dir: Path,
- packs: list[FoundPack],
A plain pack.mcmeta is folded into beet.yml, a richer one moves to src/ (at most one can).
- plan_cleanup(
- working_dir: Path,
- packs: list[FoundPack],
- pack_steps: list[Move | Extract | Skip | Delete | RemoveFolder | WriteConfig],
The pack folders, and their parents, that nothing is left in once the files have moved. Deepest first.
- has_config_key(text: str, key: str) bool[source]#
Whether a top-level key is set in a YAML config.
>>> has_config_key('id: "a"\n name: "b"', "name") False
- set_config_key(text: str, key: str, value: str) str[source]#
Set a top-level key of a YAML config, keeping every comment. A missing key is appended.
- Parameters:
value – Already a YAML value, quotes included.
>>> set_config_key('id: "a"\nname: "b"\n', "id", '"c"') 'id: "c"\nname: "b"\n' >>> set_config_key('output: "build"\n', "description", '"Hi"') 'output: "build"\n\ndescription: "Hi"\n'