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

fix #93: settings were not passed to renderList #133

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pip-log.txt
# Unit test / coverage reports
.coverage
.tox
.pytest_cache
nosetests.xml

# Translations
Expand Down
2 changes: 1 addition & 1 deletion sphinxarg/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def print_action_groups(data, nested_content, markDownHelp=False, settings=None)
for k, v in map_nested_definitions(subContent).items():
definitions[k] = v
# Render appropriately
for element in renderList(desc, markDownHelp):
for element in renderList(desc, markDownHelp, settings=settings):
section += element

localDefinitions = definitions
Expand Down
11 changes: 9 additions & 2 deletions sphinxarg/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def _try_add_parser_attribute(data, parser, attribname):
if not isinstance(attribval, str):
return
if len(attribval) > 0:
data[attribname] = attribval
data[attribname] = attribval % {'prog': data['prog']}


def _format_usage_without_prefix(parser):
Expand All @@ -59,6 +59,9 @@ def parse_parser(parser, data=None, **kwargs):
'bare_usage': _format_usage_without_prefix(parser),
'prog': parser.prog,
}
if 'prog' not in data:
data['prog'] = parser.prog

_try_add_parser_attribute(data, parser, 'description')
_try_add_parser_attribute(data, parser, 'epilog')
for action in parser._get_positional_actions():
Expand Down Expand Up @@ -164,8 +167,12 @@ def parse_parser(parser, data=None, **kwargs):
if action_group.title == 'positional arguments':
action_group.title = 'Positional Arguments'

description = action_group.description
if description is not None:
description = description % {'prog': data.get('prog', '') }

group = {'title': action_group.title,
'description': action_group.description,
'description': description,
'options': options_list}

action_groups.append(group)
Expand Down
38 changes: 26 additions & 12 deletions test/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def test_parse_description():


def test_parse_nested():
parser = argparse.ArgumentParser()
parser = argparse.ArgumentParser(prog='test_parse_nested')
parser.add_argument('foo', default=False, help='foo help')
parser.add_argument('bar', default=False)

Expand Down Expand Up @@ -158,8 +158,8 @@ def test_parse_nested():
{
'name': 'install',
'help': 'install help',
'usage': 'usage: py.test install [-h] [--upgrade] ref',
'bare_usage': 'py.test install [-h] [--upgrade] ref',
'usage': 'usage: test_parse_nested install [-h] [--upgrade] ref',
'bare_usage': 'test_parse_nested install [-h] [--upgrade] ref',
'action_groups': [
{
'title': 'Positional Arguments',
Expand Down Expand Up @@ -190,7 +190,7 @@ def test_parse_nested():

if six.PY3:
def test_parse_nested_with_alias():
parser = argparse.ArgumentParser()
parser = argparse.ArgumentParser(prog='test_parse_nested_with_alias')
parser.add_argument('foo', default=False, help='foo help')
parser.add_argument('bar', default=False)

Expand Down Expand Up @@ -219,8 +219,8 @@ def test_parse_nested_with_alias():
'name': 'install (i)',
'identifier': 'install',
'help': 'install help',
'usage': 'usage: py.test install [-h] [--upgrade] ref',
'bare_usage': 'py.test install [-h] [--upgrade] ref',
'usage': 'usage: test_parse_nested_with_alias install [-h] [--upgrade] ref',
'bare_usage': 'test_parse_nested_with_alias install [-h] [--upgrade] ref',
'action_groups': [
{
'title': 'Positional Arguments',
Expand Down Expand Up @@ -249,7 +249,7 @@ def test_parse_nested_with_alias():
]

def test_aliased_traversal():
parser = argparse.ArgumentParser()
parser = argparse.ArgumentParser(prog='test_aliased_traversal')

subparsers1 = parser.add_subparsers()
subparsers1.add_parser('level1', aliases=['l1'])
Expand All @@ -259,15 +259,15 @@ def test_aliased_traversal():
data2 = parser_navigate(data, 'level1')

assert(data2 == {
'bare_usage': 'py.test level1 [-h]',
'bare_usage': 'test_aliased_traversal level1 [-h]',
'help': '',
'usage': 'usage: py.test level1 [-h]',
'usage': 'usage: test_aliased_traversal level1 [-h]',
'name': 'level1 (l1)',
'identifier': 'level1'})


def test_parse_nested_traversal():
parser = argparse.ArgumentParser()
parser = argparse.ArgumentParser(prog='test_parse_nested_traversal')

subparsers1 = parser.add_subparsers()
subparser1 = subparsers1.add_parser('level1')
Expand Down Expand Up @@ -302,8 +302,8 @@ def test_parse_nested_traversal():
{
'name': 'level3',
'help': '',
'usage': 'usage: py.test level1 level2 level3 [-h] foo bar',
'bare_usage': 'py.test level1 level2 level3 [-h] foo bar',
'usage': 'usage: test_parse_nested_traversal level1 level2 level3 [-h] foo bar',
'bare_usage': 'test_parse_nested_traversal level1 level2 level3 [-h] foo bar',
'action_groups': [
{
'title': 'Positional Arguments',
Expand Down Expand Up @@ -344,6 +344,20 @@ def test_fill_in_default_prog():
]


def test_fill_in_description_epilog():
"""
Ensure that %(prog)s gets filled in inside description and epilog.
"""
parser = argparse.ArgumentParser(
prog='test_fill_in_description',
description='Welcome to %(prog)s',
epilog='%(prog)s salutes you')
data = parse_parser(parser)

assert data['description'] == 'Welcome to test_fill_in_description'
assert data['epilog'] == 'test_fill_in_description salutes you'


def test_string_quoting():
"""
If an optional argument has a string type and a default, then the default should be in quotes.
Expand Down