From 9866b7b96991cc57190eed0321b549c3fc227697 Mon Sep 17 00:00:00 2001 From: SoulMelody Date: Fri, 10 Jan 2025 06:02:14 +0800 Subject: [PATCH] reformat code using ruff 0.9 --- .pre-commit-config.yaml | 2 +- libresvip/cli/commands/plugin.py | 4 ++-- libresvip/core/config.py | 2 +- libresvip/model/base.py | 6 +++--- libresvip/plugins/json/__init__.py | 1 + libresvip/plugins/svp/param_expression.py | 4 ++-- libresvip/plugins/svp/synthv_parser.py | 5 +++++ libresvip/plugins/vspx/vspx_interval_dict.py | 2 +- libresvip/tui/app.py | 6 +++--- libresvip/web/pages.py | 6 +++--- tests/test_plugin.py | 5 +---- 11 files changed, 23 insertions(+), 20 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 92f82c37d..d0819ed69 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,7 +3,7 @@ ci: repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.8.6 + rev: v0.9.0 hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix, --show-fixes] diff --git a/libresvip/cli/commands/plugin.py b/libresvip/cli/commands/plugin.py index 4659b5018..f231c5f70 100644 --- a/libresvip/cli/commands/plugin.py +++ b/libresvip/cli/commands/plugin.py @@ -94,14 +94,14 @@ def print_plugin_details(plugin: FormatProviderPluginInfo) -> None: if plugin.website: typer.echo("\n" + _("Website: ") + plugin.website) format_desc = f"{_(plugin.file_format)} (*.{plugin.suffix})" - typer.echo("\n" + f'{_("This plugin is applicable to")} {format_desc}.') + typer.echo("\n" + f"{_('This plugin is applicable to')} {format_desc}.") typer.echo( _( "If you want to use this plugin, please specify '-i {}' (input) or '-o {}' (output) when converting." ).format(plugin.suffix.lower(), plugin.suffix.lower()) ) if plugin.description: - typer.echo(f'\n{_("Description: ")}\n{_(plugin.description)}') + typer.echo(f"\n{_('Description: ')}\n{_(plugin.description)}") op_arr = [_("input"), _("output")] options_arr = [ get_type_hints(plugin.plugin_object.load).get("options", None), diff --git a/libresvip/core/config.py b/libresvip/core/config.py index 873ff5313..f43ace54f 100644 --- a/libresvip/core/config.py +++ b/libresvip/core/config.py @@ -298,7 +298,7 @@ def to_language(locale: str) -> str: """Turn a locale name (en_US) into a language name (en-us).""" p = locale.find("_") if p >= 0: - return f"{locale[:p].lower()}-{locale[p + 1:].lower()}" + return f"{locale[:p].lower()}-{locale[p + 1 :].lower()}" else: return locale.lower() diff --git a/libresvip/model/base.py b/libresvip/model/base.py index 60c084df9..67ac38578 100644 --- a/libresvip/model/base.py +++ b/libresvip/model/base.py @@ -285,9 +285,9 @@ def merge_projects(cls, projects: list[Project]) -> Project: ) def split_tracks(self, max_track_count: int) -> list[Project]: - assert any( - isinstance(track, SingingTrack) for track in self.track_list - ), "No singing tracks found" + assert any(isinstance(track, SingingTrack) for track in self.track_list), ( + "No singing tracks found" + ) return [ self.model_copy(update={"track_list": track_chunk}, deep=True) for track_chunk in more_itertools.chunked( diff --git a/libresvip/plugins/json/__init__.py b/libresvip/plugins/json/__init__.py index e69de29bb..dc9fd4c06 100644 --- a/libresvip/plugins/json/__init__.py +++ b/libresvip/plugins/json/__init__.py @@ -0,0 +1 @@ +# noqa: A005 diff --git a/libresvip/plugins/svp/param_expression.py b/libresvip/plugins/svp/param_expression.py index 533c6dbb9..15520c808 100644 --- a/libresvip/plugins/svp/param_expression.py +++ b/libresvip/plugins/svp/param_expression.py @@ -116,14 +116,14 @@ class CurveGenerator(ParamExpression): _interpolation: dataclasses.InitVar[ Callable[[float, tuple[float, float], tuple[float, float]], float] ] - _base_value: dataclasses.InitVar[int] = 0 + _base_value: dataclasses.InitVar[int] interval: Optional[portion.Interval] = None def __post_init__( self, _point_list: Iterable[Point], _interpolation: Callable[[float, tuple[float, float], tuple[float, float]], float], - _base_value: int = 0, + _base_value: int, ) -> None: self.point_list = [] current_pos = -1 diff --git a/libresvip/plugins/svp/synthv_parser.py b/libresvip/plugins/svp/synthv_parser.py index 664e0cdd8..1b4fbae59 100644 --- a/libresvip/plugins/svp/synthv_parser.py +++ b/libresvip/plugins/svp/synthv_parser.py @@ -174,6 +174,7 @@ def parse_param_curve( for point in master_curve.points.root ], _interpolation=self.parse_interpolation(master_curve.mode), + _base_value=0, ) compound_expr = group_expr + master_expr group_points = group_expr.point_list @@ -266,6 +267,7 @@ def parse_pitch_curve( for point in pitch_diff.points.root ], _interpolation=self.parse_interpolation(pitch_diff.mode), + _base_value=0, ) vibrato_env_expr: ParamExpression = CurveGenerator( _point_list=[ @@ -288,6 +290,7 @@ def parse_pitch_curve( for point in master_pitch_diff.points.root ], _interpolation=self.parse_interpolation(master_pitch_diff.mode), + _base_value=0, ) if master_vibrato_env is not None: vibrato_env_expr += CurveGenerator( @@ -299,6 +302,7 @@ def parse_pitch_curve( for point in master_vibrato_env.points.root ], _interpolation=self.parse_interpolation(vibrato_env.mode), + _base_value=0, ) if self.options.instant: instant_interval = RangeInterval( @@ -321,6 +325,7 @@ def parse_pitch_curve( for point in self.instant_pitch.points.root ], _interpolation=self.parse_interpolation(self.instant_pitch.mode), + _base_value=0, ) interval = RangeInterval( [ diff --git a/libresvip/plugins/vspx/vspx_interval_dict.py b/libresvip/plugins/vspx/vspx_interval_dict.py index bcb312f97..3df02c9ea 100644 --- a/libresvip/plugins/vspx/vspx_interval_dict.py +++ b/libresvip/plugins/vspx/vspx_interval_dict.py @@ -54,7 +54,7 @@ class BasePitchCurve: def __post_init__( self, note_track: VocalSharpNoteTrack, - default_trill: Optional[VocalSharpDefaultTrill] = None, + default_trill: Optional[VocalSharpDefaultTrill], ) -> None: if not len(note_track.note): pass diff --git a/libresvip/tui/app.py b/libresvip/tui/app.py index 7107ed997..b3e35a405 100644 --- a/libresvip/tui/app.py +++ b/libresvip/tui/app.py @@ -147,8 +147,8 @@ def compose(self) -> ComposeResult: plugin_info = plugin_manager.plugin_registry[self.plugin_id] with Vertical(): yield Label(plugin_info.name, classes="title") - yield Label(f'{_("Version: ")}{plugin_info.version}') - yield Link(f'{_("Author: ")}{_(plugin_info.author)}', url=plugin_info.website) + yield Label(f"{_('Version: ')}{plugin_info.version}") + yield Link(f"{_('Author: ')}{_(plugin_info.author)}", url=plugin_info.website) yield Label(_("Introduction")) yield Markdown(_(plugin_info.description)) with Horizontal(): @@ -934,7 +934,7 @@ def compose(self) -> ComposeResult: url="https://github.com/SoulMelody/LibreSVIP", tooltip=_("Repo URL"), ) - yield Label(f'{_("Version: ")}{libresvip.__version__} 🔖') + yield Label(f"{_('Version: ')}{libresvip.__version__} 🔖") yield Link( _("Author: SoulMelody") + " 🌐", url="https://space.bilibili.com/175862486", diff --git a/libresvip/web/pages.py b/libresvip/web/pages.py index 4b442a275..21d202412 100644 --- a/libresvip/web/pages.py +++ b/libresvip/web/pages.py @@ -1964,7 +1964,7 @@ def tasks_area() -> None: js_handler=f"""(event) => {{ for (let file of event.dataTransfer.files) {{ let file_name = file.name - post_form('{uploader.props['url']}', {{ + post_form('{uploader.props["url"]}', {{ file_name: file }}) }} @@ -2037,7 +2037,7 @@ def tasks_area() -> None: js_handler=f"""(event) => {{ for (let file of event.dataTransfer.files) {{ let file_name = file.name - post_form('{uploader.props['url']}', {{ + post_form('{uploader.props["url"]}', {{ file_name: file }}) }} @@ -2217,7 +2217,7 @@ def add_javascript() -> None: for (const fileHandle of fileHandles) {{ const file = await fileHandle.getFile(); let file_name = file.name - post_form('{uploader.props['url']}', {{ + post_form('{uploader.props["url"]}', {{ file_name: file }}) }} diff --git a/tests/test_plugin.py b/tests/test_plugin.py index cb97a9e88..a32b53d1d 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -315,10 +315,7 @@ def test_ps_project_read(shared_datadir: pathlib.Path) -> None: proj_path = shared_datadir / "test.ps_project" with AESZipFile( - io.BytesIO(proj_path.read_bytes()), - "r", - compression=ZIP_STORED, - encryption=WZ_AES + io.BytesIO(proj_path.read_bytes()), "r", compression=ZIP_STORED, encryption=WZ_AES ) as zf: zf.setpassword(b"a022ab39cb3b7b1de92ee441978c9e08") rich.print(zf.read("config.json"))