Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
9886b16
fix: detect bad encoding on failure
TheNuclearNexus May 25, 2024
9457240
fix: use json5 on decode to correct for comments and trailing commas
TheNuclearNexus May 25, 2024
07ef8bd
feat: support 1.21 renames and outputting to correct folder based on …
TheNuclearNexus Jun 12, 2024
f1aecb1
feat: swap to tuples, added enchantment, updated optifine
TheNuclearNexus Jul 2, 2024
f6e21c9
fix: did not export enchantment class
TheNuclearNexus Jul 2, 2024
0c03f6a
feat: adding all 1.21 things
edayot Jul 2, 2024
831f0df
better formatting
edayot Jul 2, 2024
a6086ff
fix order in certain classes
edayot Jul 2, 2024
a677bcd
fix order in __all__
edayot Jul 2, 2024
e22a515
Merge pull request #2 from edayot/1.21-fixes_from_TheNuclearNexus_branch
TheNuclearNexus Jul 2, 2024
d1fb7b3
feat: start implementing dict scope loading
edayot Jul 8, 2024
a862b07
fix rename files plugin
edayot Jul 8, 2024
cc0d644
style: black
edayot Jul 8, 2024
0b07d7a
fix: hearing feedback from discord
edayot Jul 9, 2024
83ffc78
better & centralized function
edayot Jul 12, 2024
cf74e52
small fix
edayot Jul 12, 2024
553f591
pyright passing
edayot Jul 12, 2024
9019b6d
Merge branch '1.21-changes'
TheNuclearNexus Jul 21, 2024
4eaf9dd
Merge pull request #3 from TheNuclearNexus/1.21-changes
TheNuclearNexus Jul 21, 2024
a7f3946
Merge branch 'main' into pr/4
TheNuclearNexus Jul 21, 2024
b292aee
Merge pull request #5 from TheNuclearNexus/pr/4
TheNuclearNexus Jul 21, 2024
4dd5849
Merge remote-tracking branch 'upstream/main'
TheNuclearNexus Dec 22, 2025
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
42 changes: 36 additions & 6 deletions beet/core/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@

import io
import json

import chardet
import pyjson5
import shutil
from copy import deepcopy
from dataclasses import dataclass, replace
Expand Down Expand Up @@ -436,14 +439,41 @@ def deserialize(self, content: Union[ValueType, str]) -> ValueType:

@classmethod
def from_path(cls, path: FileSystemPath, start: int, stop: int) -> str:
with open(path, "r", encoding="utf-8") as f:
if start > 0:
f.seek(start)
return f.read(stop - start) if stop >= -1 else f.read()
# We assume that the file is utf-8 since its most common
# In the event the file fails to be parsed in utf-8, we'll attempt to detect
# the correct encoding and retry. If that fails than another exception will be raised
try:
with open(path, "r", encoding="utf-8") as f:
if start > 0:
f.seek(start)
return f.read(stop - start) if stop >= -1 else f.read()
except ValueError:
with open(path, "rb") as f:
if start > 0:
f.seek(start)
file_bytes = f.read(stop - start) if stop >= -1 else f.read()

encoding = chardet.detect(file_bytes)["encoding"]

if encoding == None:
encoding = "utf-8"

return file_bytes.decode(encoding=encoding)


@classmethod
def from_zip(cls, origin: ZipFile, name: str) -> str:
return origin.read(name).decode()
file_bytes = origin.read(name)

try:
return file_bytes.decode()
except UnicodeDecodeError:
encoding = chardet.detect(file_bytes)["encoding"]

if encoding == None:
encoding = "utf-8"

return file_bytes.decode(encoding=encoding)

def dump_path(self, path: FileSystemPath, raw: str) -> None:
with open(
Expand Down Expand Up @@ -634,7 +664,7 @@ def __post_init__(self):
if not self.encoder: # type: ignore
self.encoder = dump_json
if not self.decoder: # type: ignore
self.decoder = json.loads
self.decoder = pyjson5.loads


@dataclass(eq=False, repr=False)
Expand Down
17 changes: 17 additions & 0 deletions beet/library/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
"get_output_scope",
"PACK_COMPRESSION",
"LATEST_MINECRAFT_VERSION",
"NamespaceFileScope",
"get_output_scope",
]


Expand Down Expand Up @@ -430,6 +432,20 @@ class NamespacePin(Pin[Type[NamespaceFileType], NamespaceContainer[NamespaceFile
"""Descriptor for accessing namespace containers by attribute lookup."""


def create_scope_map(
pins: Dict[str, Pin[type[NamespaceFile], NamespaceContainer[NamespaceFile]]]
):
scope_map: Mapping[Tuple[Tuple[str, ...], str], Type[NamespaceFile]] = {}
for pin in pins.values():
if isinstance(scopes := pin.key.scope, tuple):
scope_map[(scopes, pin.key.extension)] = pin.key
else:
for scope in scopes.values():
scope_map[(scope, pin.key.extension)] = pin.key

return scope_map


class Namespace(
MergeMixin,
Container[Type[NamespaceFile], NamespaceContainer[NamespaceFile]],
Expand Down Expand Up @@ -611,6 +627,7 @@ def scan(
_update_with_none(extra_info, extend_namespace_extra)

scope_map = dict(cls.scope_map)

for file_type in extend_namespace:
for scope in list_input_scopes(file_type.scope):
scope_map[scope, file_type.extension] = file_type
Expand Down
Loading
Loading