Skip to content

Commit ce59d2b

Browse files
committed
Reformat code with black
1 parent 3818b76 commit ce59d2b

File tree

6 files changed

+335
-229
lines changed

6 files changed

+335
-229
lines changed

sphinxarg/ext.py

Lines changed: 129 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ def map_nested_definitions(nested_content):
3535
if len(ci.children) > 0:
3636
classifier = ci.children[0].astext()
3737
if classifier is not None and classifier not in (
38-
'@replace', '@before', '@after', '@skip'):
38+
'@replace',
39+
'@before',
40+
'@after',
41+
'@skip',
42+
):
3943
raise Exception('Unknown classifier: %s' % classifier)
4044
idx = subitem.first_child_matching_class(nodes.term)
4145
if idx is not None:
@@ -61,6 +65,7 @@ def renderList(l, markDownHelp, settings=None):
6165
return []
6266
if markDownHelp:
6367
from sphinxarg.markdown import parseMarkDownBlock
68+
6469
return parseMarkDownBlock('\n\n'.join(l) + '\n')
6570
else:
6671
all_children = []
@@ -121,20 +126,25 @@ def print_action_groups(data, nested_content, markDownHelp=False, settings=None)
121126
items = []
122127
# Iterate over action group members
123128
for entry in action_group['options']:
124-
"""
125-
Members will include:
126-
default The default value. This may be ==SUPPRESS==
127-
name A list of option names (e.g., ['-h', '--help']
128-
help The help message string
129-
There may also be a 'choices' member.
130-
"""
129+
# Members will include:
130+
# default The default value. This may be ==SUPPRESS==
131+
# name A list of option names (e.g., ['-h', '--help']
132+
# help The help message string
133+
# There may also be a 'choices' member.
131134
# Build the help text
132135
arg = []
133136
if 'choices' in entry:
134-
arg.append('Possible choices: {}\n'.format(", ".join([str(c) for c in entry['choices']])))
137+
arg.append(
138+
'Possible choices: {}\n'.format(
139+
", ".join([str(c) for c in entry['choices']])
140+
)
141+
)
135142
if 'help' in entry:
136143
arg.append(entry['help'])
137-
if entry['default'] is not None and entry['default'] not in ['"==SUPPRESS=="', '==SUPPRESS==']:
144+
if entry['default'] is not None and entry['default'] not in [
145+
'"==SUPPRESS=="',
146+
'==SUPPRESS==',
147+
]:
138148
if entry['default'] == '':
139149
arg.append('Default: ""')
140150
else:
@@ -153,9 +163,11 @@ def print_action_groups(data, nested_content, markDownHelp=False, settings=None)
153163
desc.insert(0, s)
154164
term = ', '.join(entry['name'])
155165

156-
n = nodes.option_list_item('',
157-
nodes.option_group('', nodes.option_string(text=term)),
158-
nodes.description('', *renderList(desc, markDownHelp, settings)))
166+
n = nodes.option_list_item(
167+
'',
168+
nodes.option_group('', nodes.option_string(text=term)),
169+
nodes.description('', *renderList(desc, markDownHelp, settings)),
170+
)
159171
items.append(n)
160172

161173
section += nodes.option_list('', *items)
@@ -205,12 +217,14 @@ def print_subcommands(data, nested_content, markDownHelp=False, settings=None):
205217
for element in renderList(desc, markDownHelp):
206218
sec += element
207219
sec += nodes.literal_block(text=child['bare_usage'])
208-
for x in print_action_groups(child, nested_content + subContent, markDownHelp,
209-
settings=settings):
220+
for x in print_action_groups(
221+
child, nested_content + subContent, markDownHelp, settings=settings
222+
):
210223
sec += x
211224

212-
for x in print_subcommands(child, nested_content + subContent, markDownHelp,
213-
settings=settings):
225+
for x in print_subcommands(
226+
child, nested_content + subContent, markDownHelp, settings=settings
227+
):
214228
sec += x
215229

216230
if 'epilog' in child and child['epilog']:
@@ -250,12 +264,23 @@ def ensureUniqueIDs(items):
250264

251265
class ArgParseDirective(Directive):
252266
has_content = True
253-
option_spec = dict(module=unchanged, func=unchanged, ref=unchanged,
254-
prog=unchanged, path=unchanged, nodefault=flag,
255-
nodefaultconst=flag, filename=unchanged,
256-
manpage=unchanged, nosubcommands=unchanged, passparser=flag,
257-
noepilog=unchanged, nodescription=unchanged,
258-
markdown=flag, markdownhelp=flag)
267+
option_spec = dict(
268+
module=unchanged,
269+
func=unchanged,
270+
ref=unchanged,
271+
prog=unchanged,
272+
path=unchanged,
273+
nodefault=flag,
274+
nodefaultconst=flag,
275+
filename=unchanged,
276+
manpage=unchanged,
277+
nosubcommands=unchanged,
278+
passparser=flag,
279+
noepilog=unchanged,
280+
nodescription=unchanged,
281+
markdown=flag,
282+
markdownhelp=flag,
283+
)
259284

260285
def _construct_manpage_specific_structure(self, parser_info):
261286
"""
@@ -274,37 +299,38 @@ def _construct_manpage_specific_structure(self, parser_info):
274299
'',
275300
nodes.title(text='Synopsis'),
276301
nodes.literal_block(text=parser_info["bare_usage"]),
277-
ids=['synopsis-section'])
302+
ids=['synopsis-section'],
303+
)
278304
items.append(synopsis_section)
279305
# DESCRIPTION section
280306
if 'nodescription' not in self.options:
281307
description_section = nodes.section(
282308
'',
283309
nodes.title(text='Description'),
284-
nodes.paragraph(text=parser_info.get(
285-
'description', parser_info.get(
286-
'help', "undocumented").capitalize())),
287-
ids=['description-section'])
288-
nested_parse_with_titles(
289-
self.state, self.content, description_section)
310+
nodes.paragraph(
311+
text=parser_info.get(
312+
'description',
313+
parser_info.get('help', "undocumented").capitalize(),
314+
)
315+
),
316+
ids=['description-section'],
317+
)
318+
nested_parse_with_titles(self.state, self.content, description_section)
290319
items.append(description_section)
291320
if parser_info.get('epilog') and 'noepilog' not in self.options:
292321
# TODO: do whatever sphinx does to understand ReST inside
293322
# docstrings magically imported from other places. The nested
294323
# parse method invoked above seem to be able to do this but
295324
# I haven't found a way to do it for arbitrary text
296325
if description_section:
297-
description_section += nodes.paragraph(
298-
text=parser_info['epilog'])
326+
description_section += nodes.paragraph(text=parser_info['epilog'])
299327
else:
300-
description_section = nodes.paragraph(
301-
text=parser_info['epilog'])
328+
description_section = nodes.paragraph(text=parser_info['epilog'])
302329
items.append(description_section)
303330
# OPTIONS section
304331
options_section = nodes.section(
305-
'',
306-
nodes.title(text='Options'),
307-
ids=['options-section'])
332+
'', nodes.title(text='Options'), ids=['options-section']
333+
)
308334
if 'args' in parser_info:
309335
options_section += nodes.paragraph()
310336
options_section += nodes.subtitle(text='Positional arguments:')
@@ -326,21 +352,22 @@ def _construct_manpage_specific_structure(self, parser_info):
326352
if 'nosubcommands' not in self.options:
327353
# SUBCOMMANDS section (non-standard)
328354
subcommands_section = nodes.section(
329-
'',
330-
nodes.title(text='Sub-Commands'),
331-
ids=['subcommands-section'])
355+
'', nodes.title(text='Sub-Commands'), ids=['subcommands-section']
356+
)
332357
if 'children' in parser_info:
333358
subcommands_section += self._format_subcommands(parser_info)
334359
if len(subcommands_section) > 1:
335360
items.append(subcommands_section)
336361
if os.getenv("INCLUDE_DEBUG_SECTION"):
337362
import json
363+
338364
# DEBUG section (non-standard)
339365
debug_section = nodes.section(
340366
'',
341367
nodes.title(text="Argparse + Sphinx Debugging"),
342368
nodes.literal_block(text=json.dumps(parser_info, indent=' ')),
343-
ids=['debug-section'])
369+
ids=['debug-section'],
370+
)
344371
items.append(debug_section)
345372
return items
346373

@@ -356,16 +383,18 @@ def _format_positional_arguments(self, parser_info):
356383
if 'choices' in arg:
357384
arg_items.append(
358385
nodes.paragraph(
359-
text='Possible choices: ' + ', '.join(arg['choices'])))
386+
text='Possible choices: ' + ', '.join(arg['choices'])
387+
)
388+
)
360389
items.append(
361390
nodes.option_list_item(
362391
'',
363392
nodes.option_group(
364-
'', nodes.option(
365-
'', nodes.option_string(text=arg['metavar'])
366-
)
393+
'', nodes.option('', nodes.option_string(text=arg['metavar']))
367394
),
368-
nodes.description('', *arg_items)))
395+
nodes.description('', *arg_items),
396+
)
397+
)
369398
return nodes.option_list('', *items)
370399

371400
def _format_optional_arguments(self, parser_info):
@@ -376,10 +405,13 @@ def _format_optional_arguments(self, parser_info):
376405
opt_items = []
377406
for name in opt['name']:
378407
option_declaration = [nodes.option_string(text=name)]
379-
if opt['default'] is not None \
380-
and opt['default'] not in ['"==SUPPRESS=="', '==SUPPRESS==']:
408+
if opt['default'] is not None and opt['default'] not in [
409+
'"==SUPPRESS=="',
410+
'==SUPPRESS==',
411+
]:
381412
option_declaration += nodes.option_argument(
382-
'', text='=' + str(opt['default']))
413+
'', text='=' + str(opt['default'])
414+
)
383415
names.append(nodes.option('', *option_declaration))
384416
if opt['help']:
385417
opt_items.append(nodes.paragraph(text=opt['help']))
@@ -388,11 +420,16 @@ def _format_optional_arguments(self, parser_info):
388420
if 'choices' in opt:
389421
opt_items.append(
390422
nodes.paragraph(
391-
text='Possible choices: ' + ', '.join(opt['choices'])))
423+
text='Possible choices: ' + ', '.join(opt['choices'])
424+
)
425+
)
392426
items.append(
393427
nodes.option_list_item(
394-
'', nodes.option_group('', *names),
395-
nodes.description('', *opt_items)))
428+
'',
429+
nodes.option_group('', *names),
430+
nodes.description('', *opt_items),
431+
)
432+
)
396433
return nodes.option_list('', *items)
397434

398435
def _format_subcommands(self, parser_info):
@@ -407,9 +444,10 @@ def _format_subcommands(self, parser_info):
407444
items.append(
408445
nodes.definition_list_item(
409446
'',
410-
nodes.term('', '', nodes.strong(
411-
text=subcmd['bare_usage'])),
412-
nodes.definition('', *subcmd_items)))
447+
nodes.term('', '', nodes.strong(text=subcmd['bare_usage'])),
448+
nodes.definition('', *subcmd_items),
449+
)
450+
)
413451
return nodes.definition_list('', *items)
414452

415453
def _nested_parse_paragraph(self, text):
@@ -438,20 +476,27 @@ def run(self):
438476
func = mod[attr_name]
439477
else:
440478
raise self.error(
441-
':module: and :func: should be specified, or :ref:, or :filename: and :func:')
479+
':module: and :func: should be specified, or :ref:, or :filename: and :func:'
480+
)
442481

443482
# Skip this if we're dealing with a local file, since it obviously can't be imported
444483
if 'filename' not in self.options:
445484
try:
446485
mod = __import__(module_name, globals(), locals(), [attr_name])
447486
except:
448-
raise self.error('Failed to import "%s" from "%s".\n%s' % (attr_name, module_name, sys.exc_info()[1]))
487+
raise self.error(
488+
'Failed to import "%s" from "%s".\n%s'
489+
% (attr_name, module_name, sys.exc_info()[1])
490+
)
449491

450492
if not hasattr(mod, attr_name):
451-
raise self.error((
452-
'Module "%s" has no attribute "%s"\n'
453-
'Incorrect argparse :module: or :func: values?'
454-
) % (module_name, attr_name))
493+
raise self.error(
494+
(
495+
'Module "%s" has no attribute "%s"\n'
496+
'Incorrect argparse :module: or :func: values?'
497+
)
498+
% (module_name, attr_name)
499+
)
455500
func = getattr(mod, attr_name)
456501

457502
if isinstance(func, ArgumentParser):
@@ -467,7 +512,10 @@ def run(self):
467512
if 'prog' in self.options:
468513
parser.prog = self.options['prog']
469514
result = parse_parser(
470-
parser, skip_default_values='nodefault' in self.options, skip_default_const_values='nodefaultconst' in self.options)
515+
parser,
516+
skip_default_values='nodefault' in self.options,
517+
skip_default_const_values='nodefaultconst' in self.options,
518+
)
471519
result = parser_navigate(result, path)
472520
if 'manpage' in self.options:
473521
return self._construct_manpage_specific_structure(result)
@@ -477,10 +525,10 @@ def run(self):
477525
nested_content = nodes.paragraph()
478526
if 'markdown' in self.options:
479527
from sphinxarg.markdown import parseMarkDownBlock
528+
480529
items.extend(parseMarkDownBlock('\n'.join(self.content) + '\n'))
481530
else:
482-
self.state.nested_parse(
483-
self.content, self.content_offset, nested_content)
531+
self.state.nested_parse(self.content, self.content_offset, nested_content)
484532
nested_content = nested_content.children
485533
# add common content between
486534
for item in nested_content:
@@ -496,11 +544,23 @@ def run(self):
496544
else:
497545
items.append(self._nested_parse_paragraph(result['description']))
498546
items.append(nodes.literal_block(text=result['usage']))
499-
items.extend(print_action_groups(result, nested_content, markDownHelp,
500-
settings=self.state.document.settings))
547+
items.extend(
548+
print_action_groups(
549+
result,
550+
nested_content,
551+
markDownHelp,
552+
settings=self.state.document.settings,
553+
)
554+
)
501555
if 'nosubcommands' not in self.options:
502-
items.extend(print_subcommands(result, nested_content, markDownHelp,
503-
settings=self.state.document.settings))
556+
items.extend(
557+
print_subcommands(
558+
result,
559+
nested_content,
560+
markDownHelp,
561+
settings=self.state.document.settings,
562+
)
563+
)
504564
if 'epilog' in result and 'noepilog' not in self.options:
505565
items.append(self._nested_parse_paragraph(result['epilog']))
506566

@@ -512,7 +572,4 @@ def run(self):
512572

513573
def setup(app):
514574
app.add_directive('argparse', ArgParseDirective)
515-
return {
516-
'parallel_read_safe': True,
517-
'version': __version__
518-
}
575+
return {'parallel_read_safe': True, 'version': __version__}

sphinxarg/markdown.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ def customWalker(node, space=''):
2020
>>> customWalker(content)
2121
document
2222
heading
23-
text Some big text block
23+
text Some big text block
2424
paragraph
25-
text with content
25+
text with content
2626
2727
Spaces are used to convey nesting
2828
"""
@@ -252,7 +252,11 @@ def listNode(node):
252252
if node.list_data['type'] == u'bullet':
253253
o = nodes.bullet_list(bullet=node.list_data['bullet_char'])
254254
else:
255-
o = nodes.enumerated_list(suffix=node.list_data['delimiter'], enumtype='arabic', start=node.list_data['start'])
255+
o = nodes.enumerated_list(
256+
suffix=node.list_data['delimiter'],
257+
enumtype='arabic',
258+
start=node.list_data['start'],
259+
)
256260
for n in MarkDown(node):
257261
o += n
258262
return o

0 commit comments

Comments
 (0)