Skip to content

Commit 8de7b5f

Browse files
committed
gp-opengraph, gp-sitemap(fix[logging]): attach NullHandler + drop trailing periods
why: PR #22 code review flagged two CLAUDE.md#logging violations in the two new packages. These are house-style invariants that every existing workspace package (gp_sphinx, sphinx_fonts, sphinx_ux_badges, …) already follows: 1. "Add ``NullHandler`` in library ``__init__.py`` files" (CLAUDE.md line 553) — both new package __init__.py files declared a module-level logger without one. Importing either package outside a Sphinx build could surface a "no handlers could be found" warning from stdlib logging. 2. "No trailing punctuation" in log messages (CLAUDE.md line 576) — two log calls introduced in commit ab3a6a6 and 04f0121 ended with a period. what: - packages/gp-opengraph/src/gp_opengraph/__init__.py: * After ``logger = logging.getLogger(__name__)`` attach ``logger.addHandler(logging.NullHandler())`` to match the sphinx-fonts pattern exactly. * ``_warn_if_social_cards_used``: message reworded to "ogp_social_cards ignored — gp-opengraph ships no card generator; use a static PNG via ogp_image (site default) or per-page 'og:image' frontmatter" (no trailing period; also trimmed the "is ignored — gp-opengraph does not bundle a card generator" phrasing into "ignored — … ships no card generator" which reads cleaner as a warning). - packages/gp-sitemap/src/gp_sitemap/__init__.py: * Import ``logging`` from stdlib and add ``logging.getLogger(__name__).addHandler(logging.NullHandler())`` alongside the existing ``logger = getLogger(__name__)`` from ``sphinx.util.logging``. The Sphinx adapter is kept because it supports the ``type=``/``subtype=`` kwargs used elsewhere for warning classification; the NullHandler attaches to the underlying stdlib logger with the same name so the library is well-behaved when imported outside Sphinx. Inline comment memorializes the two-getLogger dance so future readers don't try to delete one. * ``_write_sitemap`` "skipping sitemap" info message: trailing period removed. CI gate (all green before commit): - uv run ruff check . --fix --show-fixes: clean - uv run ruff format .: no changes - uv run mypy: Success (176 source files) - uv run py.test --reruns 0: 1199 passed, 3 skipped - just build-docs: build succeeded
1 parent 6c31af6 commit 8de7b5f

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

packages/gp-opengraph/src/gp_opengraph/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
from sphinx.config import Config
3939

4040
logger = logging.getLogger(__name__)
41+
logger.addHandler(logging.NullHandler())
4142

4243
_EXTENSION_VERSION = "0.0.1a9"
4344

@@ -260,9 +261,9 @@ def _warn_if_social_cards_used(app: Sphinx, config: Config) -> None:
260261
del app # unused; required by Sphinx's config-inited signature
261262
if config.ogp_social_cards:
262263
logger.warning(
263-
"gp-opengraph: ogp_social_cards is ignored — gp-opengraph does "
264-
"not bundle a card generator. Use a static PNG via ogp_image "
265-
"(site default) or per-page 'og:image' frontmatter.",
264+
"gp-opengraph: ogp_social_cards ignored — gp-opengraph ships "
265+
"no card generator; use a static PNG via ogp_image (site "
266+
"default) or per-page 'og:image' frontmatter",
266267
)
267268

268269

packages/gp-sitemap/src/gp_sitemap/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import contextlib
2727
import datetime as dt
2828
import fnmatch
29+
import logging
2930
import pathlib
3031
import typing as t
3132
from xml.etree import ElementTree
@@ -44,7 +45,12 @@
4445
_SITEMAP_NS = "http://www.sitemaps.org/schemas/sitemap/0.9"
4546
_XHTML_NS = "http://www.w3.org/1999/xhtml"
4647

48+
# gp-sitemap uses Sphinx's logger adapter so ``type=``/``subtype=`` kwargs
49+
# work for warning classification, but still attaches NullHandler to the
50+
# underlying stdlib logger so the library doesn't emit "no handlers" warnings
51+
# when imported outside a Sphinx build (per CLAUDE.md #Logger setup).
4752
logger = getLogger(__name__)
53+
logging.getLogger(__name__).addHandler(logging.NullHandler())
4854

4955
SitemapLink = tuple[str, str | None] # (relative link, last_updated ISO8601 or None)
5056

@@ -229,7 +235,7 @@ def _write_sitemap(app: Sphinx, exception: BaseException | None) -> None:
229235
# that run with ``-W``.
230236
logger.info(
231237
"gp-sitemap: skipping sitemap — set site_url or html_baseurl "
232-
"in conf.py to enable.",
238+
"in conf.py to enable",
233239
type="sitemap",
234240
subtype="configuration",
235241
)

0 commit comments

Comments
 (0)