Skip to content

Commit b9309e9

Browse files
Drop support for Python < 3.9, modernize code (#68)
* Drop support for Python < 3.9. * Mark as stable. * Adjust to Python 3.9+ syntax. * Fix one more type. Co-authored-by: Maxwell G <[email protected]> --------- Co-authored-by: Maxwell G <[email protected]>
1 parent e37b939 commit b9309e9

File tree

13 files changed

+176
-254
lines changed

13 files changed

+176
-254
lines changed

.github/workflows/nox.yml

Lines changed: 2 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ jobs:
2929
matrix:
3030
include:
3131
- session: test
32-
python-versions: "3.8, 3.9, 3.10, 3.11, 3.12, 3.13"
33-
other-args: "-p 3.8 3.9 3.10 3.11 3.12 3.13"
32+
python-versions: "3.9, 3.10, 3.11, 3.12, 3.13"
33+
other-args: ""
3434
codecov: true
3535
packages: ""
3636

@@ -79,76 +79,3 @@ jobs:
7979
working-directory: antsibull-docs-parser
8080
env:
8181
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
82-
nox-test-37:
83-
# python3.7 is not available on ubuntu-latest
84-
runs-on: ubuntu-22.04
85-
name: "Run nox test session (Python 3.7)"
86-
defaults:
87-
run:
88-
working-directory: antsibull-docs-parser
89-
steps:
90-
- name: Check out antsibull-docs-parser
91-
uses: actions/checkout@v4
92-
with:
93-
path: antsibull-docs-parser
94-
persist-credentials: false
95-
- name: Setup nox
96-
uses: wntrblm/[email protected]
97-
with:
98-
python-versions: "3.7"
99-
- name: Set up nox environments
100-
run: |
101-
nox -v -e "test" -p 3.7 --install-only
102-
nox -v -e coverage --install-only
103-
- name: "Run nox -e test -p 3.7"
104-
run: |
105-
nox -v -e "test" -p 3.7 --reuse-existing-virtualenvs --no-install
106-
- name: Report coverage
107-
run: |
108-
nox -v -e coverage --reuse-existing-virtualenvs --no-install
109-
- name: Upload coverage
110-
uses: codecov/codecov-action@v5
111-
with:
112-
name: "test"
113-
working-directory: antsibull-docs-parser
114-
env:
115-
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
116-
nox-test-36:
117-
# python3.6 is not available on ubuntu-latest
118-
runs-on: ubuntu-20.04
119-
name: "Run nox test session (Python 3.6)"
120-
defaults:
121-
run:
122-
working-directory: antsibull-docs-parser
123-
steps:
124-
- name: Check out antsibull-docs-parser
125-
uses: actions/checkout@v4
126-
with:
127-
path: antsibull-docs-parser
128-
persist-credentials: false
129-
- name: Setup nox
130-
uses: wntrblm/[email protected] # DO NOT UPDATE THIS! Newer versions do not work with Python 3.6
131-
with:
132-
python-versions: "3.6"
133-
# https://github.com/ansible-community/antsibull-docs-parser/issues/25
134-
# Newer virtualenv versions seem to cause failures with Python 3.6
135-
- name: Setup nox - downgrade virtualenv
136-
run: |
137-
pipx inject --force nox 'virtualenv<20.22.0'
138-
- name: Set up nox environments
139-
run: |
140-
nox -v -e test -p 3.6 --install-only
141-
nox -v -e coverage --install-only
142-
- name: Run unit tests
143-
run: |
144-
nox -v -e test -p 3.6 --reuse-existing-virtualenvs --no-install
145-
- name: Report coverage
146-
run: |
147-
nox -v -e coverage --reuse-existing-virtualenvs --no-install
148-
- name: Upload coverage
149-
uses: codecov/codecov-action@v5
150-
with:
151-
name: nox-test-36
152-
working-directory: antsibull-docs-parser
153-
env:
154-
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

changelogs/fragments/68-python.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
removed_features:
2+
- "antsibull-docs-parser no longer supports Python 3.6, 3.7, and 3.8. Python 3.9+ is now required (https://github.com/ansible-community/antsibull-docs-parser/pull/68)."

noxfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def install(session: nox.Session, *args, editable=False, **kwargs):
3333
session.install(*args, "-U", **kwargs)
3434

3535

36-
@nox.session(python=["3.6", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"])
36+
@nox.session(python=["3.9", "3.10", "3.11", "3.12", "3.13"])
3737
def test(session: nox.Session):
3838
install(session, ".[test, coverage]", editable=True)
3939
covfile = Path(session.create_tmp(), ".coverage")

pyproject.toml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ name = "antsibull-docs-parser"
1111
dynamic = ["version"]
1212
description = "Python library for processing Ansible documentation markup"
1313
readme = "README.md"
14-
requires-python = ">=3.6.1"
14+
requires-python = ">=3.9"
1515
license = "GPL-3.0-or-later AND BSD-2-Clause"
1616
license-files.globs = ["LICENSES/*.txt"]
1717
authors = [
@@ -22,13 +22,10 @@ maintainers = [
2222
{ name = "Maxwell G", email = "[email protected]" },
2323
]
2424
classifiers = [
25-
"Development Status :: 3 - Alpha",
25+
"Development Status :: 5 - Production/Stable",
2626
"Framework :: Ansible",
2727
"Intended Audience :: Developers",
2828
"Programming Language :: Python :: 3",
29-
"Programming Language :: Python :: 3.6",
30-
"Programming Language :: Python :: 3.7",
31-
"Programming Language :: Python :: 3.8",
3229
"Programming Language :: Python :: 3.9",
3330
"Programming Language :: Python :: 3.10",
3431
"Programming Language :: Python :: 3.11",

src/antsibull_docs_parser/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
Library for processing Ansible documentation markup.
88
"""
99

10+
from __future__ import annotations
11+
1012
__version__ = "1.1.1.post0"
1113

1214
__all__ = ("__version__",)

src/antsibull_docs_parser/_parser_impl.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
Internal parsing code.
88
"""
99

10+
from __future__ import annotations
11+
1012
import re
11-
import typing as t
1213

1314
_ESCAPE_OR_COMMA = re.compile(r"\\(.)| *(,) *")
1415
_ESCAPE_OR_CLOSING = re.compile(r"\\(.)|([)])")
@@ -19,12 +20,12 @@ def parse_parameters_escaped(
1920
index: int,
2021
parameter_count: int,
2122
strict: bool,
22-
) -> t.Tuple[t.List[str], int, t.Optional[str]]:
23-
result: t.List[str] = []
23+
) -> tuple[list[str], int, str | None]:
24+
result: list[str] = []
2425
parameters_left = parameter_count
2526
while parameters_left > 1:
2627
parameters_left -= 1
27-
value: t.List[str] = []
28+
value: list[str] = []
2829
while True:
2930
match = _ESCAPE_OR_COMMA.search(text, pos=index)
3031
if not match:
@@ -77,8 +78,8 @@ def parse_parameters_unescaped(
7778
index: int,
7879
parameter_count: int,
7980
strict: bool, # pylint: disable=unused-argument
80-
) -> t.Tuple[t.List[str], int, t.Optional[str]]:
81-
result: t.List[str] = []
81+
) -> tuple[list[str], int, str | None]:
82+
result: list[str] = []
8283
first = True
8384
parameters_left = parameter_count
8485
while parameters_left > 1:

src/antsibull_docs_parser/ansible_doc_text.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
Ansible-doc text serialization.
88
"""
99

10+
from __future__ import annotations
11+
1012
import typing as t
1113

1214
from . import dom
@@ -17,7 +19,7 @@
1719
class AnsibleDocTextFormatter(Formatter):
1820
@staticmethod
1921
def _format_option_like(
20-
part: t.Union[dom.OptionNamePart, dom.ReturnValuePart],
22+
part: dom.OptionNamePart | dom.ReturnValuePart,
2123
) -> str:
2224
value = part.value
2325
if value is None:
@@ -54,7 +56,7 @@ def format_italic(self, part: dom.ItalicPart) -> str:
5456
def format_link(self, part: dom.LinkPart) -> str:
5557
return f"{part.text} <{part.url}>"
5658

57-
def format_module(self, part: dom.ModulePart, url: t.Optional[str]) -> str:
59+
def format_module(self, part: dom.ModulePart, url: str | None) -> str:
5860
return f"[{part.fqcn}]"
5961

6062
def format_rst_ref(self, part: dom.RSTRefPart) -> str:
@@ -69,18 +71,16 @@ def format_text(self, part: dom.TextPart) -> str:
6971
def format_env_variable(self, part: dom.EnvVariablePart) -> str:
7072
return f"`{part.name}'"
7173

72-
def format_option_name(self, part: dom.OptionNamePart, url: t.Optional[str]) -> str:
74+
def format_option_name(self, part: dom.OptionNamePart, url: str | None) -> str:
7375
return self._format_option_like(part)
7476

7577
def format_option_value(self, part: dom.OptionValuePart) -> str:
7678
return f"`{part.value}'"
7779

78-
def format_plugin(self, part: dom.PluginPart, url: t.Optional[str]) -> str:
80+
def format_plugin(self, part: dom.PluginPart, url: str | None) -> str:
7981
return f"[{part.plugin.fqcn}]"
8082

81-
def format_return_value(
82-
self, part: dom.ReturnValuePart, url: t.Optional[str]
83-
) -> str:
83+
def format_return_value(self, part: dom.ReturnValuePart, url: str | None) -> str:
8484
return self._format_option_like(part)
8585

8686

@@ -90,12 +90,12 @@ def format_return_value(
9090
def to_ansible_doc_text(
9191
paragraphs: t.Sequence[dom.Paragraph],
9292
formatter: Formatter = DEFAULT_ANSIBLE_DOC_FORMATTER,
93-
link_provider: t.Optional[LinkProvider] = None,
93+
link_provider: LinkProvider | None = None,
9494
par_start: str = "",
9595
par_end: str = "",
9696
par_sep: str = "\n\n",
9797
par_empty: str = "",
98-
current_plugin: t.Optional[dom.PluginIdentifier] = None,
98+
current_plugin: dom.PluginIdentifier | None = None,
9999
) -> str:
100100
return _format_paragraphs(
101101
paragraphs,

0 commit comments

Comments
 (0)