Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove yapf & Update ruff #63

Merged
merged 2 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ repos:
- id: mixed-line-ending
- id: trailing-whitespace

- repo: https://github.com/google/yapf
rev: v0.40.1
hooks:
- id: yapf

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.284
rev: v0.5.5
hooks:
- id: ruff
name: ruff lint
args: ["--fix", "--show-fixes"]
- id: ruff-format
name: ruff format
19 changes: 6 additions & 13 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ version.source = "vcs"
build.hooks.vcs.version-file = "src/click_option_group/_version.py"

[tool.ruff]
exclude = []
line-length = 120
src = ["src"]

[tool.ruff.lint]
select = [
"E", "F", "W", # flake8
"B", # flake8-bugbear
Expand Down Expand Up @@ -95,26 +99,15 @@ extend-ignore = [
"PT012", # Block should contain a single simple statement
"RUF009", # Too easy to get a false positive
]
src = ["src"]
unfixable = ["T20", "F841"]
exclude = []

[tool.isort]
# Even though ruff is used as formatter, isort profile name is "black".
profile = "black"
multi_line_output = 3
include_trailing_comma = true
force_sort_within_sections = true
force_to_top = ["typing", "pytest"]
line_length = 120

[tool.yapf]
based_on_style = "pep8"
column_limit = 120
blank_line_before_module_docstring = true
coalesce_brackets = false
dedent_closing_brackets = true
split_arguments_when_comma_terminated = true
split_before_dict_set_generator = true
allow_split_before_dict_value = false

[tool.pytest.ini_options]
testpaths = ["tests"]
Expand Down
14 changes: 10 additions & 4 deletions src/click_option_group/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,12 @@ def group(self) -> "OptionGroup":
"""
return self.__group

def handle_parse_result(self, ctx: click.Context, opts: Mapping[str, Any],
args: List[str]) -> Tuple[Any, List[str]]:
def handle_parse_result(
self,
ctx: click.Context,
opts: Mapping[str, Any],
args: List[str],
) -> Tuple[Any, List[str]]:
with augment_usage_errors(ctx, param=self):
if not ctx.resilient_parsing:
self.group.handle_parse_result(self, ctx, opts)
Expand Down Expand Up @@ -390,7 +394,9 @@ def handle_parse_result(self, option: GroupedOption, ctx: click.Context, opts: M
group_name = self._group_name_str()
option_info = self.get_error_hint(ctx)

msg = f"Missing one of the required mutually exclusive options from {group_name} option group:\n{option_info}"
msg = (
f"Missing one of the required mutually exclusive options from {group_name} option group:\n{option_info}"
)
raise click.UsageError(
msg,
ctx=ctx,
Expand All @@ -415,7 +421,7 @@ def name_extra(self) -> List[str]:
def handle_parse_result(self, option: GroupedOption, ctx: click.Context, opts: Mapping[str, Any]) -> None:
option_names = set(self.get_options(ctx))

if (not option_names.isdisjoint(opts) and option_names.intersection(opts) != option_names):
if not option_names.isdisjoint(opts) and option_names.intersection(opts) != option_names:
group_name = self._group_name_str()
option_info = self.get_error_hint(ctx)

Expand Down
9 changes: 4 additions & 5 deletions src/click_option_group/_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,9 @@ def group(

if not cls:
cls = OptionGroup
else:
if not issubclass(cls, OptionGroup):
msg = "'cls' must be a subclass of 'OptionGroup' class."
raise TypeError(msg)
elif not issubclass(cls, OptionGroup):
msg = "'cls' must be a subclass of 'OptionGroup' class."
raise TypeError(msg)

def decorator(func):
callback, params = get_callback_and_params(func)
Expand Down Expand Up @@ -183,7 +182,7 @@ def help_option(self, *param_decls, **attrs) -> Decorator:
the command's help text and exits.
"""
if not param_decls:
param_decls = ("--help", )
param_decls = ("--help",)

attrs.setdefault("is_flag", True)
attrs.setdefault("is_eager", True)
Expand Down
23 changes: 7 additions & 16 deletions tests/test_click_option_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@


def test_basic_functionality_first_api(runner):

@click.command()
@click.option("--hello")
@optgroup("Group 1", help="Group 1 description")
Expand Down Expand Up @@ -45,7 +44,6 @@ def cli(hello, foo1, bar1, lol, foo2, bar2, goodbye):


def test_noname_group(runner):

@click.command()
@optgroup()
@optgroup.option("--foo")
Expand Down Expand Up @@ -99,7 +97,6 @@ def cli3(**params):


def test_missing_group_decl_first_api(runner):

@click.command()
@click.option("--hello1")
@optgroup.option("--foo")
Expand All @@ -111,31 +108,31 @@ def cli(**params):
result = runner.invoke(cli, ["--help"])

assert result.exception
assert TypeError == result.exc_info[0]
assert isinstance(result.exception, TypeError)
assert "Missing option group decorator" in str(result.exc_info[1])
assert "--foo" in str(result.exc_info[1])
assert "--bar" in str(result.exc_info[1])

result = runner.invoke(cli, [])

assert result.exception
assert TypeError == result.exc_info[0]
assert isinstance(result.exception, TypeError)
assert "Missing option group" in str(result.exc_info[1])
assert "--foo" in str(result.exc_info[1])
assert "--bar" in str(result.exc_info[1])

result = runner.invoke(cli, ["--hello1", "hello1"])

assert result.exception
assert TypeError == result.exc_info[0]
assert isinstance(result.exception, TypeError)
assert "Missing option group" in str(result.exc_info[1])
assert "--foo" in str(result.exc_info[1])
assert "--bar" in str(result.exc_info[1])

result = runner.invoke(cli, ["--foo", "foo"])

assert result.exception
assert TypeError == result.exc_info[0]
assert isinstance(result.exception, TypeError)
assert "Missing option group" in str(result.exc_info[1])
assert "--foo" in str(result.exc_info[1])
assert "--bar" in str(result.exc_info[1])
Expand Down Expand Up @@ -184,7 +181,6 @@ def cli(**params):


def test_incorrect_grouped_option_cls():

@click.command()
@optgroup()
@optgroup.option("--foo", cls=GroupedOption)
Expand Down Expand Up @@ -472,7 +468,6 @@ def cli(foo):


def test_subcommand_first_api(runner):

@click.group()
@optgroup("Group 1", help="Group 1 description")
@optgroup.option("--foo")
Expand Down Expand Up @@ -677,7 +672,6 @@ def command2(**params):


def test_command_first_api(runner):

@optgroup("Group 1")
@optgroup.option("--foo")
@optgroup.option("--bar")
Expand All @@ -697,7 +691,6 @@ def cli(foo, bar):


def test_hidden_option(runner):

@click.command()
@click.option("--hello")
@optgroup("Group 1", help="Group 1 description")
Expand Down Expand Up @@ -746,7 +739,9 @@ def cli(foo, bar):
def cli(foo, bar):
click.echo(f"{foo},{bar}")

result = runner.invoke(cli, )
result = runner.invoke(
cli,
)
assert isinstance(result.exception, TypeError)
assert "Need at least one non-hidden" in str(result.exception)

Expand Down Expand Up @@ -797,7 +792,6 @@ def cli(foo, bar):
],
)
def test_help_option(runner, param_decls, options, output):

@click.command()
@optgroup("Help Options")
@optgroup.help_option(*param_decls)
Expand All @@ -817,12 +811,10 @@ def cli() -> None:


def test_wrapped_functions(runner):

def make_z():
"""A unified option interface for making a `z`."""

def decorator(f):

@optgroup.group("Group xyz")
@optgroup.option("-x", type=int)
@optgroup.option("-y", type=int)
Expand All @@ -839,7 +831,6 @@ def make_c():
"""A unified option interface for making a `c`."""

def decorator(f):

@optgroup.group("Group abc")
@optgroup.option("-a", type=int)
@optgroup.option("-b", type=int)
Expand Down
Loading