...
 
Commits (4)
sphinx-argparse (0.1.15-4) UNRELEASED; urgency=medium
* Team upload.
* Convert from git-dpm to gbp and patches unapplied format.
(taken from Dmitry Shachnev)
* Fix aliased subcommands for Python3 (closes: #922880)
* Updated VCS and Maintainer/Uploader to match unstable version
-- Hanno Stock <opensource@hanno-stock.de> Tue, 26 Feb 2019 15:38:09 +0100
sphinx-argparse (0.1.15-3) unstable; urgency=medium
* Orphan package:
......
Source: sphinx-argparse
Section: python
Priority: optional
Maintainer: Debian QA Group <packages@qa.debian.org>
Maintainer: Debian Python Modules Team <python-modules-team@lists.alioth.debian.org>
Uploaders: ChangZhuo Chen (陳昌倬) <czchen@debian.org>
Build-Depends: debhelper (>= 9),
dh-python,
python-all (>= 2.7.3-5~),
......@@ -16,8 +17,8 @@ Build-Depends: debhelper (>= 9),
python3-pytest
Standards-Version: 3.9.8
Homepage: https://github.com/ribozz/sphinx-argparse
Vcs-Git: https://anonscm.debian.org/git/python-modules/packages/sphinx-argparse.git
Vcs-Browser: https://anonscm.debian.org/cgit/python-modules/packages/sphinx-argparse.git
Vcs-Git: https://salsa.debian.org/python-team/modules/sphinx-argparse.git
Vcs-Browser: https://salsa.debian.org/python-team/modules/sphinx-argparse
Package: python-sphinx-argparse
Architecture: all
......
[DEFAULT]
debian-branch=debian/stretch
From 8a6a275c5a0a23fb466d6fa53da968e9096a8676 Mon Sep 17 00:00:00 2001
From: Daniel Stender <debian@danielstender.com>
Date: Wed, 20 Jan 2016 21:24:54 +0100
Subject: fix-tests
......
From: Hanno Stock <hanno.stock@indurad.com>
Date: Mon, 25 Feb 2019 12:06:20 +0100
Subject: Fix aliased subcommands (Python3)
When subcommands have aliases defined, the :path: parameter
fails.
Bug: https://github.com/ribozz/sphinx-argparse/pull/109
Bug-Debian: https://bugs.debian.org/922880
Applied-Upstream: 0.2.6
---
sphinxarg/parser.py | 6 ++++-
test/test_parser.py | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 74 insertions(+), 1 deletion(-)
diff --git a/sphinxarg/parser.py b/sphinxarg/parser.py
index 7bdbfa6..c339e29 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(
@@ -90,6 +92,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)
continue
diff --git a/test/test_parser.py b/test/test_parser.py
index 43852a2..ab104aa 100755
--- a/test/test_parser.py
+++ b/test/test_parser.py
@@ -2,6 +2,7 @@ import argparse
import json
from pprint import pprint
from sphinxarg.parser import parse_parser, parser_navigate
+import six
def test_parse_options():
@@ -180,6 +181,74 @@ 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['args'] == [
+ {
+ 'name': 'foo',
+ 'help': 'foo help',
+ 'metavar': None
+ }, {
+ 'name': 'bar',
+ 'help': '',
+ 'metavar': None
+ },
+ ]
+
+ assert data['children'] == [
+ {
+ 'name': 'install (i)',
+ 'identifier': 'install',
+ 'help': 'install help',
+ 'usage': 'usage: pytest.py install [-h] [--upgrade] ref',
+ 'bare_usage': 'pytest.py install [-h] [--upgrade] ref',
+ 'args': [
+ {
+ 'name': 'ref',
+ 'help': 'foo1 help',
+ 'metavar': None
+ },
+ ],
+ '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': 'pytest.py level1 [-h]',
+ 'help': '',
+ 'usage': 'usage: pytest.py level1 [-h]',
+ 'name': 'level1 (l1)',
+ 'identifier': 'level1'})
+
+
def test_parse_nested_traversal():
parser = argparse.ArgumentParser()
0001-fix-tests.patch
0002-Fix-aliased-subcommands-Python3.patch
......@@ -160,8 +160,8 @@ def test_parse_nested():
{
'name': 'install',
'help': 'install help',
'usage': 'usage: pytest.py install [-h] [--upgrade] ref',
'bare_usage': 'pytest.py install [-h] [--upgrade] ref',
'usage': 'usage: py.test install [-h] [--upgrade] ref',
'bare_usage': 'py.test install [-h] [--upgrade] ref',
'args': [
{
'name': 'ref',
......@@ -216,8 +216,8 @@ def test_parse_nested_traversal():
{
'name': 'level3',
'help': '',
'usage': 'usage: pytest.py level1 level2 level3 [-h] foo bar',
'bare_usage': 'pytest.py level1 level2 level3 [-h] foo bar',
'usage': 'usage: py.test level1 level2 level3 [-h] foo bar',
'bare_usage': 'py.test level1 level2 level3 [-h] foo bar',
'args': [
{
'name': 'foo',
......@@ -233,4 +233,4 @@ def test_parse_nested_traversal():
}
]
assert data == parser_navigate(data, '')
assert data == parser_navigate(data, '')
\ No newline at end of file