Skip to content

Commit 0fce6d4

Browse files
RonnyPfannschmidtpatchback[bot]
authored andcommitted
Merge pull request #12493 from webknjaz/maintenance/sphinx-towncrier-draft
📝💅 Always render changelog draft @ Sphinx docs (cherry picked from commit 20dd1d6)
1 parent 4716ba5 commit 0fce6d4

File tree

7 files changed

+37
-54
lines changed

7 files changed

+37
-54
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ src/_pytest/_version.py
2525

2626
doc/*/_build
2727
doc/*/.doctrees
28-
doc/*/_changelog_towncrier_draft.rst
2928
build/
3029
dist/
3130
*.egg-info

.readthedocs.yml

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ build:
2020
3.12
2121
apt_packages:
2222
- inkscape
23+
jobs:
24+
post_checkout:
25+
- git fetch --unshallow || true
26+
- git fetch --tags || true
2327

2428
formats:
2529
- epub

doc/en/changelog.rst

+7-4
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,15 @@ with advance notice in the **Deprecations** section of releases.
1919
we named the news folder changelog
2020
2121

22-
.. only:: changelog_towncrier_draft
22+
.. only:: not is_release
2323

24-
.. The 'changelog_towncrier_draft' tag is included by our 'tox -e docs',
25-
but not on readthedocs.
24+
To be included in v\ |release| (if present)
25+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2626

27-
.. include:: _changelog_towncrier_draft.rst
27+
.. towncrier-draft-entries:: |release| [UNRELEASED DRAFT]
28+
29+
Released versions
30+
^^^^^^^^^^^^^^^^^
2831

2932
.. towncrier release notes start
3033

doc/en/conf.py

+20-26
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#
1616
# The full version, including alpha/beta/rc tags.
1717
# The short X.Y version.
18+
import os
19+
from pathlib import Path
1820
import shutil
1921
from textwrap import dedent
2022
from typing import TYPE_CHECKING
@@ -26,6 +28,16 @@
2628
import sphinx.application
2729

2830

31+
PROJECT_ROOT_DIR = Path(__file__).parents[2].resolve()
32+
IS_RELEASE_ON_RTD = (
33+
os.getenv("READTHEDOCS", "False") == "True"
34+
and os.environ["READTHEDOCS_VERSION_TYPE"] == "tag"
35+
)
36+
if IS_RELEASE_ON_RTD:
37+
tags: set[str]
38+
# pylint: disable-next=used-before-assignment
39+
tags.add("is_release") # noqa: F821
40+
2941
release = ".".join(version.split(".")[:2])
3042

3143
# If extensions (or modules to document with autodoc) are in another directory,
@@ -72,6 +84,7 @@
7284
"sphinx.ext.viewcode",
7385
"sphinx_removed_in",
7486
"sphinxcontrib_trio",
87+
"sphinxcontrib.towncrier.ext", # provides `towncrier-draft-entries` directive
7588
]
7689

7790
# Building PDF docs on readthedocs requires inkscape for svg to pdf
@@ -422,6 +435,13 @@
422435
)
423436
]
424437

438+
# -- Options for towncrier_draft extension -----------------------------------
439+
440+
towncrier_draft_autoversion_mode = "draft" # or: 'sphinx-version', 'sphinx-release'
441+
towncrier_draft_include_empty = True
442+
towncrier_draft_working_directory = PROJECT_ROOT_DIR
443+
towncrier_draft_config_path = "pyproject.toml" # relative to cwd
444+
425445

426446
intersphinx_mapping = {
427447
"pluggy": ("https://pluggy.readthedocs.io/en/stable", None),
@@ -435,30 +455,6 @@
435455
}
436456

437457

438-
def configure_logging(app: "sphinx.application.Sphinx") -> None:
439-
"""Configure Sphinx's WarningHandler to handle (expected) missing include."""
440-
import logging
441-
442-
import sphinx.util.logging
443-
444-
class WarnLogFilter(logging.Filter):
445-
def filter(self, record: logging.LogRecord) -> bool:
446-
"""Ignore warnings about missing include with "only" directive.
447-
448-
Ref: https://github.com/sphinx-doc/sphinx/issues/2150."""
449-
if (
450-
record.msg.startswith('Problems with "include" directive path:')
451-
and "_changelog_towncrier_draft.rst" in record.msg
452-
):
453-
return False
454-
return True
455-
456-
logger = logging.getLogger(sphinx.util.logging.NAMESPACE)
457-
warn_handler = [x for x in logger.handlers if x.level == logging.WARNING]
458-
assert len(warn_handler) == 1, warn_handler
459-
warn_handler[0].filters.insert(0, WarnLogFilter())
460-
461-
462458
def setup(app: "sphinx.application.Sphinx") -> None:
463459
app.add_crossref_type(
464460
"fixture",
@@ -488,8 +484,6 @@ def setup(app: "sphinx.application.Sphinx") -> None:
488484
indextemplate="pair: %s; hook",
489485
)
490486

491-
configure_logging(app)
492-
493487
# legacypath.py monkey-patches pytest.Testdir in. Import the file so
494488
# that autodoc can discover references to it.
495489
import _pytest.legacypath # noqa: F401

doc/en/requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ sphinxcontrib-svg2pdfconverter
99
# See https://github.com/pytest-dev/pytest/pull/10578#issuecomment-1348249045.
1010
packaging
1111
furo
12+
sphinxcontrib-towncrier

scripts/towncrier-draft-to-file.py

-18
This file was deleted.

tox.ini

+5-5
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@ deps =
8888
# https://github.com/twisted/towncrier/issues/340
8989
towncrier<21.3.0
9090
commands =
91-
python scripts/towncrier-draft-to-file.py
92-
# the '-t changelog_towncrier_draft' tags makes sphinx include the draft
93-
# changelog in the docs; this does not happen on ReadTheDocs because it uses
94-
# the standard sphinx command so the 'changelog_towncrier_draft' is never set there
95-
sphinx-build -W --keep-going -b html doc/en doc/en/_build/html -t changelog_towncrier_draft {posargs:}
91+
# Retrieve possibly missing commits:
92+
-git fetch --unshallow
93+
-git fetch --tags
94+
95+
sphinx-build -W --keep-going -b html doc/en doc/en/_build/html {posargs:}
9696
setenv =
9797
# Sphinx is not clean of this warning.
9898
PYTHONWARNDEFAULTENCODING=

0 commit comments

Comments
 (0)