From 913ce0679504c489a9814b73768cf65b83dce6a0 Mon Sep 17 00:00:00 2001 From: RitikShah Date: Fri, 6 Sep 2024 11:18:11 -0400 Subject: [PATCH 1/9] fix: partial impl --- beet/library/base.py | 20 +++++++++++++++---- examples/load_overlay/beet.yml | 4 ++-- examples/load_overlay/src/pack.mcmeta | 12 ++++++++--- .../{functions => function}/foo.mcfunction | 0 .../pack.mcmeta | 9 ++++----- 5 files changed, 31 insertions(+), 14 deletions(-) rename tests/snapshots/examples__build_load_overlay__0.data_pack/data/demo/{functions => function}/foo.mcfunction (100%) diff --git a/beet/library/base.py b/beet/library/base.py index 32a34958..7ca06bd1 100644 --- a/beet/library/base.py +++ b/beet/library/base.py @@ -76,7 +76,7 @@ SupportsMerge, ) from beet.core.file import File, FileOrigin, JsonFile, PngFile -from beet.core.utils import FileSystemPath, JsonDict, SupportedFormats, TextComponent +from beet.core.utils import FileSystemPath, FormatsRangeDict, JsonDict, SupportedFormats, TextComponent from .utils import list_extensions, list_origin_folders @@ -579,9 +579,21 @@ 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 - ) + # We grab the pack format from the pack's overlay parent if it exists + # Otherwise, grab it from the pack itself + pack_format = 0 + if self.pack: + if self.pack.overlay_parent: + if type(self.pack.overlay_parent.supported_formats) is int: + pack_format = self.pack.overlay_parent.supported_formats + elif type(self.pack.overlay_parent.supported_formats) is list[int]: + pack_format = self.pack.overlay_parent.supported_formats[1] + elif type(self.pack.overlay_parent.supported_formats) is FormatsRangeDict: + pack_format = self.pack.overlay_parent.supported_formats["max_inclusive"] + else: + pack_format = self.pack.pack_format + scope = get_output_scope(content_type.scope, pack_format) + prefix = "/".join((self.directory, namespace) + scope) for name, item in container.items(): yield f"{overlay}{prefix}/{name}{content_type.extension}", item diff --git a/examples/load_overlay/beet.yml b/examples/load_overlay/beet.yml index 0619fa3e..8045138c 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 d145ca2d..1b5afc51 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 1aa5c97c..3a177a56 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 From b9f449861460b380475f97729e7c2c02dae356cb Mon Sep 17 00:00:00 2001 From: Yavanni E Date: Fri, 6 Sep 2024 13:35:51 -0400 Subject: [PATCH 2/9] fix: use overlay's supported versions --- beet/library/base.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/beet/library/base.py b/beet/library/base.py index 7ca06bd1..ee6cf96a 100644 --- a/beet/library/base.py +++ b/beet/library/base.py @@ -584,12 +584,14 @@ def list_files( pack_format = 0 if self.pack: if self.pack.overlay_parent: - if type(self.pack.overlay_parent.supported_formats) is int: - pack_format = self.pack.overlay_parent.supported_formats - elif type(self.pack.overlay_parent.supported_formats) is list[int]: - pack_format = self.pack.overlay_parent.supported_formats[1] - elif type(self.pack.overlay_parent.supported_formats) is FormatsRangeDict: - pack_format = self.pack.overlay_parent.supported_formats["max_inclusive"] + supported_formats = self.pack.supported_formats + + if type(supported_formats) is int: + pack_format = supported_formats + elif type(supported_formats) is list[int]: + pack_format = supported_formats[1] + elif type(supported_formats) is FormatsRangeDict: + pack_format = supported_formats["max_inclusive"] else: pack_format = self.pack.pack_format scope = get_output_scope(content_type.scope, pack_format) From 46172437dca7aecdca92d71e6ca354e6a2775429 Mon Sep 17 00:00:00 2001 From: Misode Date: Fri, 11 Oct 2024 23:57:33 +0200 Subject: [PATCH 3/9] Fix when supported_formats doesn't exist --- beet/library/base.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/beet/library/base.py b/beet/library/base.py index ee6cf96a..4ca4741a 100644 --- a/beet/library/base.py +++ b/beet/library/base.py @@ -583,17 +583,16 @@ def list_files( # Otherwise, grab it from the pack itself pack_format = 0 if self.pack: + pack_format = self.pack.pack_format if self.pack.overlay_parent: + pack_format = self.pack.pack_format supported_formats = self.pack.supported_formats - if type(supported_formats) is int: pack_format = supported_formats elif type(supported_formats) is list[int]: pack_format = supported_formats[1] elif type(supported_formats) is FormatsRangeDict: pack_format = supported_formats["max_inclusive"] - else: - pack_format = self.pack.pack_format scope = get_output_scope(content_type.scope, pack_format) prefix = "/".join((self.directory, namespace) + scope) From a27af06d6f5808fba90a25904d88704ea2997444 Mon Sep 17 00:00:00 2001 From: Misode Date: Mon, 9 Dec 2024 02:13:39 +0100 Subject: [PATCH 4/9] Run formatter --- beet/library/base.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/beet/library/base.py b/beet/library/base.py index 4ca4741a..314b945a 100644 --- a/beet/library/base.py +++ b/beet/library/base.py @@ -76,7 +76,13 @@ SupportsMerge, ) from beet.core.file import File, FileOrigin, JsonFile, PngFile -from beet.core.utils import FileSystemPath, FormatsRangeDict, JsonDict, SupportedFormats, TextComponent +from beet.core.utils import ( + FileSystemPath, + FormatsRangeDict, + JsonDict, + SupportedFormats, + TextComponent, +) from .utils import list_extensions, list_origin_folders From 65aee3085fc92cd1cb87e605501cced273ce5e51 Mon Sep 17 00:00:00 2001 From: Misode Date: Mon, 9 Dec 2024 02:20:13 +0100 Subject: [PATCH 5/9] Simplify logic + fix comment --- beet/library/base.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/beet/library/base.py b/beet/library/base.py index 314b945a..0c2e1be0 100644 --- a/beet/library/base.py +++ b/beet/library/base.py @@ -585,20 +585,19 @@ def list_files( if extend and not issubclass(content_type, extend): continue - # We grab the pack format from the pack's overlay parent if it exists - # Otherwise, grab it from the pack itself + # Use the pack format from the pack's supported_formats. + # Otherwise, use the pack_format itself pack_format = 0 if self.pack: - pack_format = self.pack.pack_format - if self.pack.overlay_parent: + supported_formats = self.pack.supported_formats + if type(supported_formats) is int: + pack_format = supported_formats + elif type(supported_formats) is list[int]: + pack_format = supported_formats[1] + elif type(supported_formats) is FormatsRangeDict: + pack_format = supported_formats["max_inclusive"] + else: pack_format = self.pack.pack_format - supported_formats = self.pack.supported_formats - if type(supported_formats) is int: - pack_format = supported_formats - elif type(supported_formats) is list[int]: - pack_format = supported_formats[1] - elif type(supported_formats) is FormatsRangeDict: - pack_format = supported_formats["max_inclusive"] scope = get_output_scope(content_type.scope, pack_format) prefix = "/".join((self.directory, namespace) + scope) From 5a1c6c41e0b176f4a313647b6320f21909f84afd Mon Sep 17 00:00:00 2001 From: Misode Date: Sat, 4 Jan 2025 20:48:29 +0100 Subject: [PATCH 6/9] Use `isinstance` correctly --- beet/library/base.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/beet/library/base.py b/beet/library/base.py index 0c2e1be0..3d91f121 100644 --- a/beet/library/base.py +++ b/beet/library/base.py @@ -78,7 +78,6 @@ from beet.core.file import File, FileOrigin, JsonFile, PngFile from beet.core.utils import ( FileSystemPath, - FormatsRangeDict, JsonDict, SupportedFormats, TextComponent, @@ -590,11 +589,11 @@ def list_files( pack_format = 0 if self.pack: supported_formats = self.pack.supported_formats - if type(supported_formats) is int: + if isinstance(supported_formats, int): pack_format = supported_formats - elif type(supported_formats) is list[int]: + elif isinstance(supported_formats, list): pack_format = supported_formats[1] - elif type(supported_formats) is FormatsRangeDict: + elif isinstance(supported_formats, dict): pack_format = supported_formats["max_inclusive"] else: pack_format = self.pack.pack_format From c4fce6f5939b6dffa1ab12f28234defc80c309fb Mon Sep 17 00:00:00 2001 From: Misode Date: Sat, 4 Jan 2025 20:56:27 +0100 Subject: [PATCH 7/9] Move logic to get_output_scope itself --- beet/contrib/rename_files.py | 2 +- beet/library/base.py | 33 ++++++++++++++++++--------------- beet/toolchain/query.py | 4 ++-- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/beet/contrib/rename_files.py b/beet/contrib/rename_files.py index bc137b8a..79067352 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 3d91f121..b5a2a136 100644 --- a/beet/library/base.py +++ b/beet/library/base.py @@ -584,20 +584,7 @@ def list_files( if extend and not issubclass(content_type, extend): continue - # Use the pack format from the pack's supported_formats. - # Otherwise, use the pack_format itself - pack_format = 0 - if self.pack: - supported_formats = self.pack.supported_formats - if isinstance(supported_formats, int): - pack_format = supported_formats - elif isinstance(supported_formats, list): - pack_format = supported_formats[1] - elif isinstance(supported_formats, dict): - pack_format = supported_formats["max_inclusive"] - else: - pack_format = self.pack.pack_format - scope = get_output_scope(content_type.scope, pack_format) + scope = get_output_scope(content_type.scope, self.pack) prefix = "/".join((self.directory, namespace) + scope) for name, item in container.items(): @@ -1592,9 +1579,25 @@ 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 + # Use the pack format from the pack's supported_formats. + # Otherwise, use the pack_format itself + if pack is None: + # Fall back to the most recent scope + pack_format = 9999 + elif isinstance(pack, int): + pack_format = pack + else: + 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 858c826f..e32deba3 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}") From f1ec5d857d7a2b7c6038d906757227ff84b16537 Mon Sep 17 00:00:00 2001 From: Misode Date: Sat, 4 Jan 2025 20:58:15 +0100 Subject: [PATCH 8/9] Format --- beet/library/base.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/beet/library/base.py b/beet/library/base.py index b5a2a136..b9981589 100644 --- a/beet/library/base.py +++ b/beet/library/base.py @@ -76,12 +76,7 @@ SupportsMerge, ) from beet.core.file import File, FileOrigin, JsonFile, PngFile -from beet.core.utils import ( - FileSystemPath, - JsonDict, - SupportedFormats, - TextComponent, -) +from beet.core.utils import FileSystemPath, JsonDict, SupportedFormats, TextComponent from .utils import list_extensions, list_origin_folders @@ -585,7 +580,6 @@ def list_files( continue 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 @@ -1582,14 +1576,15 @@ def list_input_scopes(scope: NamespaceFileScope) -> Iterable[Tuple[str, ...]]: def get_output_scope(scope: NamespaceFileScope, pack: Optional[int | Pack[Any]]) -> Tuple[str, ...]: if isinstance(scope, tuple): return scope - # Use the pack format from the pack's supported_formats. - # Otherwise, use the pack_format itself + 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): From 4df3287a9c65aaa7387b1bc7c8193add7f60156c Mon Sep 17 00:00:00 2001 From: Misode Date: Sat, 4 Jan 2025 21:01:35 +0100 Subject: [PATCH 9/9] Format again --- beet/library/base.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/beet/library/base.py b/beet/library/base.py index b9981589..05aec8ee 100644 --- a/beet/library/base.py +++ b/beet/library/base.py @@ -1573,7 +1573,9 @@ 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: Optional[int | Pack[Any]]) -> Tuple[str, ...]: +def get_output_scope( + scope: NamespaceFileScope, pack: Optional[int | Pack[Any]] +) -> Tuple[str, ...]: if isinstance(scope, tuple): return scope