Skip to content

Commit 533368c

Browse files
misodeTheNuclearNexusritikshah
authored
fix: use supported_formats to determine scope (#455)
Co-authored-by: Yavanni E <thenuclearnexus@gmail.com> Co-authored-by: rx97 <RitikShah@users.noreply.github.com>
1 parent 01c7723 commit 533368c

7 files changed

Lines changed: 39 additions & 17 deletions

File tree

beet/contrib/rename_files.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def handle_filename_for_namespace_file(
116116
):
117117
dest = self.substitute(filename)
118118
file_type = type(file_instance)
119-
scope = get_output_scope(file_type.scope, pack.pack_format)
119+
scope = get_output_scope(file_type.scope, pack)
120120
prefix = "".join(f"{d}/" for d in scope)
121121

122122
_, namespace, path = filename.split("/", 2)

beet/library/base.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -579,9 +579,7 @@ def list_files(
579579
if extend and not issubclass(content_type, extend):
580580
continue
581581

582-
scope = get_output_scope(
583-
content_type.scope, self.pack.pack_format if self.pack else 0
584-
)
582+
scope = get_output_scope(content_type.scope, self.pack)
585583
prefix = "/".join((self.directory, namespace) + scope)
586584
for name, item in container.items():
587585
yield f"{overlay}{prefix}/{name}{content_type.extension}", item
@@ -1575,9 +1573,28 @@ def list_input_scopes(scope: NamespaceFileScope) -> Iterable[Tuple[str, ...]]:
15751573
return [scope] if isinstance(scope, tuple) else scope.values()
15761574

15771575

1578-
def get_output_scope(scope: NamespaceFileScope, pack_format: int) -> Tuple[str, ...]:
1576+
def get_output_scope(
1577+
scope: NamespaceFileScope, pack: Optional[int | Pack[Any]]
1578+
) -> Tuple[str, ...]:
15791579
if isinstance(scope, tuple):
15801580
return scope
1581+
1582+
if pack is None:
1583+
# Fall back to the most recent scope
1584+
pack_format = 9999
1585+
elif isinstance(pack, int):
1586+
pack_format = pack
1587+
else:
1588+
# Use the pack format from the pack's supported_formats.
1589+
# Otherwise, use the pack_format itself
1590+
if isinstance(pack.supported_formats, int):
1591+
pack_format = pack.supported_formats
1592+
elif isinstance(pack.supported_formats, list):
1593+
pack_format = pack.supported_formats[1]
1594+
elif isinstance(pack.supported_formats, dict):
1595+
pack_format = pack.supported_formats["max_inclusive"]
1596+
else:
1597+
pack_format = pack.pack_format
15811598
result: Tuple[str, ...] | None = None
15821599
result_format: int | None = None
15831600
for key, value in scope.items():

beet/toolchain/query.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ def analyze_base_paths(
229229

230230
escaped = GitWildMatchPattern.escape(path)
231231
if path == escaped:
232-
scope = get_output_scope(file_type.scope, pack.pack_format)
232+
scope = get_output_scope(file_type.scope, pack)
233233
prefix = "/".join([directory, namespace, *scope])
234234
base_paths.add(f"{overlay}{prefix}/{path}{file_type.extension}")
235235
continue
@@ -240,7 +240,7 @@ def analyze_base_paths(
240240
break
241241
common.append(part)
242242

243-
scope = get_output_scope(file_type.scope, pack.pack_format)
243+
scope = get_output_scope(file_type.scope, pack)
244244
prefix = "/".join([directory, namespace, *scope, *common])
245245
base_paths.add(f"{overlay}{prefix}")
246246

examples/load_overlay/beet.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
data_pack:
22
load: "src"
3-
pack_format: 20
4-
supported_formats: [18, 19, 20]
3+
pack_format: 50
4+
supported_formats: [50, 50]
55
overlays:
66
- formats:
77
min_inclusive: 18

examples/load_overlay/src/pack.mcmeta

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@
22
"overlays": {
33
"entries": [
44
{
5-
"formats": {"min_inclusive": 17, "max_inclusive": 18},
5+
"formats": {
6+
"min_inclusive": 17,
7+
"max_inclusive": 18
8+
},
69
"directory": "overlay1"
710
},
811
{
9-
"formats": {"min_inclusive": 18, "max_inclusive": 19},
12+
"formats": {
13+
"min_inclusive": 18,
14+
"max_inclusive": 19
15+
},
1016
"directory": "overlay2"
1117
},
1218
{
@@ -15,4 +21,4 @@
1521
}
1622
]
1723
}
18-
}
24+
}

tests/snapshots/examples__build_load_overlay__0.data_pack/data/demo/functions/foo.mcfunction renamed to tests/snapshots/examples__build_load_overlay__0.data_pack/data/demo/function/foo.mcfunction

File renamed without changes.

tests/snapshots/examples__build_load_overlay__0.data_pack/pack.mcmeta

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
{
22
"pack": {
3-
"pack_format": 20,
3+
"pack_format": 50,
44
"description": "",
55
"supported_formats": [
6-
18,
7-
19,
8-
20
6+
50,
7+
50
98
]
109
},
1110
"overlays": {
@@ -37,4 +36,4 @@
3736
}
3837
]
3938
}
40-
}
39+
}

0 commit comments

Comments
 (0)