Use argument lists in Song.from_monochart_instances
This commit is contained in:
parent
1ce5c75969
commit
4002282c12
@ -1,5 +1,5 @@
|
||||
"""
|
||||
Module containing all the load/dump code for all file formats
|
||||
"""
|
||||
from .enum import Format
|
||||
from .format_names import Format
|
||||
from .loaders_and_dumpers import DUMPERS, LOADERS
|
||||
|
@ -1,16 +0,0 @@
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class Format(str, Enum):
|
||||
EVE = "eve"
|
||||
JBSQ = "jbsq"
|
||||
MALODY = "malody"
|
||||
MEMON_LEGACY = "memon:legacy"
|
||||
MEMON_0_1_0 = "memon:v0.1.0"
|
||||
MEMON_0_2_0 = "memon:v0.2.0"
|
||||
MEMON_0_3_0 = "memon:v0.3.0"
|
||||
MEMON_1_0_0 = "memon:v1.0.0"
|
||||
MONO_COLUMN = "mono-column"
|
||||
MEMO = "memo"
|
||||
MEMO_1 = "memo1"
|
||||
MEMO_2 = "memo2"
|
@ -2,7 +2,7 @@ import json
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
from .enum import Format
|
||||
from .format_names import Format
|
||||
|
||||
|
||||
def guess_format(path: Path) -> Format:
|
||||
|
@ -349,4 +349,4 @@ def _load_memo_file(lines: List[str]) -> Song:
|
||||
def load_memo(path: Path, **kwargs: Any) -> Song:
|
||||
files = load_folder(path)
|
||||
charts = [_load_memo_file(lines) for _, lines in files.items()]
|
||||
return Song.from_monochart_instances(charts)
|
||||
return Song.from_monochart_instances(*charts)
|
||||
|
@ -340,4 +340,4 @@ def _load_memo1_file(lines: List[str]) -> Song:
|
||||
def load_memo1(path: Path, **kwargs: Any) -> Song:
|
||||
files = load_folder(path)
|
||||
charts = [_load_memo1_file(lines) for _, lines in files.items()]
|
||||
return Song.from_monochart_instances(charts)
|
||||
return Song.from_monochart_instances(*charts)
|
||||
|
@ -459,4 +459,4 @@ def _load_memo2_file(lines: List[str]) -> Song:
|
||||
def load_memo2(path: Path, **kwargs: Any) -> Song:
|
||||
files = load_folder(path)
|
||||
charts = [_load_memo2_file(lines) for _, lines in files.items()]
|
||||
return Song.from_monochart_instances(charts)
|
||||
return Song.from_monochart_instances(*charts)
|
||||
|
@ -246,7 +246,7 @@ class MonoColumnParser(JubeatAnalyserParser):
|
||||
def load_mono_column(path: Path, **kwargs: Any) -> Song:
|
||||
files = load_folder(path)
|
||||
charts = [_load_mono_column_file(lines) for _, lines in files.items()]
|
||||
return Song.from_monochart_instances(charts)
|
||||
return Song.from_monochart_instances(*charts)
|
||||
|
||||
|
||||
def _load_mono_column_file(lines: List[str]) -> Song:
|
||||
|
@ -7,7 +7,7 @@ from hypothesis import note as hypothesis_note
|
||||
from hypothesis import strategies as st
|
||||
|
||||
from jubeatools import song
|
||||
from jubeatools.formats.enum import Format
|
||||
from jubeatools.formats.format_names import Format
|
||||
from jubeatools.formats.jubeat_analyser.memo.dump import _dump_memo_chart
|
||||
from jubeatools.formats.jubeat_analyser.memo.load import MemoParser
|
||||
from jubeatools.testutils import strategies as jbst
|
||||
|
@ -11,7 +11,7 @@ from ..load_tools import make_chart_from_events
|
||||
def load_eve(path: Path, *, beat_snap: int = 240, **kwargs: Any) -> song.Song:
|
||||
files = load_folder(path)
|
||||
charts = [_load_eve(l, p, beat_snap=beat_snap) for p, l in files.items()]
|
||||
return song.Song.from_monochart_instances(charts)
|
||||
return song.Song.from_monochart_instances(*charts)
|
||||
|
||||
|
||||
def load_file(path: Path) -> List[str]:
|
||||
|
@ -15,7 +15,7 @@ def load_jbsq(path: Path, *, beat_snap: int = 240, **kwargs: Any) -> song.Song:
|
||||
load_jbsq_file(bytes_, path, beat_snap=beat_snap)
|
||||
for path, bytes_ in files.items()
|
||||
]
|
||||
return song.Song.from_monochart_instances(charts)
|
||||
return song.Song.from_monochart_instances(*charts)
|
||||
|
||||
|
||||
def load_file(path: Path) -> bytes:
|
||||
|
@ -1,7 +1,7 @@
|
||||
from typing import Dict
|
||||
|
||||
from . import jubeat_analyser, konami, malody, memon
|
||||
from .enum import Format
|
||||
from .format_names import Format
|
||||
from .typing import Dumper, Loader
|
||||
|
||||
LOADERS: Dict[Format, Loader] = {
|
||||
|
@ -18,7 +18,7 @@ from . import schema as malody
|
||||
def load_malody(path: Path, **kwargs: Any) -> song.Song:
|
||||
files = load_folder(path)
|
||||
charts = [load_malody_file(d) for d in files.values()]
|
||||
return song.Song.from_monochart_instances(charts)
|
||||
return song.Song.from_monochart_instances(*charts)
|
||||
|
||||
|
||||
def load_file(path: Path) -> Any:
|
||||
|
@ -31,7 +31,7 @@ def make_memon_folder_loader(memon_loader: Callable[[Any], jbt.Song]) -> Loader:
|
||||
)
|
||||
|
||||
charts = [memon_loader(d) for d in files.values()]
|
||||
return jbt.Song.from_monochart_instances(charts)
|
||||
return jbt.Song.from_monochart_instances(*charts)
|
||||
|
||||
return load
|
||||
|
||||
|
@ -4,7 +4,7 @@ import hypothesis.strategies as st
|
||||
from hypothesis import given
|
||||
|
||||
from jubeatools import song
|
||||
from jubeatools.formats.enum import Format
|
||||
from jubeatools.formats.format_names import Format
|
||||
from jubeatools.testutils import strategies as jbst
|
||||
from jubeatools.testutils.test_patterns import dump_and_load_then_compare
|
||||
|
||||
|
@ -5,7 +5,7 @@ import hypothesis.strategies as st
|
||||
from hypothesis import given
|
||||
|
||||
from jubeatools import song
|
||||
from jubeatools.formats.enum import Format
|
||||
from jubeatools.formats.format_names import Format
|
||||
from jubeatools.testutils import strategies as jbst
|
||||
from jubeatools.testutils.test_patterns import dump_and_load_then_compare
|
||||
|
||||
|
@ -223,14 +223,13 @@ class Metadata:
|
||||
preview_file: Optional[Path] = None
|
||||
|
||||
@classmethod
|
||||
def permissive_merge(cls, metadatas: Iterable["Metadata"]) -> "Metadata":
|
||||
def permissive_merge(cls, *metadatas: "Metadata") -> "Metadata":
|
||||
"""Make the "sum" of all the given metadata instances, if possible. If
|
||||
several instances have different defined values for the same field,
|
||||
merging will fail. Fields with Noneor empty values (empty string or
|
||||
empty path) are conscidered undefined and their values can be replaced
|
||||
by an actual value if supplied by at least one object from the given
|
||||
iterable."""
|
||||
metadatas = list(metadatas)
|
||||
return cls(
|
||||
**{f.name: _get_common_value(f, metadatas) for f in fields(cls)},
|
||||
)
|
||||
@ -285,8 +284,8 @@ class Song:
|
||||
common_hakus: Optional[Set[BeatsTime]] = None
|
||||
|
||||
@classmethod
|
||||
def from_monochart_instances(cls, songs: Iterable["Song"]) -> "Song":
|
||||
metadata = Metadata.permissive_merge(song.metadata for song in songs)
|
||||
def from_monochart_instances(cls, *songs: "Song") -> "Song":
|
||||
metadata = Metadata.permissive_merge(*(song.metadata for song in songs))
|
||||
charts: MultiDict[Chart] = MultiDict()
|
||||
for song in songs:
|
||||
song.remove_common_timing()
|
||||
|
@ -6,8 +6,7 @@ from typing import Callable, ContextManager, Iterator, Optional
|
||||
from hypothesis import note
|
||||
|
||||
from jubeatools import song
|
||||
from jubeatools.formats import DUMPERS, LOADERS
|
||||
from jubeatools.formats.enum import Format
|
||||
from jubeatools.formats import DUMPERS, LOADERS, Format
|
||||
from jubeatools.formats.guess import guess_format
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user