Skip to content
Closed
Show file tree
Hide file tree
Changes from 5 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: 0 additions & 2 deletions beet/library/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,8 +679,6 @@ class NamespaceProxy(

def split_key(self, key: str) -> Tuple[str, str]:
namespace, _, file_path = key.partition(":")
if not file_path:
raise KeyError(key)
return namespace, file_path

def join_key(self, key1: str, key2: str) -> str:
Expand Down
23 changes: 22 additions & 1 deletion beet/library/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,31 @@ def list_origin_folders(prefix: str, origin: FileOrigin) -> Dict[str, List[PureP

return folders

def modified_suffixes(path: PurePath) -> List[str]:
"""
Equivalent to path.suffixes but support file with empty name
filename | filename.suffixes | modified_suffixes(filename)

load.mcfunction | ['.mcfunction'] | ['.mcfunction']
.mcfunction | [] | ['.mcfunction']
..mcfunction | [] | ['.mcfunction']
load.py.mcfunction | ['.py', '.mcfunction'] | ['.py', '.mcfunction']
.py.mcfunction | ['.mcfunction'] | ['.py', '.mcfunction']
aaa...mcfunction | ['.', '.', '.mcfunction'] | ['.', '.', '.mcfunction']
...mcfunction | [] | ['.', '.', '.mcfunction']
Comment thread
edayot marked this conversation as resolved.
Outdated
"""
name = path.name
if name.endswith('.'):
return []
if name.startswith('.'):
name = name[1:]
return ['.' + suffix for suffix in name.split('.')]
return path.suffixes


def list_extensions(path: PurePath) -> List[str]:
extensions: List[str] = list(
accumulate(reversed(path.suffixes), lambda a, b: b + a) # type: ignore
accumulate(reversed(modified_suffixes(path)), lambda a, b: b + a) # type: ignore
)
extensions.reverse()
extensions.append("")
Expand Down
9 changes: 9 additions & 0 deletions examples/code_void/add_header.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from beet import Context, Function


def beet_default(ctx: Context):
for f in ctx.data.functions.keys():
ctx.data.functions[f] = Function(f"say {f}")

ctx.data.functions["namespace:"] = Function("give me sugar")
ctx.data.functions["namespace:a/"] = Function("give me apple")
10 changes: 10 additions & 0 deletions examples/code_void/beet.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
data_pack:
load: [.]
resource_pack:
load: [.]

output: build


pipeline:
- add_header
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
give me sugar
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
give me apple
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
say test:..
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
say test:.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
say test:
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
say test:.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
say test:.mcfunction.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
say test:a
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
say test:a.py.git
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
say test:a/..
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
say test:a/.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
say test:a/
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
say test:a/.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
say test:a/a
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
say test:a/a.py.git
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"pack": {
"pack_format": 26,
"description": ""
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"pack": {
"pack_format": 22,
"description": ""
}
}