Route library print() calls through bt.logging#410
Merged
Conversation
Convert 26 print() calls in library internals to bt.logging at appropriate levels (error for caught exceptions, warning for recoverable/missing-file cases, debug for success detail): - gas/cache/media_storage.py (12), gas/cache/util/video.py (10), gas/cache/util/filesystem.py (2), gas/generation/util/image.py (2) - add 'import bittensor as bt' where missing; drop now-unused 'import sys' Left as-is (genuine user-facing CLI stdout, not logging): miner_stats.py, push_model.py, verify_c2pa.py, cli.py, miner_requests.py upload progress, and print_directory_tree's display fallback (which already supports an injected log_func).
Adds T201 to the CI ruff select so print() in library code fails the build. CLI presenters and tools keep stdout output via per-file-ignores in pyproject (miner_stats, miner_requests, push_model, verify_c2pa, scripts/, tests/); print_directory_tree's display fallback gets a line-level noqa. This makes the print->bt.logging conversion durable instead of a one-time cleanup.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Part of the "one logging system" cleanup. The codebase already uses
bt.loggingat ~870 call sites; this converts the misplacedprint()calls in library internals to match, so their output actually reaches the pm2/Docker logs instead of vanishing to stdout — and adds a lint rule so it can't regress.1. Convert library prints →
bt.logging(26 calls across four files), at appropriate levels (error for caught exceptions, warning for recoverable/missing-file cases, debug for success detail):gas/cache/media_storage.py(12)gas/cache/util/video.py(10)gas/cache/util/filesystem.py(2)gas/generation/util/image.py(2)Added
import bittensor as btwhere missing; removed a now-unusedimport sys.2. Enforce it — added ruff
T201to the CI lint select soprint()in library code fails the build, with per-file-ignores inpyproject.tomlfor the genuine CLI presenters.Deliberately kept as
print()(genuine user-facing CLI stdout, not logging)gas/cache/util/miner_stats.py,neurons/discriminator/push_model.py,neurons/generator/helper/verify_c2pa.py— CLI presenters/toolsgas/protocol/miner_requests.py— inline upload progress ([1/3] … done,end=' ', flush=True)print_directory_tree's fallback — display helper that already accepts an injectedlog_func(line-level noqa)scripts/,tests/— exempted via per-file-ignoresgas/cli.pyusesclick.echo, so it needs no exemption.Test plan
pytest tests/— 37 passedruff check --select E9,F63,F7,F82,T201 gas neurons tests(exact CI command) — cleanprint()(negative test)🤖 Generated with Claude Code