|
15 | 15 | #
|
16 | 16 | # The full version, including alpha/beta/rc tags.
|
17 | 17 | # The short X.Y version.
|
| 18 | +import os |
| 19 | +from pathlib import Path |
18 | 20 | import shutil
|
19 | 21 | from textwrap import dedent
|
20 | 22 | from typing import TYPE_CHECKING
|
|
26 | 28 | import sphinx.application
|
27 | 29 |
|
28 | 30 |
|
| 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 | + |
29 | 41 | release = ".".join(version.split(".")[:2])
|
30 | 42 |
|
31 | 43 | # If extensions (or modules to document with autodoc) are in another directory,
|
|
72 | 84 | "sphinx.ext.viewcode",
|
73 | 85 | "sphinx_removed_in",
|
74 | 86 | "sphinxcontrib_trio",
|
| 87 | + "sphinxcontrib.towncrier.ext", # provides `towncrier-draft-entries` directive |
75 | 88 | ]
|
76 | 89 |
|
77 | 90 | # Building PDF docs on readthedocs requires inkscape for svg to pdf
|
|
422 | 435 | )
|
423 | 436 | ]
|
424 | 437 |
|
| 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 | + |
425 | 445 |
|
426 | 446 | intersphinx_mapping = {
|
427 | 447 | "pluggy": ("https://pluggy.readthedocs.io/en/stable", None),
|
|
435 | 455 | }
|
436 | 456 |
|
437 | 457 |
|
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 |
| - |
462 | 458 | def setup(app: "sphinx.application.Sphinx") -> None:
|
463 | 459 | app.add_crossref_type(
|
464 | 460 | "fixture",
|
@@ -488,8 +484,6 @@ def setup(app: "sphinx.application.Sphinx") -> None:
|
488 | 484 | indextemplate="pair: %s; hook",
|
489 | 485 | )
|
490 | 486 |
|
491 |
| - configure_logging(app) |
492 |
| - |
493 | 487 | # legacypath.py monkey-patches pytest.Testdir in. Import the file so
|
494 | 488 | # that autodoc can discover references to it.
|
495 | 489 | import _pytest.legacypath # noqa: F401
|
0 commit comments