Skip to content
Closed
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/dbg.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def level_ranks(self) -> Dict[str, int]:

def render_preview(self, path: str, lineno: int) -> TextComponent:
"""Render the preview as a text component."""
function = self.ctx.data.functions[path]
function = self.ctx.data.function[path]
lines = function.text.splitlines()

preview_start = max(lineno - 1 - self.opts.preview_padding, 0)
Expand Down
4 changes: 2 additions & 2 deletions beet/contrib/hangman.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ def hangman(ctx: Context, opts: HangmanOptions):
"""Plugin that provides indentation-based syntactic extensions for functions."""
logger.warning("Deprecated in favor of mecha (https://github.com/mcbeet/mecha).")

for path in ctx.data.functions.match(*opts.match):
function = ctx.data.functions[path]
for path in ctx.data.function.match(*opts.match):
function = ctx.data.function[path]
function.lines = list(
fold_hanging_commands(ctx, parse_lines(function.lines), path)
)
Expand Down
4 changes: 2 additions & 2 deletions beet/contrib/inline_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ def _function_handler(self, path: str, op: str, caller: Any) -> str:
if op == "replace":
self.ctx.data[path] = function
elif op == "append":
self.ctx.data.functions.setdefault(path, Function()).append(function)
self.ctx.data.function.setdefault(path, Function()).append(function)
elif op == "prepend":
self.ctx.data.functions.setdefault(path, Function()).prepend(function)
self.ctx.data.function.setdefault(path, Function()).prepend(function)

return ""
18 changes: 10 additions & 8 deletions beet/library/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@

from .utils import list_extensions, list_origin_folders

LATEST_MINECRAFT_VERSION: str = "1.20"
LATEST_MINECRAFT_VERSION: str = "1.21"


T = TypeVar("T")
Expand All @@ -102,7 +102,7 @@
class NamespaceFile(Protocol):
"""Protocol for detecting files that belong in pack namespaces."""

scope: ClassVar[Tuple[str, ...]]
scope: ClassVar[List[Tuple[str, ...]]]
extension: ClassVar[str]

snake_name: ClassVar[str]
Expand Down Expand Up @@ -441,8 +441,10 @@ class Namespace(
def __init_subclass__(cls):
pins = NamespacePin[NamespaceFile].collect_from(cls)
cls.field_map = {pin.key: attr for attr, pin in pins.items()}
cls.scope_map = {
(pin.key.scope, pin.key.extension): pin.key for pin in pins.values()
cls.scope_map = { # type: ignore
(scope, pin.key.extension): pin
for pin in pins.values()
for scope in pin.key.scope
}

def __init__(self):
Expand Down Expand Up @@ -571,7 +573,7 @@ def list_files(
continue
if extend and not issubclass(content_type, extend):
continue
prefix = "/".join((self.directory, namespace) + content_type.scope)
prefix = "/".join((self.directory, namespace) + content_type.scope[0])
for name, item in container.items():
yield f"{overlay}{prefix}/{name}{content_type.extension}", item

Expand Down Expand Up @@ -602,7 +604,7 @@ def scan(

scope_map = dict(cls.scope_map)
for file_type in extend_namespace:
scope_map[file_type.scope, file_type.extension] = file_type
scope_map[file_type.scope[0], file_type.extension] = file_type

name = None
namespace = None
Expand Down Expand Up @@ -1093,7 +1095,7 @@ def __setitem__(self, key: str, value: Any):
if isinstance(value, Namespace):
super().__setitem__(key, value) # type: ignore
else:
NamespaceProxy[NamespaceFile](self, type(value))[key] = value
NamespaceProxy[NamespaceFile](self, type(value))[key] = value # type: ignore

def __eq__(self, other: Any) -> bool:
if self is other:
Expand Down Expand Up @@ -1285,7 +1287,7 @@ def resolve_scope_map(
) -> Dict[Tuple[Tuple[str, ...], str], Type[NamespaceFile]]:
scope_map = dict(self.namespace_type.scope_map)
for file_type in self.extend_namespace:
scope_map[file_type.scope, file_type.extension] = file_type
scope_map[file_type.scope[0], file_type.extension] = file_type
return scope_map

def resolve_namespace_extra_info(self) -> Dict[str, Type[PackFile]]:
Expand Down
84 changes: 47 additions & 37 deletions beet/library/data_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,35 +56,35 @@
class Advancement(JsonFile):
"""Class representing an advancement."""

scope: ClassVar[Tuple[str, ...]] = ("advancements",)
scope: ClassVar[list[Tuple[str, ...]]] = [("advancement",), ("advancements",)]
extension: ClassVar[str] = ".json"


class DamageType(JsonFile):
"""Class representing a damage type."""

scope: ClassVar[Tuple[str, ...]] = ("damage_type",)
scope: ClassVar[list[Tuple[str, ...]]] = [("damage_type",)]
extension: ClassVar[str] = ".json"


class ChatType(JsonFile):
"""Class representing a chat type."""

scope: ClassVar[Tuple[str, ...]] = ("chat_type",)
scope: ClassVar[list[Tuple[str, ...]]] = [("chat_type",)]
extension: ClassVar[str] = ".json"


class BannerPattern(JsonFile):
"""Class representing a banner pattern."""

scope: ClassVar[Tuple[str, ...]] = ("banner_pattern",)
scope: ClassVar[list[Tuple[str, ...]]] = [("banner_pattern",)]
extension: ClassVar[str] = ".json"


class WolfVariant(JsonFile):
"""Class representing a wolf variant."""

scope: ClassVar[Tuple[str, ...]] = ("wolf_variant",)
scope: ClassVar[list[Tuple[str, ...]]] = [("wolf_variant",)]
extension: ClassVar[str] = ".json"


Expand All @@ -96,7 +96,7 @@ class Function(TextFileBase[List[str]]):
tags: Optional[List[str]] = extra_field(default=None)
prepend_tags: Optional[List[str]] = extra_field(default=None)

scope: ClassVar[Tuple[str, ...]] = ("functions",)
scope: ClassVar[list[Tuple[str, ...]]] = [("function",), ("functions",)]
extension: ClassVar[str] = ".mcfunction"

lines: ClassVar[FileDeserialize[List[str]]] = FileDeserialize()
Expand Down Expand Up @@ -143,28 +143,28 @@ def bind(self, pack: "DataPack", path: str):
class ItemModifier(JsonFile):
"""Class representing an item modifier."""

scope: ClassVar[Tuple[str, ...]] = ("item_modifiers",)
scope: ClassVar[list[Tuple[str, ...]]] = [("item_modifier",), ("item_modifiers",)]
extension: ClassVar[str] = ".json"


class LootTable(JsonFile):
"""Class representing a loot table."""

scope: ClassVar[Tuple[str, ...]] = ("loot_tables",)
scope: ClassVar[list[Tuple[str, ...]]] = [("loot_table",), ("loot_tables",)]
extension: ClassVar[str] = ".json"


class Predicate(JsonFile):
"""Class representing a predicate."""

scope: ClassVar[Tuple[str, ...]] = ("predicates",)
scope: ClassVar[list[Tuple[str, ...]]] = [("predicate",), ("predicates",)]
extension: ClassVar[str] = ".json"


class Recipe(JsonFile):
"""Class representing a recipe."""

scope: ClassVar[Tuple[str, ...]] = ("recipes",)
scope: ClassVar[list[Tuple[str, ...]]] = [("recipe",), ("recipes",)]
extension: ClassVar[str] = ".json"


Expand All @@ -174,33 +174,33 @@ class Structure(BinaryFileBase[StructureFileData]):

content: BinaryFileContent[StructureFileData] = None

scope: ClassVar[Tuple[str, ...]] = ("structures",)
scope: ClassVar[list[Tuple[str, ...]]] = [("structure",), ("structures",)]
extension: ClassVar[str] = ".nbt"

data: ClassVar[FileDeserialize[StructureFileData]] = FileDeserialize()

def from_bytes(self, content: bytes) -> StructureFileData:
with GzipFile(fileobj=io.BytesIO(content)) as fileobj:
return StructureFile.parse(fileobj).root
return StructureFile.parse(fileobj).root # type: ignore

def to_bytes(self, content: StructureFileData) -> bytes:
dst = io.BytesIO()
with GzipFile(fileobj=dst, mode="wb") as fileobj:
StructureFile(content).write(fileobj)
StructureFile(content).write(fileobj) # type: ignore
return dst.getvalue()


class TrimPattern(JsonFile):
"""Class representing a trim pattern."""

scope: ClassVar[Tuple[str, ...]] = ("trim_pattern",)
scope: ClassVar[list[Tuple[str, ...]]] = [("trim_pattern",)]
extension: ClassVar[str] = ".json"


class TrimMaterial(JsonFile):
"""Class representing a trim material."""

scope: ClassVar[Tuple[str, ...]] = ("trim_material",)
scope: ClassVar[list[Tuple[str, ...]]] = [("trim_material",)]
extension: ClassVar[str] = ".json"


Expand Down Expand Up @@ -261,49 +261,58 @@ def default(cls) -> JsonDict:
class BlockTag(TagFile):
"""Class representing a block tag."""

scope: ClassVar[Tuple[str, ...]] = ("tags", "blocks")
scope: ClassVar[list[Tuple[str, ...]]] = [("tags", "block"), ("tags", "blocks")]


class EntityTypeTag(TagFile):
"""Class representing an entity tag."""

scope: ClassVar[Tuple[str, ...]] = ("tags", "entity_types")
scope: ClassVar[list[Tuple[str, ...]]] = [
("tags", "entity_type"),
("tags", "entity_types"),
]


class FluidTag(TagFile):
"""Class representing a fluid tag."""

scope: ClassVar[Tuple[str, ...]] = ("tags", "fluids")
scope: ClassVar[list[Tuple[str, ...]]] = [("tags", "fluid"), ("tags", "fluids")]


class FunctionTag(TagFile):
"""Class representing a function tag."""

scope: ClassVar[Tuple[str, ...]] = ("tags", "functions")
scope: ClassVar[list[Tuple[str, ...]]] = [
("tags", "function"),
("tags", "functions"),
]


class GameEventTag(TagFile):
"""Class representing a game event tag."""

scope: ClassVar[Tuple[str, ...]] = ("tags", "game_events")
scope: ClassVar[list[Tuple[str, ...]]] = [
("tags", "game_event"),
("tags", "game_events"),
]


class ItemTag(TagFile):
"""Class representing an item tag."""

scope: ClassVar[Tuple[str, ...]] = ("tags", "items")
scope: ClassVar[list[Tuple[str, ...]]] = [("tags", "item"), ("tags", "items")]


class ChatTypeTag(TagFile):
"""Class representing a chat type tag."""

scope: ClassVar[Tuple[str, ...]] = ("tags", "chat_type")
scope: ClassVar[list[Tuple[str, ...]]] = [("tags", "chat_type")]


class DamageTypeTag(TagFile):
"""Class representing a damage type tag."""

scope: ClassVar[Tuple[str, ...]] = ("tags", "damage_type")
scope: ClassVar[list[Tuple[str, ...]]] = [("tags", "damage_type")]


class DataPackNamespace(Namespace):
Expand All @@ -312,15 +321,15 @@ class DataPackNamespace(Namespace):
directory = "data"

# fmt: off
advancements: NamespacePin[Advancement] = NamespacePin(Advancement)
functions: NamespacePin[Function] = NamespacePin(Function)
item_modifiers: NamespacePin[ItemModifier] = NamespacePin(ItemModifier)
loot_tables: NamespacePin[LootTable] = NamespacePin(LootTable)
predicates: NamespacePin[Predicate] = NamespacePin(Predicate)
recipes: NamespacePin[Recipe] = NamespacePin(Recipe)
advancement: NamespacePin[Advancement] = NamespacePin(Advancement)
function: NamespacePin[Function] = NamespacePin(Function)
item_modifier: NamespacePin[ItemModifier] = NamespacePin(ItemModifier)
loot_table: NamespacePin[LootTable] = NamespacePin(LootTable)
predicate: NamespacePin[Predicate] = NamespacePin(Predicate)
recipe: NamespacePin[Recipe] = NamespacePin(Recipe)
trim_pattern: NamespacePin[TrimPattern] = NamespacePin(TrimPattern)
trim_material: NamespacePin[TrimMaterial] = NamespacePin(TrimMaterial)
structures: NamespacePin[Structure] = NamespacePin(Structure)
structure: NamespacePin[Structure] = NamespacePin(Structure)
chat_type: NamespacePin[ChatType] = NamespacePin(ChatType)
damage_type: NamespacePin[DamageType] = NamespacePin(DamageType)
banner_patterns: NamespacePin[BannerPattern] = NamespacePin(BannerPattern)
Expand Down Expand Up @@ -350,19 +359,20 @@ class DataPack(Pack[DataPackNamespace]):
(1, 18): 9,
(1, 19): 12,
(1, 20): 41,
(1, 21): 48,
}
latest_pack_format = pack_format_registry[split_version(LATEST_MINECRAFT_VERSION)]

# fmt: off
advancements: NamespaceProxyDescriptor[Advancement] = NamespaceProxyDescriptor(Advancement)
functions: NamespaceProxyDescriptor[Function] = NamespaceProxyDescriptor(Function)
item_modifiers: NamespaceProxyDescriptor[ItemModifier] = NamespaceProxyDescriptor(ItemModifier)
loot_tables: NamespaceProxyDescriptor[LootTable] = NamespaceProxyDescriptor(LootTable)
predicates: NamespaceProxyDescriptor[Predicate] = NamespaceProxyDescriptor(Predicate)
recipes: NamespaceProxyDescriptor[Recipe] = NamespaceProxyDescriptor(Recipe)
advancement: NamespaceProxyDescriptor[Advancement] = NamespaceProxyDescriptor(Advancement)
function: NamespaceProxyDescriptor[Function] = NamespaceProxyDescriptor(Function)
item_modifier: NamespaceProxyDescriptor[ItemModifier] = NamespaceProxyDescriptor(ItemModifier)
loot_table: NamespaceProxyDescriptor[LootTable] = NamespaceProxyDescriptor(LootTable)
predicate: NamespaceProxyDescriptor[Predicate] = NamespaceProxyDescriptor(Predicate)
recipe: NamespaceProxyDescriptor[Recipe] = NamespaceProxyDescriptor(Recipe)
trim_pattern: NamespaceProxyDescriptor[TrimPattern] = NamespaceProxyDescriptor(TrimPattern)
trim_material: NamespaceProxyDescriptor[TrimMaterial] = NamespaceProxyDescriptor(TrimMaterial)
structures: NamespaceProxyDescriptor[Structure] = NamespaceProxyDescriptor(Structure)
structure: NamespaceProxyDescriptor[Structure] = NamespaceProxyDescriptor(Structure)
chat_type: NamespaceProxyDescriptor[ChatType] = NamespaceProxyDescriptor(ChatType)
damage_type: NamespaceProxyDescriptor[DamageType] = NamespaceProxyDescriptor(DamageType)
banner_patterns: NamespaceProxyDescriptor[BannerPattern] = NamespaceProxyDescriptor(BannerPattern)
Expand Down
Loading