Skip to content

Commit b981399

Browse files
authored
Bump deps and migrate conf generator to its own module (#2341)
1 parent 5732c88 commit b981399

File tree

3 files changed

+134
-152
lines changed

3 files changed

+134
-152
lines changed

docs/conf.py

Lines changed: 19 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,32 @@
33
import re
44
import sys
55
from datetime import date, datetime
6+
from importlib.machinery import SourceFileLoader
67
from pathlib import Path
78
from subprocess import check_output
8-
from typing import Any, cast
9+
from typing import Any
910

10-
from docutils.nodes import Element, Node, Text, container, fully_normalize_name, literal, paragraph, reference, strong
11-
from docutils.parsers.rst.directives import flag, unchanged, unchanged_required
12-
from docutils.parsers.rst.states import RSTState, RSTStateMachine
13-
from docutils.statemachine import StringList, string2lines
11+
from docutils.nodes import Element, reference
1412
from sphinx.addnodes import pending_xref
1513
from sphinx.application import Sphinx
1614
from sphinx.builders import Builder
17-
from sphinx.domains.std import StandardDomain
15+
from sphinx.domains.python import PythonDomain
1816
from sphinx.environment import BuildEnvironment
1917
from sphinx.ext.autodoc import Options
2018
from sphinx.ext.extlinks import ExternalLinksChecker
21-
from sphinx.locale import __
22-
from sphinx.util.docutils import SphinxDirective
23-
from sphinx.util.logging import getLogger
2419

2520
from tox import __version__
2621

27-
company = "tox-dev"
28-
name = "tox"
29-
version = ".".join(__version__.split(".")[:2])
30-
release = __version__
22+
company, name = "tox-dev", "tox"
23+
release, version = __version__, ".".join(__version__.split(".")[:2])
3124
copyright = f"2010-{date.today().year}, {company}"
25+
master_doc, source_suffix = "index", ".rst"
26+
27+
html_theme = "furo"
28+
html_title, html_last_updated_fmt = "tox", datetime.now().isoformat()
29+
pygments_style, pygments_dark_style = "sphinx", "monokai"
30+
html_static_path, html_css_files = ["_static"], ["custom.css"]
31+
html_logo, html_favicon = "_static/img/tox.svg", "_static/img/toxfavi.ico"
3232

3333
extensions = [
3434
"sphinx.ext.autodoc",
@@ -41,38 +41,13 @@
4141
"sphinx_copybutton",
4242
]
4343

44-
templates_path = []
45-
unused_docs = []
46-
source_suffix = ".rst"
4744
exclude_patterns = ["_build", "changelog/*", "_draft.rst"]
48-
49-
master_doc = "index"
50-
pygments_style = "default"
51-
52-
project = name
53-
today_fmt = "%B %d, %Y"
54-
55-
html_theme = "furo"
56-
html_theme_options = {
57-
"navigation_with_keys": True,
58-
}
59-
html_title = "tox 4 - rewrite"
60-
html_static_path = ["_static"]
61-
html_css_files = ["custom.css"]
62-
html_last_updated_fmt = datetime.now().isoformat()
63-
html_logo = "_static/img/tox.svg"
64-
html_favicon = "_static/img/toxfavi.ico"
65-
66-
autoclass_content = "class"
67-
autodoc_member_order = "bysource"
45+
autoclass_content, autodoc_member_order, autodoc_typehints = "class", "bysource", "none"
6846
autodoc_default_options = {
6947
"member-order": "bysource",
7048
"undoc-members": True,
7149
"show-inheritance": True,
7250
}
73-
autodoc_typehints = "none"
74-
always_document_param_types = False
75-
typehints_fully_qualified = True
7651
autosectionlabel_prefix_document = True
7752

7853
extlinks = {
@@ -95,10 +70,6 @@
9570
extlinks_detect_hardcoded_links = True
9671

9772

98-
def skip_member(app: Sphinx, what: str, name: str, obj: Any, would_skip: bool, options: Options) -> bool: # noqa: U100
99-
return name in options.get("exclude-members", set()) or would_skip
100-
101-
10273
def process_signature(
10374
app: Sphinx, # noqa: U100
10475
objtype: str,
@@ -113,16 +84,13 @@ def process_signature(
11384

11485

11586
def setup(app: Sphinx) -> None:
116-
logger = getLogger(__name__)
117-
118-
root = Path(__file__).parents[1]
119-
exe = Path(sys.executable)
87+
here = Path(__file__).parent
88+
# 1. run towncrier
89+
root, exe = here.parent, Path(sys.executable)
12090
towncrier = exe.with_name(f"towncrier{exe.suffix}")
12191
new = check_output([str(towncrier), "--draft", "--version", "NEXT"], cwd=root, universal_newlines=True)
12292
(root / "docs" / "_draft.rst").write_text("" if "No significant changes" in new else new)
12393

124-
from sphinx.domains.python import PythonDomain
125-
12694
class PatchedPythonDomain(PythonDomain):
12795
def resolve_xref(
12896
self,
@@ -148,95 +116,10 @@ def resolve_xref(
148116
# node.children[0].children[0] = Text(target, target)
149117
return super().resolve_xref(env, fromdocname, builder, type, target, node, contnode)
150118

151-
app.connect("autodoc-skip-member", skip_member)
152119
app.connect("autodoc-process-signature", process_signature, priority=400)
153120
app.add_domain(PatchedPythonDomain, override=True)
154-
155-
class ToxConfig(SphinxDirective):
156-
name = "conf"
157-
has_content = True
158-
option_spec = {
159-
"keys": unchanged_required,
160-
"version_added": unchanged,
161-
"version_changed": unchanged,
162-
"default": unchanged,
163-
"constant": flag,
164-
"ref_suffix": unchanged,
165-
}
166-
167-
def __init__(
168-
self,
169-
name: str,
170-
arguments: list[str],
171-
options: dict[str, str],
172-
content: StringList,
173-
lineno: int,
174-
content_offset: int,
175-
block_text: str,
176-
state: RSTState,
177-
state_machine: RSTStateMachine,
178-
):
179-
super().__init__(
180-
name,
181-
arguments,
182-
options,
183-
content,
184-
lineno,
185-
content_offset,
186-
block_text,
187-
state,
188-
state_machine,
189-
)
190-
self._std_domain: StandardDomain = cast(StandardDomain, self.env.get_domain("std"))
191-
192-
def run(self) -> list[Node]:
193-
self.env.note_reread() # this document needs to be always updated
194-
195-
line = paragraph()
196-
line += Text("■" if "constant" in self.options else "⚙️")
197-
for key in (i.strip() for i in self.options["keys"].split(",")):
198-
line += Text(" ")
199-
self._mk_key(line, key)
200-
if "default" in self.options:
201-
default = self.options["default"]
202-
line += Text(" with default value of ")
203-
line += literal(default, default)
204-
if "version_added" in self.options:
205-
line += Text(" 📢 added in ")
206-
ver = self.options["version_added"]
207-
line += literal(ver, ver)
208-
209-
p = container("")
210-
self.state.nested_parse(StringList(string2lines("\n".join(f" {i}" for i in self.content))), 0, p)
211-
line += p
212-
213-
return [line]
214-
215-
def _mk_key(self, line: paragraph, key: str) -> None:
216-
ref_id = key if "ref_suffix" not in self.options else f"{key}-{self.options['ref_suffix']}"
217-
ref = reference("", refid=ref_id, reftitle=key)
218-
line.attributes["ids"].append(ref_id)
219-
st = strong()
220-
st += literal(text=key)
221-
ref += st
222-
self._register_ref(ref_id, ref_id, ref)
223-
line += ref
224-
225-
def _register_ref(self, ref_name: str, ref_title: str, node: Element) -> None:
226-
of_name, doc_name = fully_normalize_name(ref_name), self.env.docname
227-
if of_name in self._std_domain.labels:
228-
logger.warning(
229-
__("duplicate label %s, other instance in %s"),
230-
of_name,
231-
self.env.doc2path(self._std_domain.labels[of_name][0]),
232-
location=node,
233-
type="sphinx-argparse-cli",
234-
subtype=self.env.docname,
235-
)
236-
self._std_domain.anonlabels[of_name] = doc_name, ref_name
237-
self._std_domain.labels[of_name] = doc_name, ref_name, ref_title
238-
239-
app.add_directive(ToxConfig.name, ToxConfig)
121+
tox_cfg = SourceFileLoader("tox_conf", str(here / "tox_conf.py")).load_module().ToxConfig
122+
app.add_directive(tox_cfg.name, tox_cfg)
240123

241124
def check_uri(self, refnode: reference) -> None:
242125
if refnode.document.attributes["source"].endswith("index.rst"):

docs/tox_conf.py

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
from __future__ import annotations
2+
3+
from typing import cast
4+
5+
from docutils.nodes import Element, Node, Text, container, fully_normalize_name, literal, paragraph, reference, strong
6+
from docutils.parsers.rst.directives import flag, unchanged, unchanged_required
7+
from docutils.parsers.rst.states import RSTState, RSTStateMachine
8+
from docutils.statemachine import StringList, string2lines
9+
from sphinx.domains.std import StandardDomain
10+
from sphinx.locale import __
11+
from sphinx.util.docutils import SphinxDirective
12+
from sphinx.util.logging import getLogger
13+
14+
LOGGER = getLogger(__name__)
15+
16+
17+
class ToxConfig(SphinxDirective):
18+
name = "conf"
19+
has_content = True
20+
option_spec = {
21+
"keys": unchanged_required,
22+
"version_added": unchanged,
23+
"version_changed": unchanged,
24+
"default": unchanged,
25+
"constant": flag,
26+
"ref_suffix": unchanged,
27+
}
28+
29+
def __init__(
30+
self,
31+
name: str,
32+
arguments: list[str],
33+
options: dict[str, str],
34+
content: StringList,
35+
lineno: int,
36+
content_offset: int,
37+
block_text: str,
38+
state: RSTState,
39+
state_machine: RSTStateMachine,
40+
):
41+
super().__init__(
42+
name,
43+
arguments,
44+
options,
45+
content,
46+
lineno,
47+
content_offset,
48+
block_text,
49+
state,
50+
state_machine,
51+
)
52+
self._std_domain: StandardDomain = cast(StandardDomain, self.env.get_domain("std"))
53+
54+
def run(self) -> list[Node]:
55+
self.env.note_reread() # this document needs to be always updated
56+
57+
line = paragraph()
58+
line += Text("■" if "constant" in self.options else "⚙️")
59+
for key in (i.strip() for i in self.options["keys"].split(",")):
60+
line += Text(" ")
61+
self._mk_key(line, key)
62+
if "default" in self.options:
63+
default = self.options["default"]
64+
line += Text(" with default value of ")
65+
line += literal(default, default)
66+
if "version_added" in self.options:
67+
line += Text(" 📢 added in ")
68+
ver = self.options["version_added"]
69+
line += literal(ver, ver)
70+
71+
p = container("")
72+
self.state.nested_parse(StringList(string2lines("\n".join(f" {i}" for i in self.content))), 0, p)
73+
line += p
74+
75+
return [line]
76+
77+
def _mk_key(self, line: paragraph, key: str) -> None:
78+
ref_id = key if "ref_suffix" not in self.options else f"{key}-{self.options['ref_suffix']}"
79+
ref = reference("", refid=ref_id, reftitle=key)
80+
line.attributes["ids"].append(ref_id)
81+
st = strong()
82+
st += literal(text=key)
83+
ref += st
84+
self._register_ref(ref_id, ref_id, ref)
85+
line += ref
86+
87+
def _register_ref(self, ref_name: str, ref_title: str, node: Element) -> None:
88+
of_name, doc_name = fully_normalize_name(ref_name), self.env.docname
89+
if of_name in self._std_domain.labels:
90+
LOGGER.warning(
91+
__("duplicate label %s, other instance in %s"),
92+
of_name,
93+
self.env.doc2path(self._std_domain.labels[of_name][0]),
94+
location=node,
95+
type="sphinx-argparse-cli",
96+
subtype=self.env.docname,
97+
)
98+
self._std_domain.anonlabels[of_name] = doc_name, ref_name
99+
self._std_domain.labels[of_name] = doc_name, ref_name, ref_title

setup.cfg

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,31 +60,31 @@ console_scripts =
6060

6161
[options.extras_require]
6262
docs =
63-
furo>=2021.8.17b43
63+
furo>=2022.1.2
6464
sphinx>=4.4
65-
sphinx-argparse-cli>=1.7
65+
sphinx-argparse-cli>=1.8.3
6666
sphinx-autodoc-typehints>=1.16
67-
sphinx-copybutton>=0.4
68-
sphinx-inline-tabs>=2021.4.11b9
69-
sphinxcontrib-towncrier>=0.2.0a0
67+
sphinx-copybutton>=0.5
68+
sphinx-inline-tabs>=2022.1.2b11
69+
sphinxcontrib-towncrier>=0.2.1a0
7070
towncrier>=21.3
7171
testing =
72-
covdefaults>=1.2
72+
covdefaults>=2.2
7373
devpi-client>=5.2
74-
devpi-server>=6.1
75-
distlib>=0.3.2
76-
filelock>=3
74+
devpi-server>=6.4
75+
distlib>=0.3.4
76+
filelock>=3.4
7777
flaky>=3.7
7878
freezegun>=1.1
79-
psutil>=5.8
80-
pytest>=6.2
81-
pytest-cov>=2.12
82-
pytest-mock>=3.6
83-
pytest-xdist>=2.3
79+
psutil>=5.9
80+
pytest>=7
81+
pytest-cov>=3
82+
pytest-mock>=3.7
83+
pytest-xdist>=2.5
8484
re-assert>=1.1
85-
setuptools>=57
85+
setuptools>=60
8686
setuptools-scm>=6
87-
wheel>=0.36
87+
wheel>=0.37
8888

8989
[options.package_data]
9090
tox = py.typed

0 commit comments

Comments
 (0)