Skip to content

Commit

Permalink
style: Enable Ruff ARG (flake8-unused-arguments) rules (meltano#7501)
Browse files Browse the repository at this point in the history
Co-authored-by: Edgar R. M <edgar@meltano.com>
Co-authored-by: Cody J. Hanson <cody@meltano.com>
  • Loading branch information
3 people committed Apr 11, 2023
1 parent 9dcc6a6 commit 8791799
Show file tree
Hide file tree
Showing 82 changed files with 636 additions and 624 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@ ignore = [
"UP026", # Replace `mock` import with `unittest.mock` - remove once Python 3.7 support is dropped
]
select = [
"ARG", # flake8-unused-arguments
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"COM", # flake8-commas
Expand Down
2 changes: 0 additions & 2 deletions src/meltano/cli/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ def add( # noqa: WPS238
try:
plugins.append(
add_plugin(
project,
plugin_type,
plugin,
inherit_from=inherit_from,
Expand All @@ -137,7 +136,6 @@ def add( # noqa: WPS238
raise

required_plugins = add_required_plugins(
project,
plugins,
add_service=add_service,
)
Expand Down
6 changes: 4 additions & 2 deletions src/meltano/cli/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
default="all",
)
@pass_project()
@click.pass_context
def discover(ctx: click.Context, project: Project, plugin_type: str):
def discover( # noqa: C901
project: Project,
plugin_type: str,
):
"""
List the available discoverable plugins and their variants.
Expand Down
3 changes: 1 addition & 2 deletions src/meltano/cli/dragon.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@


@click.command(short_help="Summon a dragon!")
@click.pass_context
def dragon(ctx):
def dragon():
"""Summon a dragon."""
dragon_list = [
MELTY,
Expand Down
4 changes: 0 additions & 4 deletions src/meltano/cli/invoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,6 @@ def invoke(
exit_code = asyncio.run(
_invoke(
invoker,
project,
plugin_name,
plugin_args,
session,
dump,
Expand All @@ -146,8 +144,6 @@ def invoke(

async def _invoke(
invoker: PluginInvoker,
project: Project,
plugin_name: str,
plugin_args: str,
session: sessionmaker,
dump: str,
Expand Down
3 changes: 1 addition & 2 deletions src/meltano/cli/remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
@click.argument("plugin_type", type=click.Choice(PluginType.cli_arguments()))
@click.argument("plugin_names", nargs=-1, required=True)
@pass_project()
@click.pass_context
def remove(ctx, project, plugin_type, plugin_names):
def remove(project, plugin_type, plugin_names):
"""
Remove plugins from your project.
Expand Down
2 changes: 0 additions & 2 deletions src/meltano/cli/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,8 @@ def selection_mark(selection):
help="Exclude all attributes that match specified pattern.",
)
@pass_project(migrate=True)
@click.pass_context
@click_run_async
async def select(
ctx: click.Context,
project: Project,
extractor: str,
entities_filter: str,
Expand Down
33 changes: 12 additions & 21 deletions src/meltano/cli/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import re
import typing as t
from datetime import datetime as dt
from functools import partial, reduce, wraps
from functools import partial, reduce
from operator import xor

import click
Expand Down Expand Up @@ -47,23 +47,17 @@ def __str__(self) -> str:
def _prompt_for_confirmation(prompt):
"""Wrap destructive CLI commands which should prompt the user for confirmation."""

def wrapper(func):
fun = click.option(
"--force",
is_flag=True,
help="Don't prompt for confirmation.",
)(func)

@wraps(func)
def _wrapper(force=False, *args, **kwargs):
if force or click.confirm(prompt):
return fun(*args, **kwargs, force=force)
else:
click.secho("Aborting.", fg="red")

return _wrapper
def _prompt_callback(ctx, param, value): # noqa: ARG001
if not value:
click.confirm(prompt)

return wrapper
return click.option(
"--force",
is_flag=True,
expose_value=False,
callback=_prompt_callback,
help="Don't prompt for confirmation.",
)


prompt_for_confirmation = partial(
Expand Down Expand Up @@ -164,7 +158,6 @@ def copy_state(
project: Project,
src_state_id: str,
dst_state_id: str,
force: bool,
):
"""Copy state to another job ID."""
# Retrieve state for copying
Expand Down Expand Up @@ -195,7 +188,6 @@ def move_state(
project: Project,
src_state_id: str,
dst_state_id: str,
force: bool,
):
"""Move state to another job ID, clearing the original."""
# Retrieve state for moveing
Expand Down Expand Up @@ -281,7 +273,6 @@ def set_state(
state_id: str,
state: str | None,
input_file: click.Path | None,
force: bool,
):
"""Set state."""
state_service: StateService = (
Expand Down Expand Up @@ -322,7 +313,7 @@ def get_state(ctx: click.Context, project: Project, state_id: str): # noqa: WPS
@click.argument("state-id")
@pass_project(migrate=True)
@click.pass_context
def clear_state(ctx: click.Context, project: Project, state_id: str, force: bool):
def clear_state(ctx: click.Context, project: Project, state_id: str):
"""Clear state."""
state_service: StateService = (
state_service_from_state_id(project, state_id) or ctx.obj[STATE_SERVICE_KEY]
Expand Down
3 changes: 1 addition & 2 deletions src/meltano/cli/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ def user(ctx, project):
"admin and regular."
),
)
@click.pass_context
def add(ctx, username, password, role, **flags):
def add(username, password, role, **flags):
"""
Create a Meltano user account.
Expand Down
2 changes: 0 additions & 2 deletions src/meltano/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ def _prompt_plugin_settings(plugin_type):


def add_plugin(
project: Project,
plugin_type: PluginType,
plugin_name: str,
add_service: ProjectAddService,
Expand Down Expand Up @@ -355,7 +354,6 @@ def add_plugin(


def add_required_plugins(
project: Project,
plugins: list[ProjectPlugin],
add_service: ProjectAddService,
lock: bool = True,
Expand Down
2 changes: 0 additions & 2 deletions src/meltano/cli/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ async def run_test(self, name: str) -> int:
nargs=-1,
)
@pass_project(migrate=True)
@click.pass_context
def test(
ctx: click.Context,
project: Project,
all_tests: bool,
plugin_tests: tuple[str] = (),
Expand Down
2 changes: 1 addition & 1 deletion src/meltano/core/behavior/canonical.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def with_attrs(self: T, *args: t.Any, **kwargs: t.Any) -> T:
Returns:
A new instance with the given attributes set.
"""
return type(self)(**{**self.canonical(), **kwargs})
return type(self)(*args, **{**self.canonical(), **kwargs})

@classmethod
def parse(cls: type[T], obj: t.Any) -> T:
Expand Down
5 changes: 4 additions & 1 deletion src/meltano/core/job/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,10 @@ async def _heartbeating(self, session):
await heartbeat_future

@contextmanager
def _handling_sigterm(self, session):
def _handling_sigterm(
self,
session, # noqa: ARG002
):
def handler(*_): # noqa: WPS430
sigterm_status = 143
raise SystemExit(sigterm_status)
Expand Down
2 changes: 1 addition & 1 deletion src/meltano/core/plugin/airflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def update_config_file(invoker: AirflowInvoker) -> None:
logging.debug(f"Saved '{str(airflow_cfg_path)}'")

@hook("before_install")
async def setup_env(self, *args, **kwargs):
async def setup_env(self, *args, **kwargs): # noqa: ARG002
"""Configure the env to make airflow installable without GPL deps.
Args:
Expand Down
10 changes: 8 additions & 2 deletions src/meltano/core/plugin/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,10 @@ def all_requires(self):
"""
return self._variant.requires

def env_prefixes(self, for_writing=False) -> list[str]:
def env_prefixes(
self,
for_writing=False, # noqa: ARG002
) -> list[str]:
"""Return environment variable prefixes to use for settings.
Args:
Expand Down Expand Up @@ -701,7 +704,10 @@ def should_add_to_file(self) -> bool:
"""
return True

def exec_args(self, files: dict):
def exec_args(
self,
files: dict, # noqa: ARG002
):
"""Return the arguments to pass to the plugin runner.
Args:
Expand Down
2 changes: 1 addition & 1 deletion src/meltano/core/plugin/dbt/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async def install_dbt_plugin(
project: Project,
plugin: ProjectPlugin,
reason: PluginInstallReason,
**kwargs,
**kwargs, # noqa: ARG001
) -> None:
"""Install the transform into the project.
Expand Down
12 changes: 7 additions & 5 deletions src/meltano/core/plugin/meltano_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
import yaml

from meltano.core import bundle
from meltano.core.plugin.file import FilePlugin
from meltano.core.project import Project

from .file import FilePlugin


class MeltanoFilePlugin(FilePlugin):
overwrite = {"meltano.yml"}
Expand All @@ -18,7 +17,10 @@ def __init__(self, discovery: bool = False):
super().__init__(None, None)
self._discovery = discovery

def file_contents(self, project) -> dict[Path, str]:
def file_contents(
self,
project, # noqa: ARG002
) -> dict[Path, str]:
"""Get a mapping of paths to contents.
Args:
Expand All @@ -36,7 +38,7 @@ def file_contents(self, project) -> dict[Path, str]:
file_contents["discovery.yml"] = (bundle.root / "discovery.yml").read_text()
return file_contents

def update_config(self, project):
def update_config(self, project): # noqa: ARG002, D102
return {}

def files_to_create(
Expand All @@ -58,7 +60,7 @@ def files_to_create(
def project_file_contents(
self,
project: Project,
paths_to_update: list[str],
paths_to_update: list[str], # noqa: ARG002
) -> dict[Path, str]:
"""Return the contents of the files to be created or updated in the project.
Expand Down
8 changes: 6 additions & 2 deletions src/meltano/core/plugin/singer/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,12 @@ def _pop_non_leaf_keys(nested_config: dict) -> None: # noqa: WPS430
return processed_config

@hook("before_configure")
async def before_configure(self, invoker, session):
"""Create configuration file."""
async def before_configure(
self,
invoker,
session, # noqa: ARG002
):
"""Create configuration file.""" # noqa: DAR101
config_path = invoker.files["config"]
with open(config_path, "w") as config_file:
config = invoker.plugin_config_processed
Expand Down

0 comments on commit 8791799

Please sign in to comment.