14
0

- Resolve the mess with different

patches. different_pytest_name.patch has been
  replaced by prog-in-description.patch from
  gh#alex-rudakov/sphinx-argparse#121

OBS-URL: https://build.opensuse.org/package/show/devel:languages:python/python-sphinx-argparse?expand=0&rev=3
This commit is contained in:
2020-06-12 10:26:13 +00:00
committed by Git OBS Bridge
parent 09bedc0e1e
commit 71eaa46927
4 changed files with 95 additions and 55 deletions

View File

@@ -1,51 +0,0 @@
--- a/test/test_parser.py
+++ b/test/test_parser.py
@@ -1,4 +1,8 @@
import argparse
+import os
+import sys
+print("sys.path = {}".format(sys.path))
+
from sphinxarg.parser import parse_parser, parser_navigate
@@ -129,6 +133,8 @@ def test_parse_description():
def test_parse_nested():
+ pytest_name = os.environ['PYTEST_NAME'] if 'PYTEST_NAME' in os.environ \
+ else 'py.test'
parser = argparse.ArgumentParser()
parser.add_argument('foo', default=False, help='foo help')
parser.add_argument('bar', default=False)
@@ -157,8 +163,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: {} install [-h] [--upgrade] ref'.format(pytest_name),
+ 'bare_usage': '{} install [-h] [--upgrade] ref'.format(pytest_name),
'action_groups': [
{
'title': 'Positional Arguments',
@@ -188,6 +194,8 @@ def test_parse_nested():
def test_parse_nested_traversal():
+ pytest_name = os.environ['PYTEST_NAME'] if 'PYTEST_NAME' in os.environ \
+ else 'py.test'
parser = argparse.ArgumentParser()
subparsers1 = parser.add_subparsers()
@@ -223,8 +231,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: {} level1 level2 level3 [-h] foo bar'.format(pytest_name),
+ 'bare_usage': '{} level1 level2 level3 [-h] foo bar'.format(pytest_name),
'action_groups': [
{
'title': 'Positional Arguments',

83
prog-in-description.patch Normal file
View File

@@ -0,0 +1,83 @@
--- a/sphinxarg/parser.py
+++ b/sphinxarg/parser.py
@@ -10,7 +10,7 @@ def parser_navigate(parser_result, path,
if isinstance(path, str):
if path == '':
return parser_result
- path = re.split('\s+', path)
+ path = re.split(r'\s+', path)
current_path = current_path or []
if len(path) == 0:
return parser_result
@@ -35,7 +35,7 @@ def _try_add_parser_attribute(data, pars
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):
--- a/test/test_parser.py
+++ b/test/test_parser.py
@@ -129,7 +129,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)
@@ -157,8 +157,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',
@@ -188,7 +188,7 @@ def test_parse_nested():
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')
@@ -223,8 +223,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',
@@ -265,6 +265,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.

View File

@@ -1,3 +1,11 @@
-------------------------------------------------------------------
Fri Jun 12 10:25:03 UTC 2020 - Matej Cepl <mcepl@suse.com>
- Resolve the mess with different
patches. different_pytest_name.patch has been
replaced by prog-in-description.patch from
gh#alex-rudakov/sphinx-argparse#121
------------------------------------------------------------------- -------------------------------------------------------------------
Fri Dec 13 12:19:37 CET 2019 - Matej Cepl <mcepl@suse.com> Fri Dec 13 12:19:37 CET 2019 - Matej Cepl <mcepl@suse.com>

View File

@@ -1,7 +1,7 @@
# #
# spec file for package python-sphinx-argparse # spec file for package python-sphinx-argparse
# #
# Copyright (c) 2019 SUSE LLC # Copyright (c) 2020 SUSE LLC
# #
# All modifications and additions to the file contributed by third parties # All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed # remain the property of their copyright owners, unless otherwise agreed
@@ -27,9 +27,9 @@ Group: Development/Languages/Python
URL: https://github.com/ribozz/sphinx-argparse URL: https://github.com/ribozz/sphinx-argparse
Source0: https://files.pythonhosted.org/packages/source/s/sphinx-argparse/sphinx-argparse-%{version}.tar.gz Source0: https://files.pythonhosted.org/packages/source/s/sphinx-argparse/sphinx-argparse-%{version}.tar.gz
Source1: https://raw.githubusercontent.com/alex-rudakov/sphinx-argparse/%{version}/LICENSE#/LICENSE-sphinx-argparse Source1: https://raw.githubusercontent.com/alex-rudakov/sphinx-argparse/%{version}/LICENSE#/LICENSE-sphinx-argparse
# PATCH-FIX-UPSTREAM different_pytest_name.patch gh#alex-rudakov/sphinx-argparse#121 mcepl@suse.com # PATCH-FIX-UPSTREAM prog-in-description.patch gh#alex-rudakov/sphinx-argparse#113 mcepl@suse.com
# Use environmental variable PYTEST_NAME for different names of the pytest executable # Substitute %(prog)s in description and epilog
Patch0: different_pytest_name.patch Patch0: prog-in-description.patch
BuildRequires: %{python_module CommonMark} BuildRequires: %{python_module CommonMark}
BuildRequires: %{python_module Sphinx >= 1.2.0} BuildRequires: %{python_module Sphinx >= 1.2.0}
BuildRequires: %{python_module pytest} BuildRequires: %{python_module pytest}