Avoid stdlib logging shadowing during build#198
Conversation
There was a problem hiding this comment.
💡 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
| """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"] |
There was a problem hiding this comment.
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 👍 / 👎.
Summary
sys.pathreticulum_openapi.loggingalias from__init__and update module importsTesting
https://chatgpt.com/codex/tasks/task_e_68e64f9f52188325afbf46ab23fc6c64