Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use supported_formats to determine scope #455

Merged
merged 10 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion beet/contrib/rename_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
25 changes: 21 additions & 4 deletions beet/library/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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():
Expand Down
4 changes: 2 additions & 2 deletions beet/toolchain/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}")

Expand Down
4 changes: 2 additions & 2 deletions examples/load_overlay/beet.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 9 additions & 3 deletions examples/load_overlay/src/pack.mcmeta
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
{
Expand All @@ -15,4 +21,4 @@
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
{
"pack": {
"pack_format": 20,
"pack_format": 50,
"description": "",
"supported_formats": [
18,
19,
20
50,
50
]
},
"overlays": {
Expand Down Expand Up @@ -37,4 +36,4 @@
}
]
}
}
}
Loading