8000 [3.12] GH-121970: Extract ``misc_news`` into a new extension (GH-1295… · python/cpython@834b9d6 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 834b9d6

Browse files
authored
[3.12] GH-121970: Extract misc_news into a new extension (GH-129577) (#129587)
(cherry picked from commit ae47888)
1 parent 14bd0fc commit 834b9d6

File tree

8 files changed

+85
-50
lines changed

8 files changed

+85
-50
lines changed

Doc/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
'changes',
2929
'glossary_search',
3030
'lexers',
31+
'misc_news',
3132
'pyspecific',
3233
'sphinx.ext.coverage',
3334
'sphinx.ext.doctest',

Doc/make.bat

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,16 +127,14 @@ goto end
127127
:build
128128
if not exist "%BUILDDIR%" mkdir "%BUILDDIR%"
129129

130-
rem PY_MISC_NEWS_DIR is also used by our Sphinx extension in tools/extensions/pyspecific.py
131-
if not defined PY_MISC_NEWS_DIR set PY_MISC_NEWS_DIR=%BUILDDIR%\%1
132-
if not exist "%PY_MISC_NEWS_DIR%" mkdir "%PY_MISC_NEWS_DIR%"
130+
if not exist build mkdir build
133131
if exist ..\Misc\NEWS (
134-
echo.Copying Misc\NEWS to %PY_MISC_NEWS_DIR%\NEWS
135-
copy ..\Misc\NEWS "%PY_MISC_NEWS_DIR%\NEWS" > nul
132+
echo.Copying existing Misc\NEWS file to Doc\build\NEWS
133+
copy ..\Misc\NEWS build\NEWS > nul
136134
) else if exist ..\Misc\NEWS.D (
137135
if defined BLURB (
138136
echo.Merging Misc/NEWS with %BLURB%
139-
%BLURB% merge -f "%PY_MISC_NEWS_DIR%\NEWS"
137+
%BLURB% merge -f build\NEWS
140138
) else (
141139
echo.No Misc/NEWS file and Blurb is not available.
142140
exit /B 1

Doc/tools/extensions/misc_news.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
"""Support for including Misc/NEWS."""
2+
3+
from __future__ import annotations
4+
5+
import re
6+
from pathlib import Path
7+
from typing import TYPE_CHECKING
8+
9+
from docutils import nodes
10+
from sphinx.locale import _ as sphinx_gettext
11+
from sphinx.util.docutils import SphinxDirective
12+
13+
if TYPE_CHECKING:
14+
from typing import Final
15+
16+
from docutils.nodes import Node
17+
from sphinx.application import Sphinx
18+
from sphinx.util.typing import ExtensionMetadata
19+
20+
21+
BLURB_HEADER = """\
22+
+++++++++++
23+
Python News
24+
+++++++++++
25+
"""
26+
27+
bpo_issue_re: Final[re.Pattern[str]] = re.compile(
28+
"(?:issue #|bpo-)([0-9]+)", re.ASCII
29+
)
30+
gh_issue_re: Final[re.Pattern[str]] = re.compile(
31+
"gh-(?:issue-)?([0-9]+)", re.ASCII | re.IGNORECASE
32+
)
33+
whatsnew_re: Final[re.Pattern[str]] = re.compile(
34+
r"^what's new in (.*?)\??$", re.ASCII | re.IGNORECASE | re.MULTILINE
35+
)
36+
37+
38+
class MiscNews(SphinxDirective):
39+
has_content = False
40+
required_arguments = 1
41+
optional_arguments = 0
42+
final_argument_whitespace = False
43+
option_spec = {}
44+
45+
def run(self) -> list[Node]:
46+
# Get content of NEWS file
47+
source, _ = self.get_source_info()
48+
news_file = Path(source).resolve().parent / self.arguments[0]
49+
self.env.note_dependency(news_file)
50+
try:
51+
news_text = news_file.read_text(encoding="utf-8")
52+
except (OSError, UnicodeError):
53+
text = sphinx_gettext("The NEWS file is not available.")
54+
return [nodes.strong(text, text)]
55+
56+
# remove first 3 lines as they are the main heading
57+
news_text = news_text.removeprefix(BLURB_HEADER)
58+
59+
news_text = bpo_issue_re.sub(r":issue:`\1`", news_text)
60+
# Fallback handling for GitHub issues
61+
news_text = gh_issue_re.sub(r":gh:`\1`", news_text)
62+
news_text = whatsnew_re.sub(r"\1", news_text)
63+
64+
self.state_machine.insert_input(news_text.splitlines(), str(news_file))
65+
return []
66+
67+
68+
def setup(app: Sphinx) -> ExtensionMetadata:
69+
app.add_directive("miscnews", MiscNews)
70+
71+
return {
72+
"version": "1.0",
73+
"parallel_read_safe": True,
74+
"parallel_write_safe": True,
75+
}

Doc/tools/extensions/pyspecific.py

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -147,46 +147,6 @@ def run(self):
147147
return PyMethod.run(self)
148148

149149

150-
# Support for including Misc/NEWS
151-
152-
issue_re = re.compile('(?:[Ii]ssue #|bpo-)([0-9]+)', re.I)
153-
gh_issue_re = re.compile('(?:gh-issue-|gh-)([0-9]+)', re.I)
154-
whatsnew_re = re.compile(r"(?im)^what's new in (.*?)\??$")
155-
156-
157-
class MiscNews(SphinxDirective):
158-
has_content = False
159-
required_arguments = 1
160-
optional_arguments = 0
161-
final_argument_whitespace = False
162-
option_spec = {}
163-
164-
def run(self):
165-
fname = self.arguments[0]
166-
source = self.state_machine.input_lines.source(
167-
self.lineno - self.state_machine.input_offset - 1)
168-
source_dir = getenv('PY_MISC_NEWS_DIR')
169-
if not source_dir:
170-
source_dir = path.dirname(path.abspath(source))
171-
fpath = path.join(source_dir, fname)
172-
self.env.note_dependency(path.abspath(fpath))
173-
try:
174-
with io.open(fpath, encoding='utf-8') as fp:
175-
content = fp.read()
176-
except Exception:
177-
text = 'The NEWS file is not available.'
178-
node = nodes.strong(text, text)
179-
return [node]
180-
content = issue_re.sub(r':issue:`\1`', content)
181-
# Fallback handling for the GitHub issue
182-
content = gh_issue_re.sub(r':gh:`\1`', content)
183-
content = whatsnew_re.sub(r'\1', content)
184-
# remove first 3 lines as they are the main heading
185-
lines = ['.. default-role:: obj', ''] + content.splitlines()[3:]
186-
self.state_machine.insert_input(lines, fname)
187-
return []
188-
189-
190150
# Support for building "topic help" for pydoc
191151

192152
pydoc_topic_labels = [
@@ -340,6 +300,5 @@ def setup(app):
340300
app.add_directive_to_domain('py', 'awaitablefunction', PyAwaitableFunction)
341301
app.add_directive_to_domain('py', 'awaitablemethod', PyAwaitableMethod)
342302
app.add_directive_to_domain('py', 'abstractmethod', PyAbstractMethod)
343-
app.add_directive('miscnews', MiscNews)
344303
app.connect('env-check-consistency', patch_pairindextypes)
345304
return {'version': '1.0', 'parallel_read_safe': True}

Doc/whatsnew/changelog.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
.. _changelog:
22

3+
.. default-role:: py:obj
4+
35
+++++++++
46
Changelog
57
+++++++++

Misc/NEWS.d/3.5.3rc1.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1146,7 +1146,7 @@ after a commit.
11461146
.. section: Library
11471147
11481148
A new version of typing.py from https://github.com/python/typing:
1149-
Collection (only for 3.6) (Issue #27598). Add FrozenSet to __all__
1149+
Collection (only for 3.6) (issue #27598). Add FrozenSet to __all__
11501150
(upstream #261). Fix crash in _get_type_vars() (upstream #259). Remove the
11511151
dict constraint in ForwardRef._eval_type (upstream #252).
11521152

Misc/NEWS.d/3.6.0a4.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ Support keyword arguments to zlib.decompress(). Patch by Xiang Zhang.
177177
.. section: Library
178178
179179
Prevent segfault after interpreter re-initialization due to ref count
180-
problem introduced in code for Issue #27038 in 3.6.0a3. Patch by Xiang
180+
problem introduced in code for issue #27038 in 3.6.0a3. Patch by Xiang
181181
Zhang.
182182

183183
..

Misc/NEWS.d/3.6.0b1.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,7 @@ chunked transfer-encoding.
11371137
.. section: Library
11381138
11391139
A new version of typing.py from https://github.com/python/typing: -
1140-
Collection (only for 3.6) (Issue #27598) - Add FrozenSet to __all__
1140+
Collection (only for 3.6) (issue #27598) - Add FrozenSet to __all__
11411141
(upstream #261) - fix crash in _get_type_vars() (upstream #259) - Remove the
11421142
dict constraint in ForwardRef._eval_type (upstream #252)
11431143

0 commit comments

Comments
 (0)
0