Skip to content

Commit 8bfb76a

Browse files
committed
Switch to black
Signed-off-by: Stephen Finucane <stephen@that.guru>
1 parent 7a7240b commit 8bfb76a

File tree

7 files changed

+192
-84
lines changed

7 files changed

+192
-84
lines changed

.pre-commit-config.yaml

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,29 @@
1+
# See https://pre-commit.com for more information
2+
# See https://pre-commit.com/hooks.html for more hooks
3+
---
4+
default_language_version:
5+
# force all unspecified python hooks to run python3
6+
python: python3
17
repos:
2-
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v2.2.3
4-
hooks:
5-
- id: flake8
6-
- id: trailing-whitespace
8+
- repo: https://github.com/ambv/black
9+
rev: stable
10+
hooks:
11+
- id: black
12+
- repo: https://github.com/pre-commit/pre-commit-hooks
13+
rev: v3.1.0
14+
hooks:
15+
- id: trailing-whitespace
16+
- id: mixed-line-ending
17+
args: ['--fix', 'lf']
18+
- id: check-byte-order-marker
19+
- id: check-executables-have-shebangs
20+
- id: check-merge-conflict
21+
- id: debug-statements
22+
- id: end-of-file-fixer
23+
- id: check-yaml
24+
files: .*\.(yaml|yml)$
25+
- id: check-added-large-files
26+
- repo: https://gitlab.com/pycqa/flake8
27+
rev: 3.8.3
28+
hooks:
29+
- id: flake8

pyproject.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[tool.black]
2+
line-length = 88
3+
target-version = ['py36']
4+
skip-string-normalization = true
5+
exclude = '''
6+
(
7+
/(
8+
\.eggs
9+
| \.git
10+
| \.tox
11+
| \.venv
12+
| build
13+
| dist
14+
)
15+
)
16+
'''

setup.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,7 @@ packages =
2525

2626
[wheel]
2727
universal = 1
28+
29+
[flake8]
30+
max-line-length = 88
31+
ignore = E203,E501,E741,W503

setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@
33
from setuptools import setup
44

55
setup(
6-
setup_requires=['pbr>=2.0'],
7-
pbr=True,
6+
setup_requires=['pbr>=2.0'], pbr=True,
87
)

sphinx_click/ext.py

Lines changed: 46 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def _get_help_record(opt):
3838
3939
[1] http://www.sphinx-doc.org/en/stable/domains.html#directive-option
4040
"""
41+
4142
def _write_opts(opts):
4243
rv, _ = click.formatting.join_options(opts)
4344
if not opt.is_flag and not opt.count:
@@ -57,9 +58,14 @@ def _write_opts(opts):
5758
# documentation thus needs a manually written string.
5859
extra.append('default: %s' % opt.show_default)
5960
else:
60-
extra.append('default: %s' %
61-
(', '.join('%s' % d for d in opt.default) if isinstance(
62-
opt.default, (list, tuple)) else opt.default, ))
61+
extra.append(
62+
'default: %s'
63+
% (
64+
', '.join('%s' % d for d in opt.default)
65+
if isinstance(opt.default, (list, tuple))
66+
else opt.default,
67+
)
68+
)
6369
if opt.required:
6470
extra.append('required')
6571
if extra:
@@ -84,9 +90,9 @@ def _format_description(ctx):
8490
return
8591

8692
bar_enabled = False
87-
for line in statemachine.string2lines(help_string,
88-
tab_width=4,
89-
convert_whitespace=True):
93+
for line in statemachine.string2lines(
94+
help_string, tab_width=4, convert_whitespace=True
95+
):
9096
if line == '\b':
9197
bar_enabled = True
9298
continue
@@ -113,18 +119,19 @@ def _format_option(opt):
113119
yield '.. option:: {}'.format(opt[0])
114120
if opt[1]:
115121
yield ''
116-
for line in statemachine.string2lines(opt[1],
117-
tab_width=4,
118-
convert_whitespace=True):
122+
for line in statemachine.string2lines(
123+
opt[1], tab_width=4, convert_whitespace=True
124+
):
119125
yield _indent(line)
120126

121127

122128
def _format_options(ctx):
123129
"""Format all `click.Option` for a `click.Command`."""
124130
# the hidden attribute is part of click 7.x only hence use of getattr
125131
params = [
126-
x for x in ctx.command.params
127-
if isinstance(x, click.Option) and not getattr(x, 'hidden', False)
132+
param
133+
for param in ctx.command.params
134+
if isinstance(param, click.Option) and not getattr(param, 'hidden', False)
128135
]
129136

130137
for param in params:
@@ -137,9 +144,11 @@ def _format_argument(arg):
137144
"""Format the output of a `click.Argument`."""
138145
yield '.. option:: {}'.format(arg.human_readable_name)
139146
yield ''
140-
yield _indent('{} argument{}'.format(
141-
'Required' if arg.required else 'Optional',
142-
'(s)' if arg.nargs != 1 else ''))
147+
yield _indent(
148+
'{} argument{}'.format(
149+
'Required' if arg.required else 'Optional', '(s)' if arg.nargs != 1 else ''
150+
)
151+
)
143152

144153

145154
def _format_arguments(ctx):
@@ -195,9 +204,9 @@ def _format_subcommand(command):
195204

196205
if short_help:
197206
yield ''
198-
for line in statemachine.string2lines(short_help,
199-
tab_width=4,
200-
convert_whitespace=True):
207+
for line in statemachine.string2lines(
208+
short_help, tab_width=4, convert_whitespace=True
209+
):
201210
yield _indent(line)
202211

203212

@@ -311,39 +320,39 @@ def _load_module(self, module_path):
311320
module_name, attr_name = module_path.split(':', 1)
312321
except ValueError: # noqa
313322
raise self.error(
314-
'"{}" is not of format "module:parser"'.format(module_path))
323+
'"{}" is not of format "module:parser"'.format(module_path)
324+
)
315325

316326
try:
317327
mod = __import__(module_name, globals(), locals(), [attr_name])
318328
except (Exception, SystemExit) as exc: # noqa
319-
err_msg = 'Failed to import "{}" from "{}". '.format(
320-
attr_name, module_name)
329+
err_msg = 'Failed to import "{}" from "{}". '.format(attr_name, module_name)
321330
if isinstance(exc, SystemExit):
322331
err_msg += 'The module appeared to call sys.exit()'
323332
else:
324333
err_msg += 'The following exception was raised:\n{}'.format(
325-
traceback.format_exc())
334+
traceback.format_exc()
335+
)
326336

327337
raise self.error(err_msg)
328338

329339
if not hasattr(mod, attr_name):
330-
raise self.error('Module "{}" has no attribute "{}"'.format(
331-
module_name, attr_name))
340+
raise self.error(
341+
'Module "{}" has no attribute "{}"'.format(module_name, attr_name)
342+
)
332343

333344
parser = getattr(mod, attr_name)
334345

335346
if not isinstance(parser, click.BaseCommand):
336-
raise self.error('"{}" of type "{}" is not derived from '
337-
'"click.BaseCommand"'.format(
338-
type(parser), module_path))
347+
raise self.error(
348+
'"{}" of type "{}" is not derived from '
349+
'"click.BaseCommand"'.format(type(parser), module_path)
350+
)
339351
return parser
340352

341-
def _generate_nodes(self,
342-
name,
343-
command,
344-
parent=None,
345-
show_nested=False,
346-
commands=None):
353+
def _generate_nodes(
354+
self, name, command, parent=None, show_nested=False, commands=None
355+
):
347356
"""Generate the relevant Sphinx nodes.
348357
349358
Format a `click.Group` or `click.Command`.
@@ -367,7 +376,8 @@ def _generate_nodes(self,
367376
'',
368377
nodes.title(text=name),
369378
ids=[nodes.make_id(ctx.command_path)],
370-
names=[nodes.fully_normalize_name(ctx.command_path)])
379+
names=[nodes.fully_normalize_name(ctx.command_path)],
380+
)
371381

372382
# Summary
373383

@@ -387,8 +397,8 @@ def _generate_nodes(self,
387397
commands = _filter_commands(ctx, commands)
388398
for command in commands:
389399
section.extend(
390-
self._generate_nodes(command.name, command, ctx,
391-
show_nested))
400+
self._generate_nodes(command.name, command, ctx, show_nested)
401+
)
392402

393403
return [section]
394404

@@ -404,8 +414,7 @@ def run(self):
404414
show_nested = 'show-nested' in self.options
405415
commands = self.options.get('commands')
406416

407-
return self._generate_nodes(prog_name, command, None, show_nested,
408-
commands)
417+
return self._generate_nodes(prog_name, command, None, show_nested, commands)
409418

410419

411420
def setup(app):

0 commit comments

Comments
 (0)