Skip to content

Commit 3523e28

Browse files
authored
Merge pull request #60 from ulgens/update_precommit_hooks
Update precommit hooks
2 parents f4d24f6 + c68fafa commit 3523e28

File tree

5 files changed

+32
-45
lines changed

5 files changed

+32
-45
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.4.0
3+
rev: v4.6.0
44
hooks:
55
- id: check-added-large-files
66
- id: check-case-conflict
@@ -12,13 +12,11 @@ repos:
1212
- id: mixed-line-ending
1313
- id: trailing-whitespace
1414

15-
- repo: https://github.com/google/yapf
16-
rev: v0.40.1
17-
hooks:
18-
- id: yapf
19-
2015
- repo: https://github.com/astral-sh/ruff-pre-commit
21-
rev: v0.0.284
16+
rev: v0.5.5
2217
hooks:
2318
- id: ruff
19+
name: ruff lint
2420
args: ["--fix", "--show-fixes"]
21+
- id: ruff-format
22+
name: ruff format

pyproject.toml

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ version.source = "vcs"
6565
build.hooks.vcs.version-file = "src/click_option_group/_version.py"
6666

6767
[tool.ruff]
68+
exclude = []
6869
line-length = 120
70+
src = ["src"]
71+
72+
[tool.ruff.lint]
6973
select = [
7074
"E", "F", "W", # flake8
7175
"B", # flake8-bugbear
@@ -95,26 +99,15 @@ extend-ignore = [
9599
"PT012", # Block should contain a single simple statement
96100
"RUF009", # Too easy to get a false positive
97101
]
98-
src = ["src"]
99102
unfixable = ["T20", "F841"]
100-
exclude = []
101103

102104
[tool.isort]
105+
# Even though ruff is used as formatter, isort profile name is "black".
106+
profile = "black"
103107
multi_line_output = 3
104108
include_trailing_comma = true
105109
force_sort_within_sections = true
106110
force_to_top = ["typing", "pytest"]
107-
line_length = 120
108-
109-
[tool.yapf]
110-
based_on_style = "pep8"
111-
column_limit = 120
112-
blank_line_before_module_docstring = true
113-
coalesce_brackets = false
114-
dedent_closing_brackets = true
115-
split_arguments_when_comma_terminated = true
116-
split_before_dict_set_generator = true
117-
allow_split_before_dict_value = false
118111

119112
[tool.pytest.ini_options]
120113
testpaths = ["tests"]

src/click_option_group/_core.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,12 @@ def group(self) -> "OptionGroup":
6161
"""
6262
return self.__group
6363

64-
def handle_parse_result(self, ctx: click.Context, opts: Mapping[str, Any],
65-
args: List[str]) -> Tuple[Any, List[str]]:
64+
def handle_parse_result(
65+
self,
66+
ctx: click.Context,
67+
opts: Mapping[str, Any],
68+
args: List[str],
69+
) -> Tuple[Any, List[str]]:
6670
with augment_usage_errors(ctx, param=self):
6771
if not ctx.resilient_parsing:
6872
self.group.handle_parse_result(self, ctx, opts)
@@ -390,7 +394,9 @@ def handle_parse_result(self, option: GroupedOption, ctx: click.Context, opts: M
390394
group_name = self._group_name_str()
391395
option_info = self.get_error_hint(ctx)
392396

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

418-
if (not option_names.isdisjoint(opts) and option_names.intersection(opts) != option_names):
424+
if not option_names.isdisjoint(opts) and option_names.intersection(opts) != option_names:
419425
group_name = self._group_name_str()
420426
option_info = self.get_error_hint(ctx)
421427

src/click_option_group/_decorators.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,9 @@ def group(
111111

112112
if not cls:
113113
cls = OptionGroup
114-
else:
115-
if not issubclass(cls, OptionGroup):
116-
msg = "'cls' must be a subclass of 'OptionGroup' class."
117-
raise TypeError(msg)
114+
elif not issubclass(cls, OptionGroup):
115+
msg = "'cls' must be a subclass of 'OptionGroup' class."
116+
raise TypeError(msg)
118117

119118
def decorator(func):
120119
callback, params = get_callback_and_params(func)
@@ -183,7 +182,7 @@ def help_option(self, *param_decls, **attrs) -> Decorator:
183182
the command's help text and exits.
184183
"""
185184
if not param_decls:
186-
param_decls = ("--help", )
185+
param_decls = ("--help",)
187186

188187
attrs.setdefault("is_flag", True)
189188
attrs.setdefault("is_eager", True)

tests/test_click_option_group.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717

1818
def test_basic_functionality_first_api(runner):
19-
2019
@click.command()
2120
@click.option("--hello")
2221
@optgroup("Group 1", help="Group 1 description")
@@ -45,7 +44,6 @@ def cli(hello, foo1, bar1, lol, foo2, bar2, goodbye):
4544

4645

4746
def test_noname_group(runner):
48-
4947
@click.command()
5048
@optgroup()
5149
@optgroup.option("--foo")
@@ -99,7 +97,6 @@ def cli3(**params):
9997

10098

10199
def test_missing_group_decl_first_api(runner):
102-
103100
@click.command()
104101
@click.option("--hello1")
105102
@optgroup.option("--foo")
@@ -111,31 +108,31 @@ def cli(**params):
111108
result = runner.invoke(cli, ["--help"])
112109

113110
assert result.exception
114-
assert TypeError == result.exc_info[0]
111+
assert isinstance(result.exception, TypeError)
115112
assert "Missing option group decorator" in str(result.exc_info[1])
116113
assert "--foo" in str(result.exc_info[1])
117114
assert "--bar" in str(result.exc_info[1])
118115

119116
result = runner.invoke(cli, [])
120117

121118
assert result.exception
122-
assert TypeError == result.exc_info[0]
119+
assert isinstance(result.exception, TypeError)
123120
assert "Missing option group" in str(result.exc_info[1])
124121
assert "--foo" in str(result.exc_info[1])
125122
assert "--bar" in str(result.exc_info[1])
126123

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

129126
assert result.exception
130-
assert TypeError == result.exc_info[0]
127+
assert isinstance(result.exception, TypeError)
131128
assert "Missing option group" in str(result.exc_info[1])
132129
assert "--foo" in str(result.exc_info[1])
133130
assert "--bar" in str(result.exc_info[1])
134131

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

137134
assert result.exception
138-
assert TypeError == result.exc_info[0]
135+
assert isinstance(result.exception, TypeError)
139136
assert "Missing option group" in str(result.exc_info[1])
140137
assert "--foo" in str(result.exc_info[1])
141138
assert "--bar" in str(result.exc_info[1])
@@ -184,7 +181,6 @@ def cli(**params):
184181

185182

186183
def test_incorrect_grouped_option_cls():
187-
188184
@click.command()
189185
@optgroup()
190186
@optgroup.option("--foo", cls=GroupedOption)
@@ -472,7 +468,6 @@ def cli(foo):
472468

473469

474470
def test_subcommand_first_api(runner):
475-
476471
@click.group()
477472
@optgroup("Group 1", help="Group 1 description")
478473
@optgroup.option("--foo")
@@ -677,7 +672,6 @@ def command2(**params):
677672

678673

679674
def test_command_first_api(runner):
680-
681675
@optgroup("Group 1")
682676
@optgroup.option("--foo")
683677
@optgroup.option("--bar")
@@ -697,7 +691,6 @@ def cli(foo, bar):
697691

698692

699693
def test_hidden_option(runner):
700-
701694
@click.command()
702695
@click.option("--hello")
703696
@optgroup("Group 1", help="Group 1 description")
@@ -746,7 +739,9 @@ def cli(foo, bar):
746739
def cli(foo, bar):
747740
click.echo(f"{foo},{bar}")
748741

749-
result = runner.invoke(cli, )
742+
result = runner.invoke(
743+
cli,
744+
)
750745
assert isinstance(result.exception, TypeError)
751746
assert "Need at least one non-hidden" in str(result.exception)
752747

@@ -797,7 +792,6 @@ def cli(foo, bar):
797792
],
798793
)
799794
def test_help_option(runner, param_decls, options, output):
800-
801795
@click.command()
802796
@optgroup("Help Options")
803797
@optgroup.help_option(*param_decls)
@@ -817,12 +811,10 @@ def cli() -> None:
817811

818812

819813
def test_wrapped_functions(runner):
820-
821814
def make_z():
822815
"""A unified option interface for making a `z`."""
823816

824817
def decorator(f):
825-
826818
@optgroup.group("Group xyz")
827819
@optgroup.option("-x", type=int)
828820
@optgroup.option("-y", type=int)
@@ -839,7 +831,6 @@ def make_c():
839831
"""A unified option interface for making a `c`."""
840832

841833
def decorator(f):
842-
843834
@optgroup.group("Group abc")
844835
@optgroup.option("-a", type=int)
845836
@optgroup.option("-b", type=int)

0 commit comments

Comments
 (0)