Skip to content

Commit

Permalink
style: Enable Ruff COM (commas) rules (meltano#7435)
Browse files Browse the repository at this point in the history
  • Loading branch information
WillDaSilva committed Mar 28, 2023
1 parent 72d5df8 commit afc3137
Show file tree
Hide file tree
Showing 175 changed files with 2,107 additions and 1,052 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,7 @@ ignore = [
]
select = [
"C4", # flake8-comprehensions
"COM", # flake8-commas
"E", # pycodestyle (error)
"F", # pyflakes
"I", # isort
Expand Down
4 changes: 3 additions & 1 deletion scripts/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ def build_webapp() -> None:

try:
node_version_check = subprocess.run(
("node", "--version"), text=True, capture_output=True
("node", "--version"),
text=True,
capture_output=True,
)
node_version_check.check_returncode()
except Exception:
Expand Down
2 changes: 1 addition & 1 deletion src/meltano/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def _run_cli():
cli(obj={"project": None})
except ProjectReadonly as err:
raise CliError(
f"The requested action could not be completed: {err}"
f"The requested action could not be completed: {err}",
) from err
except KeyboardInterrupt: # noqa: WPS329
raise
Expand Down
15 changes: 9 additions & 6 deletions src/meltano/cli/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ def add( # noqa: WPS238
PluginRef(plugin_type=plugin_type, name=name) for name in plugin_names
]
dependencies_met, err = check_dependencies_met(
plugin_refs=plugin_refs, plugins_service=project.plugins
plugin_refs=plugin_refs,
plugins_service=project.plugins,
)
if not dependencies_met:
tracker.track_command_event(CliEvent.aborted)
Expand All @@ -126,22 +127,24 @@ def add( # noqa: WPS238
variant=variant,
custom=flags["custom"],
add_service=add_service,
)
),
)
except Exception:
# if the plugin is not known to meltano send what information we do have
tracker.add_contexts(
PluginsTrackingContext([(plugin, None) for plugin in plugins])
PluginsTrackingContext([(plugin, None) for plugin in plugins]),
)
tracker.track_command_event(CliEvent.aborted)
raise

required_plugins = add_required_plugins(
project, plugins, add_service=add_service
project,
plugins,
add_service=add_service,
)
plugins.extend(required_plugins)
tracker.add_contexts(
PluginsTrackingContext([(candidate, None) for candidate in plugins])
PluginsTrackingContext([(candidate, None) for candidate in plugins]),
)
tracker.track_command_event(CliEvent.inflight)

Expand Down Expand Up @@ -169,5 +172,5 @@ def _print_plugins(plugins):

click.echo(
f"To learn more about {plugin.type.descriptor} '{plugin.name}', "
f"visit {docs_url}"
f"visit {docs_url}",
)
15 changes: 11 additions & 4 deletions src/meltano/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,23 @@ def main(self, *args, **kwargs) -> t.NoReturn:


@click.group(
cls=NoWindowsGlobbingGroup, invoke_without_command=True, no_args_is_help=True
cls=NoWindowsGlobbingGroup,
invoke_without_command=True,
no_args_is_help=True,
)
@click.option("--log-level", type=click.Choice(LEVELS.keys()))
@click.option(
"--log-config", type=str, help="Path to a python logging yaml config file."
"--log-config",
type=str,
help="Path to a python logging yaml config file.",
)
@click.option("-v", "--verbose", count=True, help="Not used.")
@click.option("--environment", help="Meltano environment name.")
@click.option(
"--no-environment", is_flag=True, default=False, help="Don't use any environment."
"--no-environment",
is_flag=True,
default=False,
help="Don't use any environment.",
)
@click.option(
"--cwd",
Expand Down Expand Up @@ -127,7 +134,7 @@ def cli( # noqa: C901,WPS231
)
click.echo(
"For more details, visit "
"https://docs.meltano.com/guide/installation#upgrading-meltano-version"
"https://docs.meltano.com/guide/installation#upgrading-meltano-version",
)
sys.exit(3)

Expand Down
9 changes: 5 additions & 4 deletions src/meltano/cli/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ def compile( # noqa: WPS125
directory.mkdir(parents=True, exist_ok=True)
except OSError as ex:
raise CliError(
f"Unable to create directory for Meltano manifests {directory}: {ex}"
f"Unable to create directory for Meltano manifests {directory}: {ex}",
) from ex

environments = _environments(ctx, project)

click.echo(
"Compiling Meltano manifest for environments: "
+ ", ".join("no environment" if x is None else x.name for x in environments)
+ ", ".join("no environment" if x is None else x.name for x in environments),
)
for environment in environments:
path = directory / (
Expand All @@ -96,7 +96,7 @@ def compile( # noqa: WPS125
)
except OSError as ex:
raise CliError(
f"Unable to write Meltano manifest {str(path)!r}: {ex}"
f"Unable to write Meltano manifest {str(path)!r}: {ex}",
) from ex

click.echo(f"Compiled {path}")
Expand All @@ -112,7 +112,8 @@ def _environments(
if ctx.obj["selected_environment"] and not ctx.obj["is_default_environment"]:
return (
Environment.find(
project.meltano.environments, ctx.obj["selected_environment"]
project.meltano.environments,
ctx.obj["selected_environment"],
),
)
return (None, *EnvironmentService(project).list_environments())
18 changes: 12 additions & 6 deletions src/meltano/cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ def get_label(metadata) -> str:
environment_behavior=CliEnvironmentBehavior.environment_optional_ignore_default,
)
@click.option(
"--plugin-type", type=click.Choice(PluginType.cli_arguments()), default=None
"--plugin-type",
type=click.Choice(PluginType.cli_arguments()),
default=None,
)
@click.argument("plugin_name")
@click.option(
Expand Down Expand Up @@ -154,7 +156,9 @@ def config( # noqa: WPS231

try:
plugin = project.plugins.find_plugin(
plugin_name, plugin_type=plugin_type, configurable=True
plugin_name,
plugin_type=plugin_type,
configurable=True,
)
except PluginNotFoundError:
if plugin_name == "meltano":
Expand Down Expand Up @@ -185,7 +189,9 @@ def config( # noqa: WPS231
if config_format == "json":
process = extras is not True
json_config = settings.as_dict(
extras=extras, process=process, session=session
extras=extras,
process=process,
session=session,
)
click.echo(json.dumps(json_config, indent=2))
elif config_format == "env":
Expand Down Expand Up @@ -293,7 +299,7 @@ def list_settings(ctx, extras: bool):
if docs_url:
click.echo()
click.echo(
f"To learn more about {settings.label} and its settings, visit {docs_url}"
f"To learn more about {settings.label} and its settings, visit {docs_url}",
)
tracker.track_command_event(CliEvent.completed)

Expand All @@ -320,7 +326,7 @@ def reset(ctx, store):
tracker.track_command_event(CliEvent.aborted)
raise CliError(
f"{settings.label.capitalize()} settings in {store.label} could "
f"not be reset: {err}"
f"not be reset: {err}",
) from err

store = metadata["store"]
Expand Down Expand Up @@ -415,7 +421,7 @@ def unset(ctx, setting_name, store):
tracker.track_command_event(CliEvent.aborted)
raise CliError(
f"{settings.label.capitalize()} setting '{path}' in {store.label} "
f"could not be unset: {err}"
f"could not be unset: {err}",
) from err

name = metadata["name"]
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 @@ -20,7 +20,9 @@
short_help="List the available plugins in Meltano Hub and their variants.",
)
@click.argument(
"plugin_type", type=click.Choice([*list(PluginType), "all"]), default="all"
"plugin_type",
type=click.Choice([*list(PluginType), "all"]),
default="all",
)
@pass_project()
@click.pass_context
Expand All @@ -45,7 +47,7 @@ def discover(ctx: click.Context, project: Project, plugin_type: str):

try:
plugin_type_index = project.hub_service.get_plugins_of_type(
discovered_plugin_type
discovered_plugin_type,
)
except Exception:
click.secho(
Expand Down
32 changes: 21 additions & 11 deletions src/meltano/cli/elt.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@
help="Dump content of pipeline-specific generated file.",
)
@click.option(
"--state-id", envvar="MELTANO_STATE_ID", help="A custom string to identify the job."
"--state-id",
envvar="MELTANO_STATE_ID",
help="A custom string to identify the job.",
)
@click.option(
"--force",
Expand Down Expand Up @@ -123,7 +125,7 @@ async def elt(
raise CliError(
"ELT command not supported on Windows. Please use the run command "
"as documented here: "
"https://docs.meltano.com/reference/command-line-interface#run"
"https://docs.meltano.com/reference/command-line-interface#run",
)

tracker: Tracker = ctx.obj["tracker"]
Expand All @@ -141,7 +143,7 @@ async def elt(
or (
f'{datetime.datetime.utcnow().strftime("%Y-%m-%dT%H%M%S")}--'
f"{extractor}--{loader}"
)
),
)
_, Session = project_engine(project) # noqa: N806
session = Session()
Expand Down Expand Up @@ -234,7 +236,7 @@ async def _run_job(tracker, project, job, session, context_builder, force=False)
raise CliError(
f"Another '{job.job_name}' pipeline is already running which "
f"started at {existing.started_at}. To ignore this check use "
"the '--force' option."
"the '--force' option.",
)

async with job.run(session):
Expand All @@ -252,10 +254,12 @@ async def _run_job(tracker, project, job, session, context_builder, force=False)
@asynccontextmanager
async def _redirect_output(log, output_logger):
meltano_stdout = output_logger.out(
"meltano", log.bind(stdio="stdout", cmd_type="elt")
"meltano",
log.bind(stdio="stdout", cmd_type="elt"),
)
meltano_stderr = output_logger.out(
"meltano", log.bind(stdio="stderr", cmd_type="elt")
"meltano",
log.bind(stdio="stderr", cmd_type="elt"),
)

with meltano_stdout.redirect_logging(ignore_errors=(CliError,)):
Expand Down Expand Up @@ -295,7 +299,7 @@ async def _run_elt(
"--log-level=debug ...' CLI flag.\nNote that you can also "
f"check the generated log file at '{output_logger.file}'.\n"
"For more information on debugging and logging: "
"https://docs.meltano.com/reference/command-line-interface#debugging"
"https://docs.meltano.com/reference/command-line-interface#debugging",
) from err


Expand All @@ -321,10 +325,14 @@ async def _run_extract_load(log, elt_context, output_logger, **kwargs): # noqa:
stdio="stdout",
)
extractor_out = output_logger.out(
f"{extractor} (out)", stdout_log.bind(cmd_type="extractor"), logging.DEBUG
f"{extractor} (out)",
stdout_log.bind(cmd_type="extractor"),
logging.DEBUG,
)
loader_out = output_logger.out(
f"{loader} (out)", stdout_log.bind(cmd_type="loader"), logging.DEBUG
f"{loader} (out)",
stdout_log.bind(cmd_type="loader"),
logging.DEBUG,
)

extractor_out_writer_ctxmgr = extractor_out.line_writer
Expand Down Expand Up @@ -391,12 +399,14 @@ def _find_transform_for_extractor(extractor: str, plugins_service):
discovery_service = plugins_service.discovery_service
try:
extractor_plugin_def = discovery_service.find_definition(
PluginType.EXTRACTORS, extractor
PluginType.EXTRACTORS,
extractor,
)

# Check if there is a default transform for this extractor
transform_plugin_def = discovery_service.find_definition_by_namespace(
PluginType.TRANSFORMS, extractor_plugin_def.namespace
PluginType.TRANSFORMS,
extractor_plugin_def.namespace,
)

# Check if the transform has been added to the project
Expand Down
7 changes: 5 additions & 2 deletions src/meltano/cli/initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
@click.pass_context
@click.argument("project_directory", required=False, type=path_type)
@click.option(
"--no_usage_stats", help="Do not send anonymous usage stats.", is_flag=True
"--no_usage_stats",
help="Do not send anonymous usage stats.",
is_flag=True,
)
@click.option(
"--force",
Expand All @@ -45,7 +47,8 @@ def init(ctx, project_directory: Path, no_usage_stats: bool, force: bool):
if not project_directory:
click.echo("We need a project name to get started!")
project_directory = click.prompt(
"Enter a name now to create a Meltano project", type=path_type
"Enter a name now to create a Meltano project",
type=path_type,
)

if ctx.obj["project"]:
Expand Down
6 changes: 4 additions & 2 deletions src/meltano/cli/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

@cli.command(cls=PartialInstrumentedCmd, short_help="Install project dependencies.")
@click.argument(
"plugin_type", type=click.Choice(PluginType.cli_arguments()), required=False
"plugin_type",
type=click.Choice(PluginType.cli_arguments()),
required=False,
)
@click.argument("plugin_name", nargs=-1, required=False)
@click.option(
Expand Down Expand Up @@ -74,7 +76,7 @@ def install(

click.echo(f"Installing {len(plugins)} plugins...")
tracker.add_contexts(
PluginsTrackingContext([(candidate, None) for candidate in plugins])
PluginsTrackingContext([(candidate, None) for candidate in plugins]),
)
tracker.track_command_event(CliEvent.inflight)

Expand Down

0 comments on commit afc3137

Please sign in to comment.