diff --git a/beet/contrib/rename_files.py b/beet/contrib/rename_files.py index bc137b8a0..790673529 100644 --- a/beet/contrib/rename_files.py +++ b/beet/contrib/rename_files.py @@ -116,7 +116,7 @@ def handle_filename_for_namespace_file( ): dest = self.substitute(filename) file_type = type(file_instance) - scope = get_output_scope(file_type.scope, pack.pack_format) + scope = get_output_scope(file_type.scope, pack) prefix = "".join(f"{d}/" for d in scope) _, namespace, path = filename.split("/", 2) diff --git a/beet/library/base.py b/beet/library/base.py index 32a34958e..05aec8ee7 100644 --- a/beet/library/base.py +++ b/beet/library/base.py @@ -579,9 +579,7 @@ def list_files( if extend and not issubclass(content_type, extend): continue - scope = get_output_scope( - content_type.scope, self.pack.pack_format if self.pack else 0 - ) + scope = get_output_scope(content_type.scope, self.pack) prefix = "/".join((self.directory, namespace) + scope) for name, item in container.items(): yield f"{overlay}{prefix}/{name}{content_type.extension}", item @@ -1575,9 +1573,28 @@ def list_input_scopes(scope: NamespaceFileScope) -> Iterable[Tuple[str, ...]]: return [scope] if isinstance(scope, tuple) else scope.values() -def get_output_scope(scope: NamespaceFileScope, pack_format: int) -> Tuple[str, ...]: +def get_output_scope( + scope: NamespaceFileScope, pack: Optional[int | Pack[Any]] +) -> Tuple[str, ...]: if isinstance(scope, tuple): return scope + + if pack is None: + # Fall back to the most recent scope + pack_format = 9999 + elif isinstance(pack, int): + pack_format = pack + else: + # Use the pack format from the pack's supported_formats. + # Otherwise, use the pack_format itself + if isinstance(pack.supported_formats, int): + pack_format = pack.supported_formats + elif isinstance(pack.supported_formats, list): + pack_format = pack.supported_formats[1] + elif isinstance(pack.supported_formats, dict): + pack_format = pack.supported_formats["max_inclusive"] + else: + pack_format = pack.pack_format result: Tuple[str, ...] | None = None result_format: int | None = None for key, value in scope.items(): diff --git a/beet/toolchain/query.py b/beet/toolchain/query.py index 858c826f1..e32deba3c 100644 --- a/beet/toolchain/query.py +++ b/beet/toolchain/query.py @@ -229,7 +229,7 @@ def analyze_base_paths( escaped = GitWildMatchPattern.escape(path) if path == escaped: - scope = get_output_scope(file_type.scope, pack.pack_format) + scope = get_output_scope(file_type.scope, pack) prefix = "/".join([directory, namespace, *scope]) base_paths.add(f"{overlay}{prefix}/{path}{file_type.extension}") continue @@ -240,7 +240,7 @@ def analyze_base_paths( break common.append(part) - scope = get_output_scope(file_type.scope, pack.pack_format) + scope = get_output_scope(file_type.scope, pack) prefix = "/".join([directory, namespace, *scope, *common]) base_paths.add(f"{overlay}{prefix}") diff --git a/examples/load_overlay/beet.yml b/examples/load_overlay/beet.yml index 0619fa3ee..8045138c2 100644 --- a/examples/load_overlay/beet.yml +++ b/examples/load_overlay/beet.yml @@ -1,7 +1,7 @@ data_pack: load: "src" - pack_format: 20 - supported_formats: [18, 19, 20] + pack_format: 50 + supported_formats: [50, 50] overlays: - formats: min_inclusive: 18 diff --git a/examples/load_overlay/src/pack.mcmeta b/examples/load_overlay/src/pack.mcmeta index d145ca2d9..1b5afc512 100644 --- a/examples/load_overlay/src/pack.mcmeta +++ b/examples/load_overlay/src/pack.mcmeta @@ -2,11 +2,17 @@ "overlays": { "entries": [ { - "formats": {"min_inclusive": 17, "max_inclusive": 18}, + "formats": { + "min_inclusive": 17, + "max_inclusive": 18 + }, "directory": "overlay1" }, { - "formats": {"min_inclusive": 18, "max_inclusive": 19}, + "formats": { + "min_inclusive": 18, + "max_inclusive": 19 + }, "directory": "overlay2" }, { @@ -15,4 +21,4 @@ } ] } -} +} \ No newline at end of file diff --git a/tests/snapshots/examples__build_load_overlay__0.data_pack/data/demo/functions/foo.mcfunction b/tests/snapshots/examples__build_load_overlay__0.data_pack/data/demo/function/foo.mcfunction similarity index 100% rename from tests/snapshots/examples__build_load_overlay__0.data_pack/data/demo/functions/foo.mcfunction rename to tests/snapshots/examples__build_load_overlay__0.data_pack/data/demo/function/foo.mcfunction diff --git a/tests/snapshots/examples__build_load_overlay__0.data_pack/pack.mcmeta b/tests/snapshots/examples__build_load_overlay__0.data_pack/pack.mcmeta index 1aa5c97cc..3a177a56e 100644 --- a/tests/snapshots/examples__build_load_overlay__0.data_pack/pack.mcmeta +++ b/tests/snapshots/examples__build_load_overlay__0.data_pack/pack.mcmeta @@ -1,11 +1,10 @@ { "pack": { - "pack_format": 20, + "pack_format": 50, "description": "", "supported_formats": [ - 18, - 19, - 20 + 50, + 50 ] }, "overlays": { @@ -37,4 +36,4 @@ } ] } -} +} \ No newline at end of file