Skip to content

Commit afddc75

Browse files
authored
Merge pull request #18 from FlipperPA/black
Paint it Black!
2 parents 077d3ba + 48cc1c7 commit afddc75

File tree

18 files changed

+271
-254
lines changed

18 files changed

+271
-254
lines changed

djclick/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
from .adapter import CommandRegistrator as command # NOQA
88
from .adapter import GroupRegistrator as group, pass_verbosity # NOQA
99

10-
10+
# The RegEx in setup.py requires single quotes. Rather than change it, turn off Black.
11+
# fmt: off
1112
__version__ = '2.2.0'
1213
__url__ = 'https://github.com/GaretJax/django-click'
1314
__author__ = 'Jonathan Stoppani'
1415
__email__ = '[email protected]'
1516
__license__ = 'MIT'
16-
17+
# fmt: on
1718

1819
del click

djclick/adapter.py

Lines changed: 64 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
class OptionParseAdapter(object):
1414
"""Django pre-1.10-compatible adapter, deprecated"""
15+
1516
def parse_args(self, args):
1617
return (self, None) # NOCOV
1718

@@ -22,7 +23,7 @@ def __init__(self, args):
2223

2324
def _get_kwargs(self):
2425
return {
25-
'args': self._args,
26+
"args": self._args,
2627
}
2728

2829

@@ -43,8 +44,7 @@ class DjangoCommandMixin(object):
4344
@property
4445
def stealth_options(self):
4546
return sum(
46-
([p.name] + [i.lstrip('-') for i in p.opts] for p in self.params),
47-
[],
47+
([p.name] + [i.lstrip("-") for i in p.opts] for p in self.params), [],
4848
)
4949

5050
def invoke(self, ctx):
@@ -54,22 +54,26 @@ def invoke(self, ctx):
5454
# Honor the --traceback flag
5555
if ctx.traceback: # NOCOV
5656
raise
57-
styled_message = click.style('{}: {}'.format(e.__class__.__name__, e), fg='red', bold=True)
57+
styled_message = click.style(
58+
"{}: {}".format(e.__class__.__name__, e), fg="red", bold=True
59+
)
5860
click.echo(styled_message, err=True)
5961
ctx.exit(1)
6062

6163
def run_from_argv(self, argv):
6264
"""
6365
Called when run from the command line.
6466
"""
65-
prog_name = '{} {}'.format(os.path.basename(argv[0]), argv[1])
67+
prog_name = "{} {}".format(os.path.basename(argv[0]), argv[1])
6668
try:
6769
# We won't get an exception here in standalone_mode=False
68-
exit_code = self.main(args=argv[2:], prog_name=prog_name, standalone_mode=False)
70+
exit_code = self.main(
71+
args=argv[2:], prog_name=prog_name, standalone_mode=False
72+
)
6973
if exit_code:
7074
sys.exit(exit_code)
7175
except click.ClickException as e:
72-
if getattr(e.ctx, 'traceback', False): # NOCOV
76+
if getattr(e.ctx, "traceback", False): # NOCOV
7377
raise
7478
e.show()
7579
sys.exit(e.exit_code)
@@ -84,13 +88,13 @@ def create_parser(self, progname, subcommand):
8488
return OptionParseAdapter()
8589

8690
def print_help(self, prog_name, subcommand):
87-
prog_name = '{} {}'.format(prog_name, subcommand)
88-
self.main(['--help'], prog_name=prog_name, standalone_mode=False)
91+
prog_name = "{} {}".format(prog_name, subcommand)
92+
self.main(["--help"], prog_name=prog_name, standalone_mode=False)
8993

9094
def map_names(self):
9195
for param in self.params:
9296
for opt in param.opts:
93-
yield opt.lstrip('--').replace('-', '_'), param.name
97+
yield opt.lstrip("--").replace("-", "_"), param.name
9498

9599
def execute(self, *args, **kwargs):
96100
"""
@@ -100,13 +104,14 @@ def execute(self, *args, **kwargs):
100104
`call_command`.
101105
"""
102106
# Remove internal Django command handling machinery
103-
kwargs.pop('skip_checks', None)
107+
kwargs.pop("skip_checks", None)
104108
parent_ctx = click.get_current_context(silent=True)
105-
with self.make_context('', list(args), parent=parent_ctx) as ctx:
109+
with self.make_context("", list(args), parent=parent_ctx) as ctx:
106110
# Rename kwargs to to the appropriate destination argument name
107111
opt_mapping = dict(self.map_names())
108-
arg_options = {opt_mapping.get(key, key): value
109-
for key, value in six.iteritems(kwargs)}
112+
arg_options = {
113+
opt_mapping.get(key, key): value for key, value in six.iteritems(kwargs)
114+
}
110115

111116
# Update the context with the passed (renamed) kwargs
112117
ctx.params.update(arg_options)
@@ -150,53 +155,63 @@ def suppress_colors(ctx, param, value):
150155
class BaseRegistrator(object):
151156
common_options = [
152157
click.option(
153-
'-v', '--verbosity',
158+
"-v",
159+
"--verbosity",
154160
expose_value=False,
155-
default='1',
161+
default="1",
156162
callback=register_on_context,
157163
type=click.IntRange(min=0, max=3),
158-
help=('Verbosity level; 0=minimal output, 1=normal ''output, '
159-
'2=verbose output, 3=very verbose output.'),
164+
help=(
165+
"Verbosity level; 0=minimal output, 1=normal "
166+
"output, "
167+
"2=verbose output, 3=very verbose output."
168+
),
160169
),
161170
click.option(
162-
'--settings',
163-
metavar='SETTINGS',
171+
"--settings",
172+
metavar="SETTINGS",
164173
expose_value=False,
165-
help=('The Python path to a settings module, e.g. '
166-
'"myproject.settings.main". If this is not provided, the '
167-
'DJANGO_SETTINGS_MODULE environment variable will be used.'),
174+
help=(
175+
"The Python path to a settings module, e.g. "
176+
'"myproject.settings.main". If this is not provided, the '
177+
"DJANGO_SETTINGS_MODULE environment variable will be used."
178+
),
168179
),
169180
click.option(
170-
'--pythonpath',
171-
metavar='PYTHONPATH',
181+
"--pythonpath",
182+
metavar="PYTHONPATH",
172183
expose_value=False,
173-
help=('A directory to add to the Python path, e.g. '
174-
'"/home/djangoprojects/myproject".'),
184+
help=(
185+
"A directory to add to the Python path, e.g. "
186+
'"/home/djangoprojects/myproject".'
187+
),
175188
),
176189
click.option(
177-
'--traceback/--no-traceback',
190+
"--traceback/--no-traceback",
178191
is_flag=True,
179192
default=False,
180193
expose_value=False,
181194
callback=register_on_context,
182-
help='Raise on CommandError exceptions.',
195+
help="Raise on CommandError exceptions.",
183196
),
184197
click.option(
185-
'--color/--no-color',
198+
"--color/--no-color",
186199
default=None,
187200
expose_value=False,
188201
callback=suppress_colors,
189-
help=('Enable or disable output colorization. Default is to '
190-
'autodetect the best behavior.'),
202+
help=(
203+
"Enable or disable output colorization. Default is to "
204+
"autodetect the best behavior."
205+
),
191206
),
192207
]
193208

194209
def __init__(self, **kwargs):
195210
self.kwargs = kwargs
196-
self.version = self.kwargs.pop('version', get_version())
211+
self.version = self.kwargs.pop("version", get_version())
197212

198-
context_settings = kwargs.setdefault('context_settings', {})
199-
context_settings['help_option_names'] = ['-h', '--help']
213+
context_settings = kwargs.setdefault("context_settings", {})
214+
context_settings["help_option_names"] = ["-h", "--help"]
200215

201216
def get_params(self, name):
202217
def show_help(ctx, param, value):
@@ -205,17 +220,23 @@ def show_help(ctx, param, value):
205220
ctx.exit()
206221

207222
return [
208-
click.version_option(version=self.version, message='%(version)s'),
209-
click.option('-h', '--help', is_flag=True, is_eager=True,
210-
expose_value=False, callback=show_help,
211-
help='Show this message and exit.',),
223+
click.version_option(version=self.version, message="%(version)s"),
224+
click.option(
225+
"-h",
226+
"--help",
227+
is_flag=True,
228+
is_eager=True,
229+
expose_value=False,
230+
callback=show_help,
231+
help="Show this message and exit.",
232+
),
212233
] + self.common_options
213234

214235
def __call__(self, func):
215236
module = sys.modules[func.__module__]
216237

217238
# Get the command name as Django expects it
218-
self.name = func.__module__.rsplit('.', 1)[-1]
239+
self.name = func.__module__.rsplit(".", 1)[-1]
219240

220241
# Build the click command
221242
decorators = [
@@ -237,9 +258,11 @@ def pass_verbosity(f):
237258
"""
238259
Marks a callback as wanting to receive the verbosity as a keyword argument.
239260
"""
261+
240262
def new_func(*args, **kwargs):
241-
kwargs['verbosity'] = click.get_current_context().verbosity
263+
kwargs["verbosity"] = click.get_current_context().verbosity
242264
return f(*args, **kwargs)
265+
243266
return update_wrapper(new_func, f)
244267

245268

djclick/params.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,13 @@
44

55

66
class ModelInstance(click.ParamType):
7-
def __init__(self, qs, lookup='pk'):
7+
def __init__(self, qs, lookup="pk"):
88
from django.db import models
99

1010
if isinstance(qs, type) and issubclass(qs, models.Model):
1111
qs = qs.objects.all()
1212
self.qs = qs
13-
self.name = '{}.{}'.format(
14-
qs.model._meta.app_label,
15-
qs.model.__name__,
16-
)
13+
self.name = "{}.{}".format(qs.model._meta.app_label, qs.model.__name__,)
1714
self.lookup = lookup
1815

1916
def convert(self, value, param, ctx):
@@ -25,6 +22,7 @@ def convert(self, value, param, ctx):
2522
pass
2623
# call `fail` outside of exception context to avoid nested exception
2724
# handling on Python 3
28-
msg = 'could not find {s.name} with {s.lookup}={value}'.format(
29-
s=self, value=value)
25+
msg = "could not find {s.name} with {s.lookup}={value}".format(
26+
s=self, value=value
27+
)
3028
self.fail(msg, param, ctx)

djclick/test/conftest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
import pytest
77

88

9-
@pytest.fixture(scope='session')
9+
@pytest.fixture(scope="session")
1010
def manage():
1111
def call(*args, **kwargs):
12-
ignore_errors = kwargs.pop('ignore_errors', False)
12+
ignore_errors = kwargs.pop("ignore_errors", False)
1313
assert not kwargs
1414
cmd = [
1515
sys.executable,
16-
os.path.join(os.path.dirname(__file__), 'testprj', 'manage.py'),
16+
os.path.join(os.path.dirname(__file__), "testprj", "manage.py"),
1717
] + list(args)
1818
try:
1919
return subprocess.check_output(cmd, stderr=subprocess.STDOUT)

0 commit comments

Comments
 (0)