Skip to content
This repository was archived by the owner on May 3, 2026. It is now read-only.

Avoid stdlib logging shadowing during build#198

Merged
brothercorvo merged 1 commit intomainfrom
corvo/outline-steps-to-release-project-on-github
Oct 8, 2025
Merged

Avoid stdlib logging shadowing during build#198
brothercorvo merged 1 commit intomainfrom
corvo/outline-steps-to-release-project-on-github

Conversation

@brothercorvo
Copy link
Copy Markdown
Contributor

Summary

  • rename the logging helper module to avoid shadowing the standard library when the package directory is on sys.path
  • provide a backwards-compatible reticulum_openapi.logging alias from __init__ and update module imports
  • extend the logging configuration test suite to cover the alias and confirm handler reuse

Testing

  • pytest tests/test_logging_config.py
  • python -m build

https://chatgpt.com/codex/tasks/task_e_68e64f9f52188325afbf46ab23fc6c64

@brothercorvo brothercorvo merged commit 6bde311 into main Oct 8, 2025
2 checks passed
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting

Comment on lines +1 to +45
"""Shared logging configuration for the ``reticulum_openapi`` package."""

from __future__ import annotations

import logging as _logging
from typing import Iterable

PACKAGE_LOGGER_NAME = "reticulum_openapi"
_DEFAULT_LOG_LEVEL = _logging.INFO
_HANDLER_NAME = "reticulum_openapi.stream"
_LOG_FORMAT = "[%(asctime)s] %(levelname)s %(name)s: %(message)s"


def _handler_exists(handlers: Iterable[_logging.Handler]) -> bool:
"""Return ``True`` when the shared stream handler has already been added."""
for handler in handlers:
if getattr(handler, "name", "") == _HANDLER_NAME:
return True
return False


def configure_logging(level: int = _DEFAULT_LOG_LEVEL) -> _logging.Logger:
"""Configure and return the package logger.

Args:
level (int): Logging level applied to the package logger. Defaults to
:data:`logging.INFO`.

Returns:
logging.Logger: The shared package logger instance.
"""
logger = _logging.getLogger(PACKAGE_LOGGER_NAME)
logger.setLevel(level)
if not _handler_exists(logger.handlers):
handler = _logging.StreamHandler()
handler.set_name(_HANDLER_NAME)
handler.setFormatter(_logging.Formatter(_LOG_FORMAT))
logger.addHandler(handler)
logger.propagate = False
return logger


configure_logging()

__all__ = ["configure_logging", "PACKAGE_LOGGER_NAME"]
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Renaming does not remove stdlib shadowing

The new logging_config module and alias in __init__ still leave reticulum_openapi/logging.py in the package. When the package directory itself is placed on sys.path (the scenario described in the summary), import logging continues to resolve to that legacy file and raises a circular import (AttributeError: partially initialized module 'logging' has no attribute 'INFO'), so the original build failure remains. The helper file needs to be physically renamed or removed so only the stdlib logging is found when importing by basename.

Useful? React with 👍 / 👎.

@brothercorvo brothercorvo deleted the corvo/outline-steps-to-release-project-on-github branch November 14, 2025 18:26
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant