1
0
mirror of synced 2024-12-04 19:17:55 +01:00

Use argument lists in Song.from_monochart_instances

This commit is contained in:
Stepland 2021-12-27 23:12:46 +01:00
parent e111f93645
commit c06c9ffc33
17 changed files with 18 additions and 36 deletions

View File

@ -1,5 +1,5 @@
""" """
Module containing all the load/dump code for all file formats 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 from .loaders_and_dumpers import DUMPERS, LOADERS

View File

@ -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"

View File

@ -2,7 +2,7 @@ import json
import re import re
from pathlib import Path from pathlib import Path
from .enum import Format from .format_names import Format
def guess_format(path: Path) -> Format: def guess_format(path: Path) -> Format:

View File

@ -349,4 +349,4 @@ def _load_memo_file(lines: List[str]) -> Song:
def load_memo(path: Path, **kwargs: Any) -> Song: def load_memo(path: Path, **kwargs: Any) -> Song:
files = load_folder(path) files = load_folder(path)
charts = [_load_memo_file(lines) for _, lines in files.items()] charts = [_load_memo_file(lines) for _, lines in files.items()]
return Song.from_monochart_instances(charts) return Song.from_monochart_instances(*charts)

View File

@ -340,4 +340,4 @@ def _load_memo1_file(lines: List[str]) -> Song:
def load_memo1(path: Path, **kwargs: Any) -> Song: def load_memo1(path: Path, **kwargs: Any) -> Song:
files = load_folder(path) files = load_folder(path)
charts = [_load_memo1_file(lines) for _, lines in files.items()] charts = [_load_memo1_file(lines) for _, lines in files.items()]
return Song.from_monochart_instances(charts) return Song.from_monochart_instances(*charts)

View File

@ -459,4 +459,4 @@ def _load_memo2_file(lines: List[str]) -> Song:
def load_memo2(path: Path, **kwargs: Any) -> Song: def load_memo2(path: Path, **kwargs: Any) -> Song:
files = load_folder(path) files = load_folder(path)
charts = [_load_memo2_file(lines) for _, lines in files.items()] charts = [_load_memo2_file(lines) for _, lines in files.items()]
return Song.from_monochart_instances(charts) return Song.from_monochart_instances(*charts)

View File

@ -246,7 +246,7 @@ class MonoColumnParser(JubeatAnalyserParser):
def load_mono_column(path: Path, **kwargs: Any) -> Song: def load_mono_column(path: Path, **kwargs: Any) -> Song:
files = load_folder(path) files = load_folder(path)
charts = [_load_mono_column_file(lines) for _, lines in files.items()] 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: def _load_mono_column_file(lines: List[str]) -> Song:

View File

@ -7,7 +7,7 @@ from hypothesis import note as hypothesis_note
from hypothesis import strategies as st from hypothesis import strategies as st
from jubeatools import song 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.dump import _dump_memo_chart
from jubeatools.formats.jubeat_analyser.memo.load import MemoParser from jubeatools.formats.jubeat_analyser.memo.load import MemoParser
from jubeatools.testutils import strategies as jbst from jubeatools.testutils import strategies as jbst

View File

@ -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: def load_eve(path: Path, *, beat_snap: int = 240, **kwargs: Any) -> song.Song:
files = load_folder(path) files = load_folder(path)
charts = [_load_eve(l, p, beat_snap=beat_snap) for p, l in files.items()] 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]: def load_file(path: Path) -> List[str]:

View File

@ -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) load_jbsq_file(bytes_, path, beat_snap=beat_snap)
for path, bytes_ in files.items() 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: def load_file(path: Path) -> bytes:

View File

@ -1,7 +1,7 @@
from typing import Dict from typing import Dict
from . import jubeat_analyser, konami, malody, memon from . import jubeat_analyser, konami, malody, memon
from .enum import Format from .format_names import Format
from .typing import Dumper, Loader from .typing import Dumper, Loader
LOADERS: Dict[Format, Loader] = { LOADERS: Dict[Format, Loader] = {

View File

@ -18,7 +18,7 @@ from . import schema as malody
def load_malody(path: Path, **kwargs: Any) -> song.Song: def load_malody(path: Path, **kwargs: Any) -> song.Song:
files = load_folder(path) files = load_folder(path)
charts = [load_malody_file(d) for d in files.values()] 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: def load_file(path: Path) -> Any:

View File

@ -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()] 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 return load

View File

@ -4,7 +4,7 @@ import hypothesis.strategies as st
from hypothesis import given from hypothesis import given
from jubeatools import song 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 import strategies as jbst
from jubeatools.testutils.test_patterns import dump_and_load_then_compare from jubeatools.testutils.test_patterns import dump_and_load_then_compare

View File

@ -5,7 +5,7 @@ import hypothesis.strategies as st
from hypothesis import given from hypothesis import given
from jubeatools import song 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 import strategies as jbst
from jubeatools.testutils.test_patterns import dump_and_load_then_compare from jubeatools.testutils.test_patterns import dump_and_load_then_compare

View File

@ -223,14 +223,13 @@ class Metadata:
preview_file: Optional[Path] = None preview_file: Optional[Path] = None
@classmethod @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 """Make the "sum" of all the given metadata instances, if possible. If
several instances have different defined values for the same field, several instances have different defined values for the same field,
merging will fail. Fields with Noneor empty values (empty string or merging will fail. Fields with Noneor empty values (empty string or
empty path) are conscidered undefined and their values can be replaced 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 by an actual value if supplied by at least one object from the given
iterable.""" iterable."""
metadatas = list(metadatas)
return cls( return cls(
**{f.name: _get_common_value(f, metadatas) for f in fields(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 common_hakus: Optional[Set[BeatsTime]] = None
@classmethod @classmethod
def from_monochart_instances(cls, songs: Iterable["Song"]) -> "Song": def from_monochart_instances(cls, *songs: "Song") -> "Song":
metadata = Metadata.permissive_merge(song.metadata for song in songs) metadata = Metadata.permissive_merge(*(song.metadata for song in songs))
charts: MultiDict[Chart] = MultiDict() charts: MultiDict[Chart] = MultiDict()
for song in songs: for song in songs:
song.remove_common_timing() song.remove_common_timing()

View File

@ -6,8 +6,7 @@ from typing import Callable, ContextManager, Iterator, Optional
from hypothesis import note from hypothesis import note
from jubeatools import song from jubeatools import song
from jubeatools.formats import DUMPERS, LOADERS from jubeatools.formats import DUMPERS, LOADERS, Format
from jubeatools.formats.enum import Format
from jubeatools.formats.guess import guess_format from jubeatools.formats.guess import guess_format