-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add pack extensions and walk method
- Loading branch information
Showing
19 changed files
with
186 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
require: ["demo.extend_data_pack"] | ||
data_pack: | ||
load: ["src"] | ||
pipeline: ["demo.process_functions"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from typing import cast | ||
|
||
from beet import Context, JsonFile, NamespaceFile, TextFile, YamlFile | ||
from beet.library.data_pack import Function | ||
|
||
|
||
class FunctionConfig(YamlFile, NamespaceFile): | ||
scope = ("functions",) | ||
extension = ".yml" | ||
|
||
|
||
def extend_data_pack(ctx: Context): | ||
ctx.data.extend_extra["myproject.json"] = JsonFile | ||
ctx.data.extend_namespace.append(FunctionConfig) | ||
ctx.data.extend_namespace_extra["numbers.txt"] = TextFile | ||
|
||
|
||
def process_functions(ctx: Context): | ||
project_data = cast(JsonFile, ctx.data.extra["myproject.json"]).data | ||
|
||
for prefix, dirs, functions in ctx.data.functions.walk(): | ||
dirs.discard("zprivate") | ||
|
||
namespace = ctx.data[prefix.partition(":")[0]] | ||
numbers = cast(TextFile, namespace.extra["numbers.txt"]).text.splitlines() | ||
|
||
folder_config = ctx.data[FunctionConfig][prefix + "config"].data | ||
|
||
for function in functions.values(): | ||
function.prepend( | ||
Function( | ||
[ | ||
f"# config.yml = {folder_config}", | ||
f"# numbers.txt = {numbers}", | ||
f"# myproject.json = {project_data}", | ||
] | ||
) | ||
) | ||
|
||
del ctx.data.extra["myproject.json"] | ||
for namespace in ctx.data.values(): | ||
del namespace.extra["numbers.txt"] | ||
del namespace[FunctionConfig] |
1 change: 1 addition & 0 deletions
1
examples/load_extend/src/data/demo/functions/abc/blah.mcfunction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
say abc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
value: 13 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
value: 42 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
say hello |
1 change: 1 addition & 0 deletions
1
examples/load_extend/src/data/demo/functions/zprivate/thing.mcfunction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
say keep this untouched |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
1 | ||
2 | ||
3 | ||
4 | ||
5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
value: 7798 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
say wat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
1 | ||
2 | ||
9000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"foo": "bar" | ||
} |
4 changes: 4 additions & 0 deletions
4
...napshots/examples__build_load_extend__0.data_pack/data/demo/functions/abc/blah.mcfunction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# config.yml = {'value': 13} | ||
# numbers.txt = ['1', '2', '3', '4', '5'] | ||
# myproject.json = {'foo': 'bar'} | ||
say abc |
4 changes: 4 additions & 0 deletions
4
tests/snapshots/examples__build_load_extend__0.data_pack/data/demo/functions/foo.mcfunction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# config.yml = {'value': 42} | ||
# numbers.txt = ['1', '2', '3', '4', '5'] | ||
# myproject.json = {'foo': 'bar'} | ||
say hello |
1 change: 1 addition & 0 deletions
1
...ts/examples__build_load_extend__0.data_pack/data/demo/functions/zprivate/thing.mcfunction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
say keep this untouched |
4 changes: 4 additions & 0 deletions
4
tests/snapshots/examples__build_load_extend__0.data_pack/data/other/functions/qqq.mcfunction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# config.yml = {'value': 7798} | ||
# numbers.txt = ['1', '2', '9000'] | ||
# myproject.json = {'foo': 'bar'} | ||
say wat |
6 changes: 6 additions & 0 deletions
6
tests/snapshots/examples__build_load_extend__0.data_pack/pack.mcmeta
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"pack": { | ||
"pack_format": 7, | ||
"description": "" | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
tests/snapshots/examples__build_load_extend__1.resource_pack/pack.mcmeta
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"pack": { | ||
"pack_format": 7, | ||
"description": "" | ||
} | ||
} |