From c06c9ffc33e97207cbbddda5b8458f57356b8dff Mon Sep 17 00:00:00 2001 From: Stepland <16676308+Stepland@users.noreply.github.com> Date: Mon, 27 Dec 2021 23:12:46 +0100 Subject: [PATCH] Use argument lists in Song.from_monochart_instances --- jubeatools/formats/__init__.py | 2 +- jubeatools/formats/enum.py | 16 ---------------- jubeatools/formats/guess.py | 2 +- jubeatools/formats/jubeat_analyser/memo/load.py | 2 +- jubeatools/formats/jubeat_analyser/memo1/load.py | 2 +- jubeatools/formats/jubeat_analyser/memo2/load.py | 2 +- .../formats/jubeat_analyser/mono_column/load.py | 2 +- .../jubeat_analyser/tests/memo/test_memo.py | 2 +- jubeatools/formats/konami/eve/load.py | 2 +- jubeatools/formats/konami/jbsq/load.py | 2 +- jubeatools/formats/loaders_and_dumpers.py | 2 +- jubeatools/formats/malody/load.py | 2 +- jubeatools/formats/memon/tools.py | 2 +- jubeatools/formats/memon/v0/test_v0.py | 2 +- jubeatools/formats/memon/v1/tests/test_v1.py | 2 +- jubeatools/song.py | 7 +++---- jubeatools/testutils/test_patterns.py | 3 +-- 17 files changed, 18 insertions(+), 36 deletions(-) delete mode 100644 jubeatools/formats/enum.py diff --git a/jubeatools/formats/__init__.py b/jubeatools/formats/__init__.py index 56e6d1c..75bf893 100644 --- a/jubeatools/formats/__init__.py +++ b/jubeatools/formats/__init__.py @@ -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 diff --git a/jubeatools/formats/enum.py b/jubeatools/formats/enum.py deleted file mode 100644 index b4b198a..0000000 --- a/jubeatools/formats/enum.py +++ /dev/null @@ -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" diff --git a/jubeatools/formats/guess.py b/jubeatools/formats/guess.py index fc4821c..364e3b2 100644 --- a/jubeatools/formats/guess.py +++ b/jubeatools/formats/guess.py @@ -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: diff --git a/jubeatools/formats/jubeat_analyser/memo/load.py b/jubeatools/formats/jubeat_analyser/memo/load.py index 498e5c7..2a4d5a7 100644 --- a/jubeatools/formats/jubeat_analyser/memo/load.py +++ b/jubeatools/formats/jubeat_analyser/memo/load.py @@ -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) diff --git a/jubeatools/formats/jubeat_analyser/memo1/load.py b/jubeatools/formats/jubeat_analyser/memo1/load.py index 2667c26..43f6f57 100644 --- a/jubeatools/formats/jubeat_analyser/memo1/load.py +++ b/jubeatools/formats/jubeat_analyser/memo1/load.py @@ -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) diff --git a/jubeatools/formats/jubeat_analyser/memo2/load.py b/jubeatools/formats/jubeat_analyser/memo2/load.py index ec48ffe..6009586 100644 --- a/jubeatools/formats/jubeat_analyser/memo2/load.py +++ b/jubeatools/formats/jubeat_analyser/memo2/load.py @@ -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) diff --git a/jubeatools/formats/jubeat_analyser/mono_column/load.py b/jubeatools/formats/jubeat_analyser/mono_column/load.py index 98f63ae..18d52fd 100644 --- a/jubeatools/formats/jubeat_analyser/mono_column/load.py +++ b/jubeatools/formats/jubeat_analyser/mono_column/load.py @@ -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: diff --git a/jubeatools/formats/jubeat_analyser/tests/memo/test_memo.py b/jubeatools/formats/jubeat_analyser/tests/memo/test_memo.py index 7275340..a14880f 100644 --- a/jubeatools/formats/jubeat_analyser/tests/memo/test_memo.py +++ b/jubeatools/formats/jubeat_analyser/tests/memo/test_memo.py @@ -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 diff --git a/jubeatools/formats/konami/eve/load.py b/jubeatools/formats/konami/eve/load.py index d42e738..fab9e37 100644 --- a/jubeatools/formats/konami/eve/load.py +++ b/jubeatools/formats/konami/eve/load.py @@ -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]: diff --git a/jubeatools/formats/konami/jbsq/load.py b/jubeatools/formats/konami/jbsq/load.py index e7ad02c..b607188 100644 --- a/jubeatools/formats/konami/jbsq/load.py +++ b/jubeatools/formats/konami/jbsq/load.py @@ -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: diff --git a/jubeatools/formats/loaders_and_dumpers.py b/jubeatools/formats/loaders_and_dumpers.py index 7aa613c..7a959c0 100644 --- a/jubeatools/formats/loaders_and_dumpers.py +++ b/jubeatools/formats/loaders_and_dumpers.py @@ -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] = { diff --git a/jubeatools/formats/malody/load.py b/jubeatools/formats/malody/load.py index dadc4ff..05a5dc9 100644 --- a/jubeatools/formats/malody/load.py +++ b/jubeatools/formats/malody/load.py @@ -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: diff --git a/jubeatools/formats/memon/tools.py b/jubeatools/formats/memon/tools.py index 6ea2aaf..0391378 100644 --- a/jubeatools/formats/memon/tools.py +++ b/jubeatools/formats/memon/tools.py @@ -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 diff --git a/jubeatools/formats/memon/v0/test_v0.py b/jubeatools/formats/memon/v0/test_v0.py index 54fe1d7..f2ebd56 100644 --- a/jubeatools/formats/memon/v0/test_v0.py +++ b/jubeatools/formats/memon/v0/test_v0.py @@ -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 diff --git a/jubeatools/formats/memon/v1/tests/test_v1.py b/jubeatools/formats/memon/v1/tests/test_v1.py index 1dfe907..65ac55f 100644 --- a/jubeatools/formats/memon/v1/tests/test_v1.py +++ b/jubeatools/formats/memon/v1/tests/test_v1.py @@ -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 diff --git a/jubeatools/song.py b/jubeatools/song.py index fbc905b..880bf21 100644 --- a/jubeatools/song.py +++ b/jubeatools/song.py @@ -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() diff --git a/jubeatools/testutils/test_patterns.py b/jubeatools/testutils/test_patterns.py index 2a43686..e2171ef 100644 --- a/jubeatools/testutils/test_patterns.py +++ b/jubeatools/testutils/test_patterns.py @@ -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