Skip to content

Commit d3975fe

Browse files
authored
Add support for 3.10 (#13)
1 parent 01376c0 commit d3975fe

File tree

9 files changed

+171
-50
lines changed

9 files changed

+171
-50
lines changed

.github/workflows/check.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@ jobs:
2222
os:
2323
- Ubuntu
2424
py:
25+
- 3.10.0-rc.2
2526
- 3.9
2627
- 3.8
2728
- 3.7
2829
steps:
2930
- name: setup python for tox
3031
uses: actions/setup-python@v2
3132
with:
32-
python-version: 3.9
33+
python-version: 3.10.0-rc.2
3334
- name: install tox
3435
run: python -m pip install tox
3536
- uses: actions/checkout@v2
@@ -67,10 +68,10 @@ jobs:
6768
- pkg_check
6869
steps:
6970
- uses: actions/checkout@v2
70-
- name: setup Python 3.9
71+
- name: setup Python 3.10.0-rc.2
7172
uses: actions/setup-python@v2
7273
with:
73-
python-version: 3.9
74+
python-version: 3.10.0-rc.2
7475
- name: install tox
7576
run: python -m pip install tox
7677
- name: run check for ${{ matrix.tox_env }}
@@ -86,7 +87,7 @@ jobs:
8687
- name: setup python to build package
8788
uses: actions/setup-python@v2
8889
with:
89-
python-version: 3.9
90+
python-version: 3.10.0-rc.2
9091
- name: install build
9192
run: python -m pip install build
9293
- uses: actions/checkout@v2

.pre-commit-config.yaml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ repos:
1010
- id: end-of-file-fixer
1111
- id: trailing-whitespace
1212
- repo: https://github.com/asottile/pyupgrade
13-
rev: v2.28.0
13+
rev: v2.29.0
1414
hooks:
1515
- id: pyupgrade
1616
- repo: https://github.com/PyCQA/isort
@@ -27,7 +27,7 @@ repos:
2727
rev: v1.17.0
2828
hooks:
2929
- id: setup-cfg-fmt
30-
args: ["--max-py-version", "3.9"]
30+
args: ["--max-py-version", "3.10"]
3131
- repo: https://github.com/tox-dev/tox-ini-fmt
3232
rev: "0.5.1"
3333
hooks:
@@ -36,10 +36,12 @@ repos:
3636
rev: "3.9.2"
3737
hooks:
3838
- id: flake8
39-
additional_dependencies: [
40-
"flake8-bugbear == 21.4.3",
41-
"flake8-unused-arguments == 0.0.6",
42-
"flake8-comprehensions == 3.5.0",
43-
"flake8-spellcheck == 0.24.0",
44-
"flake8-pytest-style == 1.4.2",
45-
]
39+
additional_dependencies:
40+
- flake8-bugbear==21.9.2
41+
- flake8-comprehensions==3.6.1
42+
- flake8-pytest-style==1.5
43+
- flake8-spellcheck==0.24
44+
- flake8-unused-arguments==0.0.6
45+
- flake8-noqa==1.1.0
46+
- flake8-eradicate==1.1.0
47+
- pep8-naming==0.12.1

setup.cfg

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ classifiers =
2424
Programming Language :: Python :: 3.7
2525
Programming Language :: Python :: 3.8
2626
Programming Language :: Python :: 3.9
27+
Programming Language :: Python :: 3.10
2728
Programming Language :: Python :: Implementation :: CPython
2829
Topic :: Documentation
2930
Topic :: Documentation :: Sphinx
@@ -55,9 +56,13 @@ test =
5556
sphinx_argparse_cli = py.typed
5657

5758
[flake8]
59+
max-complexity = 22
5860
max-line-length = 120
59-
ignore = F401, H301, E203
61+
unused-arguments-ignore-abstract-functions = true
62+
noqa-require-code = true
6063
dictionaries = en_US,python,technical
64+
ignore =
65+
E203 # whitespace before :
6166

6267
[coverage:report]
6368
show_missing = True

src/sphinx_argparse_cli/_logic.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@
33
import os
44
import re
55
import sys
6-
from argparse import _ArgumentGroup # noqa
7-
from argparse import _SubParsersAction # noqa
8-
from argparse import SUPPRESS, Action, ArgumentParser, HelpFormatter
6+
from argparse import (
7+
SUPPRESS,
8+
Action,
9+
ArgumentParser,
10+
HelpFormatter,
11+
_ArgumentGroup,
12+
_SubParsersAction,
13+
)
914
from collections import defaultdict, namedtuple
1015
from typing import Iterator, cast
1116

@@ -89,17 +94,17 @@ def parser(self) -> ArgumentParser:
8994
return self._parser
9095

9196
def load_sub_parsers(self) -> Iterator[tuple[list[str], str, ArgumentParser]]:
92-
top_sub_parser = self.parser._subparsers # noqa
97+
top_sub_parser = self.parser._subparsers
9398
if not top_sub_parser:
9499
return
95100
parser_to_args: dict[int, list[str]] = defaultdict(list)
96101
str_to_parser: dict[str, ArgumentParser] = {}
97-
sub_parser = cast(_SubParsersAction, top_sub_parser._group_actions[0]) # noqa
98-
for key, parser in sub_parser._name_parser_map.items(): # noqa
102+
sub_parser = cast(_SubParsersAction, top_sub_parser._group_actions[0])
103+
for key, parser in sub_parser._name_parser_map.items():
99104
parser_to_args[id(parser)].append(key)
100105
str_to_parser[key] = parser
101106
done_parser: set[int] = set()
102-
for name, parser in sub_parser.choices.items(): # noqa
107+
for name, parser in sub_parser.choices.items():
103108
parser_id = id(parser)
104109
if parser_id in done_parser:
105110
continue
@@ -124,8 +129,8 @@ def run(self) -> list[Node]:
124129
home_section += desc_paragraph
125130
# construct groups excluding sub-parsers
126131
home_section += self._mk_usage(self.parser)
127-
for group in self.parser._action_groups: # noqa
128-
if not group._group_actions or group is self.parser._subparsers: # noqa
132+
for group in self.parser._action_groups:
133+
if not group._group_actions or group is self.parser._subparsers:
129134
continue
130135
home_section += self._mk_option_group(group, prefix=self.parser.prog.split("/")[-1])
131136
# construct sub-parser
@@ -147,7 +152,7 @@ def _mk_option_group(self, group: _ArgumentGroup, prefix: str) -> section:
147152
group_section += paragraph("", Text(group.description))
148153
self._register_ref(ref_id, title_text, group_section)
149154
opt_group = bullet_list()
150-
for action in group._group_actions: # noqa
155+
for action in group._group_actions:
151156
point = self._mk_option_line(action, prefix)
152157
opt_group += point
153158
group_section += opt_group
@@ -176,7 +181,7 @@ def _build_opt_grp_title(self, group: _ArgumentGroup, prefix: str, sub_title_pre
176181
title_text += group.title or ""
177182
return title_text
178183

179-
def _mk_option_line(self, action: Action, prefix: str) -> list_item: # noqa
184+
def _mk_option_line(self, action: Action, prefix: str) -> list_item:
180185
line = paragraph()
181186
as_key = action.dest
182187
if action.metavar:
@@ -259,7 +264,7 @@ def _mk_sub_command(self, aliases: list[str], help_msg: str, parser: ArgumentPar
259264
desc_paragraph = paragraph("", Text(command_desc))
260265
group_section += desc_paragraph
261266
group_section += self._mk_usage(parser)
262-
for group in parser._action_groups: # noqa
267+
for group in parser._action_groups:
263268
if not group._group_actions: # do not show empty groups
264269
continue
265270
group_section += self._mk_option_group(group, prefix=parser.prog)

tests/complex.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ argparse tester
77
{first,f,second,third} ...
88

99

10-
complex optional arguments
11-
==========================
10+
complex options
11+
===============
1212

1313
* **"-h"**, **"--help"** - show this help message and exit
1414

@@ -49,8 +49,8 @@ complex first positional arguments
4949
* **"pos_two"** - second positional argument (default: "1")
5050

5151

52-
complex first optional arguments
53-
--------------------------------
52+
complex first options
53+
---------------------
5454

5555
* **"-h"**, **"--help"** - show this help message and exit
5656

@@ -73,8 +73,8 @@ complex second positional arguments
7373
* **"pos_two"** - second positional argument (default: "green")
7474

7575

76-
complex second optional arguments
77-
---------------------------------
76+
complex second options
77+
----------------------
7878

7979
* **"-h"**, **"--help"** - show this help message and exit
8080

@@ -89,7 +89,7 @@ complex third
8989
complex third [-h]
9090

9191

92-
complex third optional arguments
93-
--------------------------------
92+
complex third options
93+
---------------------
9494

9595
* **"-h"**, **"--help"** - show this help message and exit

tests/complex_pre_310.txt

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
complex - CLI interface
2+
***********************
3+
4+
argparse tester
5+
6+
complex [-h] [--root] [--no-help] [--outdir out_dir] [--in-dir IN_DIR] [--foo | --bar]
7+
{first,f,second,third} ...
8+
9+
10+
complex optional arguments
11+
==========================
12+
13+
* **"-h"**, **"--help"** - show this help message and exit
14+
15+
* **"--root"** - root flag (default: "False")
16+
17+
* **"--no-help"** (default: "False")
18+
19+
* **"--outdir"** "OUT_DIR", **"-o"** "OUT_DIR" - output directory
20+
(default: "None")
21+
22+
* **"--in-dir"** "IN_DIR", **"-i"** "IN_DIR" - input directory
23+
(default: "None")
24+
25+
26+
complex Exclusive
27+
=================
28+
29+
this is an exclusive group
30+
31+
* **"--foo"** - foo (default: "False")
32+
33+
* **"--bar"** - bar (default: "False")
34+
35+
36+
complex first (f)
37+
=================
38+
39+
a-first-desc
40+
41+
complex first [-h] [--flag] [--root] one pos_two
42+
43+
44+
complex first positional arguments
45+
----------------------------------
46+
47+
* **"one"** - first positional argument (default: "None")
48+
49+
* **"pos_two"** - second positional argument (default: "1")
50+
51+
52+
complex first optional arguments
53+
--------------------------------
54+
55+
* **"-h"**, **"--help"** - show this help message and exit
56+
57+
* **"--flag"** - a parser first flag (default: "False")
58+
59+
* **"--root"** - root flag (default: "False")
60+
61+
62+
complex second
63+
==============
64+
65+
complex second [-h] [--flag] [--root] one pos_two
66+
67+
68+
complex second positional arguments
69+
-----------------------------------
70+
71+
* **"one"** - first positional argument (default: "None")
72+
73+
* **"pos_two"** - second positional argument (default: "green")
74+
75+
76+
complex second optional arguments
77+
---------------------------------
78+
79+
* **"-h"**, **"--help"** - show this help message and exit
80+
81+
* **"--flag"** - a parser second flag (default: "False")
82+
83+
* **"--root"** - root flag (default: "False")
84+
85+
86+
complex third
87+
=============
88+
89+
complex third [-h]
90+
91+
92+
complex third optional arguments
93+
--------------------------------
94+
95+
* **"-h"**, **"--help"** - show this help message and exit

0 commit comments

Comments
 (0)