Skip to content
Snippets Groups Projects
Commit ee4b1c9f authored by André Anjos's avatar André Anjos :speech_balloon:
Browse files

Merge branch 'fix_line_length' into 'main'

fix(ruff): set to line length back to 88 as used originally

See merge request !22
parents cf10ccea 2f7d35dd
No related branches found
No related tags found
1 merge request!22fix(ruff): set to line length back to 88 as used originally
Pipeline #86946 passed
......@@ -130,7 +130,7 @@ include = [
packages = ["src/clapper"]
[tool.ruff]
line-length = 80
line-length = 88
target-version = "py310"
[tool.ruff.format]
......
......@@ -91,9 +91,7 @@ def verbosity_option(
}[value]
logger.setLevel(log_level)
logger.debug(
f'Level of Logger("{logger.name}") was set to {log_level}'
)
logger.debug(f'Level of Logger("{logger.name}") was set to {log_level}')
return value
return click.option(
......@@ -168,9 +166,7 @@ will override the values of configuration files. You can run this command with
# Add the config argument to the command
def configs_argument_callback(ctx, param, value):
config_context = load(
value, entry_point_group=self.entry_point_group
)
config_context = load(value, entry_point_group=self.entry_point_group)
config_context = mod_to_context(config_context)
ctx.config_context = config_context
......@@ -246,9 +242,7 @@ will override the values of configuration files. You can run this command with
f" [default: {param.default}]",
)
config_file.write(
f"{begin}: {param.name} ({', '.join(param.opts)}){dflt}"
)
config_file.write(f"{begin}: {param.name} ({', '.join(param.opts)}){dflt}")
if param.help is not None:
config_file.write(f"\n{param.help}")
......@@ -264,9 +258,7 @@ will override the values of configuration files. You can run this command with
config_file.write('"""\n')
click.echo(
f"Configuration file `{config_file.name}' was written; exiting"
)
click.echo(f"Configuration file `{config_file.name}' was written; exiting")
config_file.close()
ctx.exit()
......@@ -356,9 +348,7 @@ class ResourceOption(click.Option):
self.entry_point_group = entry_point_group
if entry_point_group is not None:
name, _, _ = self._parse_decls(
param_decls, kwargs.get("expose_value")
)
name, _, _ = self._parse_decls(param_decls, kwargs.get("expose_value"))
help = help or "" # noqa: A001
help += ( # noqa: A001
f" Can be a `{entry_point_group}' entry point, a module name, or "
......@@ -406,9 +396,7 @@ class ResourceOption(click.Option):
it used to retrieve it.
"""
if (
not hasattr(ctx, "config_context")
) and self.entry_point_group is None:
if (not hasattr(ctx, "config_context")) and self.entry_point_group is None:
raise TypeError(
"The ResourceOption class is not meant to be used this way. "
"See package documentation for details."
......@@ -442,9 +430,7 @@ class ResourceOption(click.Option):
return value, source
def type_cast_value(
self, ctx: click.Context, value: typing.Any
) -> typing.Any:
def type_cast_value(self, ctx: click.Context, value: typing.Any) -> typing.Any:
"""Convert and validate a value against the option's type.
This method considers the option's ``type``, ``multiple``, and ``nargs``.
......@@ -466,9 +452,7 @@ class ResourceOption(click.Option):
# if the value is a string and an entry_point_group is provided, load it
if self.entry_point_group is not None:
while (
isinstance(value, str) and value not in self.string_exceptions
):
while isinstance(value, str) and value not in self.string_exceptions:
value = load(
[value],
entry_point_group=self.entry_point_group,
......@@ -691,9 +675,7 @@ def config_group(
def group_decorator(
func: typing.Callable[..., typing.Any],
) -> typing.Callable[..., typing.Any]:
@click.group(
cls=AliasedGroup, context_settings=_COMMON_CONTEXT_SETTINGS
)
@click.group(cls=AliasedGroup, context_settings=_COMMON_CONTEXT_SETTINGS)
@verbosity_option(logger=logger)
@functools.wraps(func)
def group_wrapper(**kwargs):
......@@ -760,8 +742,7 @@ def config_group(
if ":" in ep.value: # it's an object
summary = (
f"[{type(obj).__name__}] "
f"{pprint.pformat(obj)}"
f"[{type(obj).__name__}] {pprint.pformat(obj)}"
)
summary = summary.replace("\n", " ")
else: # it's a whole module
......@@ -774,9 +755,7 @@ def config_group(
summary += "[undocumented]"
except Exception as ex:
summary = (
"(cannot be loaded; add another -v for details)"
)
summary = "(cannot be loaded; add another -v for details)"
if (ctx.parent.params["verbose"] >= 2) or (
ctx.params["verbose"] >= 2
):
......@@ -875,9 +854,7 @@ def config_group(
return group_decorator
def log_parameters(
logger_handle: logging.Logger, ignore: tuple[str] | None = None
):
def log_parameters(logger_handle: logging.Logger, ignore: tuple[str] | None = None):
"""Log the click parameters with the logging module.
Parameters
......
......@@ -147,9 +147,7 @@ def _resolve_entry_point_or_modules(
object_names = []
for path in paths:
module_name = (
"user_config" # fixed module name for files with full paths
)
module_name = "user_config" # fixed module name for files with full paths
resolved_path, object_name = _object_name(path, common_name)
# if it already points to a file, then do nothing
......@@ -163,10 +161,7 @@ def _resolve_entry_point_or_modules(
object_name = entry.attr if entry.attr else common_name
resolved_path = _get_module_filename(module_name)
if (
resolved_path is None
or not pathlib.Path(resolved_path).is_file()
):
if resolved_path is None or not pathlib.Path(resolved_path).is_file():
raise ValueError(
f"The specified entry point `{path}' pointing to module "
f"`{module_name}' and resolved to `{resolved_path}' does "
......@@ -177,10 +172,7 @@ def _resolve_entry_point_or_modules(
else:
# if we have gotten here so far then path must resolve as a module
resolved_path = _get_module_filename(resolved_path)
if (
resolved_path is None
or not pathlib.Path(resolved_path).is_file()
):
if resolved_path is None or not pathlib.Path(resolved_path).is_file():
raise ValueError(
f"The specified path `{path}' is not a file, a entry "
f"point name, or a known-module name"
......@@ -267,9 +259,7 @@ def load(
ctxt.__dict__.pop("__name__", None)
ctxt.__dict__.pop("__package__", None)
# do not propogate __ variables
context = {
k: v for k, v in ctxt.__dict__.items() if not k.startswith("__")
}
context = {k: v for k, v in ctxt.__dict__.items() if not k.startswith("__")}
mod.__dict__.update(context)
_LOADED_CONFIGS.append(mod)
ctxt = _load_context(k, mod)
......
......@@ -74,8 +74,7 @@ def setup(
# First check that logger with a matching name or stream is not already
# there before attaching a new one.
if (debug_logger_name not in handlers_installed) or (
getattr(handlers_installed[debug_logger_name], "stream")
!= low_level_stream
getattr(handlers_installed[debug_logger_name], "stream") != low_level_stream
):
debug_info = logging.StreamHandler(low_level_stream)
debug_info.setLevel(logging.DEBUG)
......@@ -89,8 +88,7 @@ def setup(
# First check that logger with a matching name or stream is not already
# there before attaching a new one.
if (error_logger_name not in handlers_installed) or (
getattr(handlers_installed[error_logger_name], "stream")
!= high_level_stream
getattr(handlers_installed[error_logger_name], "stream") != high_level_stream
):
warn_err = logging.StreamHandler(high_level_stream)
warn_err.setLevel(logging.WARNING)
......
......@@ -69,9 +69,7 @@ class UserDefaults(collections.abc.MutableMapping):
def read(self) -> None:
"""Read configuration file, replaces any internal values."""
if self.path.exists():
self.logger.debug(
"User configuration file exists, reading contents..."
)
self.logger.debug("User configuration file exists, reading contents...")
self.data.clear()
with self.path.open("rb") as f:
......
......@@ -224,9 +224,7 @@ def test_config_dump2(tmp_path, datadir):
runner = CliRunner()
output = tmp_path / "test_dump.py"
result = runner.invoke(
test, ["test", "-H", str(output)], catch_exceptions=False
)
result = runner.invoke(test, ["test", "-H", str(output)], catch_exceptions=False)
ref = datadir / "test_dump_config2.py"
assert result.exit_code == 0
......@@ -235,9 +233,7 @@ def test_config_dump2(tmp_path, datadir):
def test_config_command_with_callback_options():
@click.command(cls=ConfigCommand, entry_point_group="clapper.test.config")
@verbosity_option(
logging.getLogger(__name__), envvar="VERBOSE", cls=ResourceOption
)
@verbosity_option(logging.getLogger(__name__), envvar="VERBOSE", cls=ResourceOption)
@click.pass_context
def cli(ctx, **_):
verbose = ctx.meta["verbose"]
......
......@@ -57,9 +57,7 @@ def test_config_with_module():
def test_config_with_entry_point():
c = load(
["first", "second", "complex"], entry_point_group="clapper.test.config"
)
c = load(["first", "second", "complex"], entry_point_group="clapper.test.config")
assert hasattr(c, "a") and c.a == 1
assert hasattr(c, "b") and c.b == 6
assert hasattr(c, "cplx") and isinstance(c.cplx, dict)
......@@ -173,9 +171,7 @@ def test_config_click_describe_error(cli_messages):
runner = CliRunner()
result = runner.invoke(cli, ["describe", "not-found"])
assert result.exit_code == 0
assert (
"Cannot find configuration resource `not-found'" in messages.getvalue()
)
assert "Cannot find configuration resource `not-found'" in messages.getvalue()
def test_config_click_copy(cli_messages, datadir, tmp_path):
......@@ -193,7 +189,4 @@ def test_config_click_copy_error(cli_messages, datadir, tmp_path):
dest = tmp_path / "file.py"
result = runner.invoke(cli, ["copy", "firstx", str(dest)])
assert result.exit_code == 0
assert (
"[ERROR] Cannot find configuration resource `firstx'"
in messages.getvalue()
)
assert "[ERROR] Cannot find configuration resource `firstx'" in messages.getvalue()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment