This repository was archived by the owner on May 3, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Avoid stdlib logging shadowing during build #198
Merged
brothercorvo
merged 1 commit into
main
from
corvo/outline-steps-to-release-project-on-github
Oct 8, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,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"] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new
logging_configmodule and alias in__init__still leavereticulum_openapi/logging.pyin the package. When the package directory itself is placed onsys.path(the scenario described in the summary),import loggingcontinues 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 stdlibloggingis found when importing by basename.Useful? React with 👍 / 👎.