See attached the patch for current master. Alternatively use merge request https://salsa.debian.org/python-team/modules/sphinx-argparse/merge_requests/1
From fddc8fda48ef44398463ba36e518c8a3b80e71c1 Mon Sep 17 00:00:00 2001 From: Hanno Stock <opensou...@hanno-stock.de> Date: Mon, 25 Feb 2019 17:08:02 +0100 Subject: [PATCH] Fix aliased subcommands (patch, closes: #922880)
--- .../0001-Fix-aliased-subcommands-Python3.patch | 136 +++++++++++++++++++++ .../{0001-fix-tests.patch => 0002-fix-tests.patch} | 34 +++++- ...-of-Markdown-options-in-docs-markdown.rs.patch} | 0 debian/patches/series | 5 +- 4 files changed, 167 insertions(+), 8 deletions(-) create mode 100644 debian/patches/0001-Fix-aliased-subcommands-Python3.patch rename debian/patches/{0001-fix-tests.patch => 0002-fix-tests.patch} (50%) rename debian/patches/{0002-Remove-usage-of-Markdown-options-in-docs-markdown.rs.patch => 0003-Remove-usage-of-Markdown-options-in-docs-markdown.rs.patch} (100%) diff --git a/debian/patches/0001-Fix-aliased-subcommands-Python3.patch b/debian/patches/0001-Fix-aliased-subcommands-Python3.patch new file mode 100644 index 0000000..861c991 --- /dev/null +++ b/debian/patches/0001-Fix-aliased-subcommands-Python3.patch @@ -0,0 +1,136 @@ +From: Hanno Stock <opensou...@hanno-stock.de> +Date: Mon, 25 Feb 2019 16:58:48 +0100 +Subject: Fix aliased subcommands (Python3) + +parser_navigate throws an exception when trying to navigate to a +subcommand with an alias. + +Forwarded: https://github.com/ribozz/sphinx-argparse/pull/109 +Bug: https://github.com/ribozz/sphinx-argparse/issues/108 +Bug-Debian: https://bugs.debian.org/922880 +Applied-Upstream: 0.2.6 +--- + sphinxarg/parser.py | 6 +++- + test/test_parser.py | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++ + 2 files changed, 84 insertions(+), 1 deletion(-) + +diff --git a/sphinxarg/parser.py b/sphinxarg/parser.py +index aa3ef09..b86da3d 100644 +--- a/sphinxarg/parser.py ++++ b/sphinxarg/parser.py +@@ -20,7 +20,9 @@ def parser_navigate(parser_result, path, current_path=None): + ' '.join(current_path)) + next_hop = path.pop(0) + for child in parser_result['children']: +- if child['name'] == next_hop: ++ # identifer is only used for aliased subcommands ++ identifier = child['identifier'] if 'identifier' in child else child['name'] ++ if identifier == next_hop: + current_path.append(next_hop) + return parser_navigate(child, path, current_path) + raise NavigationException( +@@ -88,6 +90,8 @@ def parse_parser(parser, data=None, **kwargs): + 'usage': subaction.format_usage().strip(), + 'bare_usage': _format_usage_without_prefix(subaction), + } ++ if subalias: ++ subdata['identifier'] = name + parse_parser(subaction, subdata, **kwargs) + data.setdefault('children', []).append(subdata) + +diff --git a/test/test_parser.py b/test/test_parser.py +index 075888b..26a7481 100755 +--- a/test/test_parser.py ++++ b/test/test_parser.py +@@ -1,5 +1,6 @@ + import argparse + from sphinxarg.parser import parse_parser, parser_navigate ++import six + + + def test_parse_options(): +@@ -187,6 +188,84 @@ def test_parse_nested(): + ] + + ++if six.PY3: ++ def test_parse_nested_with_alias(): ++ parser = argparse.ArgumentParser() ++ parser.add_argument('foo', default=False, help='foo help') ++ parser.add_argument('bar', default=False) ++ ++ subparsers = parser.add_subparsers() ++ ++ subparser = subparsers.add_parser('install', aliases=['i'], help='install help') ++ subparser.add_argument('ref', type=str, help='foo1 help') ++ subparser.add_argument('--upgrade', action='store_true', default=False, help='foo2 help') ++ ++ data = parse_parser(parser) ++ ++ assert data['action_groups'][0]['options'] == [ ++ { ++ 'name': ['foo'], ++ 'help': 'foo help', ++ 'default': False ++ }, { ++ 'name': ['bar'], ++ 'help': '', ++ 'default': False ++ } ++ ] ++ ++ assert data['children'] == [ ++ { ++ 'name': 'install (i)', ++ 'identifier': 'install', ++ 'help': 'install help', ++ 'usage': 'usage: py.test install [-h] [--upgrade] ref', ++ 'bare_usage': 'py.test install [-h] [--upgrade] ref', ++ 'action_groups': [ ++ { ++ 'title': 'Positional Arguments', ++ 'description': None, ++ 'options': [ ++ { ++ 'name': ['ref'], ++ 'help': 'foo1 help', ++ 'default': None ++ } ++ ] ++ }, ++ { ++ 'description': None, ++ 'title': 'Named Arguments', ++ 'options': [ ++ { ++ 'name': ['--upgrade'], ++ 'default': False, ++ 'help': 'foo2 help' ++ } ++ ] ++ } ++ ] ++ } ++ ] ++ ++ def test_aliased_traversal(): ++ parser = argparse.ArgumentParser() ++ ++ subparsers1 = parser.add_subparsers() ++ subparsers1.add_parser('level1', aliases=['l1']) ++ ++ data = parse_parser(parser) ++ ++ data2 = parser_navigate(data, 'level1') ++ ++ assert(data2 == { ++ 'bare_usage': 'py.test level1 [-h]', ++ 'help': '', ++ 'usage': 'usage: py.test level1 [-h]', ++ 'name': 'level1 (l1)', ++ 'identifier': 'level1'}) ++ ++ + def test_parse_nested_traversal(): + parser = argparse.ArgumentParser() + diff --git a/debian/patches/0001-fix-tests.patch b/debian/patches/0002-fix-tests.patch similarity index 50% rename from debian/patches/0001-fix-tests.patch rename to debian/patches/0002-fix-tests.patch index 58bc042..0045476 100644 --- a/debian/patches/0001-fix-tests.patch +++ b/debian/patches/0002-fix-tests.patch @@ -1,4 +1,3 @@ -From 680b7314c75db8aec6fc9b79da6c0b3c8f968459 Mon Sep 17 00:00:00 2001 From: Daniel Stender <deb...@danielstender.com> Date: Wed, 20 Jan 2016 21:24:54 +0100 Subject: fix-tests @@ -6,14 +5,14 @@ Subject: fix-tests fix tests for running py.test via Python interpreter Forwarded: not-needed --- - test/test_parser.py | 8 ++++---- - 1 file changed, 4 insertions(+), 4 deletions(-) + test/test_parser.py | 16 ++++++++-------- + 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/test_parser.py b/test/test_parser.py -index 075888b..47eb05b 100755 +index 26a7481..78633f1 100755 --- a/test/test_parser.py +++ b/test/test_parser.py -@@ -157,8 +157,8 @@ def test_parse_nested(): +@@ -158,8 +158,8 @@ def test_parse_nested(): { 'name': 'install', 'help': 'install help', @@ -24,7 +23,30 @@ index 075888b..47eb05b 100755 'action_groups': [ { 'title': 'Positional Arguments', -@@ -223,8 +223,8 @@ def test_parse_nested_traversal(): +@@ -219,8 +219,8 @@ if six.PY3: + '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: pytest.py install [-h] [--upgrade] ref', ++ 'bare_usage': 'pytest.py install [-h] [--upgrade] ref', + 'action_groups': [ + { + 'title': 'Positional Arguments', +@@ -259,9 +259,9 @@ if six.PY3: + data2 = parser_navigate(data, 'level1') + + assert(data2 == { +- 'bare_usage': 'py.test level1 [-h]', ++ 'bare_usage': 'pytest.py level1 [-h]', + 'help': '', +- 'usage': 'usage: py.test level1 [-h]', ++ 'usage': 'usage: pytest.py level1 [-h]', + 'name': 'level1 (l1)', + 'identifier': 'level1'}) + +@@ -302,8 +302,8 @@ def test_parse_nested_traversal(): { 'name': 'level3', 'help': '', diff --git a/debian/patches/0002-Remove-usage-of-Markdown-options-in-docs-markdown.rs.patch b/debian/patches/0003-Remove-usage-of-Markdown-options-in-docs-markdown.rs.patch similarity index 100% rename from debian/patches/0002-Remove-usage-of-Markdown-options-in-docs-markdown.rs.patch rename to debian/patches/0003-Remove-usage-of-Markdown-options-in-docs-markdown.rs.patch diff --git a/debian/patches/series b/debian/patches/series index dfcca93..4c4bb03 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -1,2 +1,3 @@ -0001-fix-tests.patch -0002-Remove-usage-of-Markdown-options-in-docs-markdown.rs.patch +0001-Fix-aliased-subcommands-Python3.patch +0002-fix-tests.patch +0003-Remove-usage-of-Markdown-options-in-docs-markdown.rs.patch -- 2.11.0
signature.asc
Description: OpenPGP digital signature