Skip to content

Route library print() calls through bt.logging#410

Merged
dylanuys merged 2 commits into
mainfrom
refactor/logging
Jul 9, 2026
Merged

Route library print() calls through bt.logging#410
dylanuys merged 2 commits into
mainfrom
refactor/logging

Conversation

@dylanuys

@dylanuys dylanuys commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Part of the "one logging system" cleanup. The codebase already uses bt.logging at ~870 call sites; this converts the misplaced print() 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 bt where missing; removed a now-unused import sys.

2. Enforce it — added ruff T201 to the CI lint select so print() in library code fails the build, with per-file-ignores in pyproject.toml for 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/tools
  • gas/protocol/miner_requests.py — inline upload progress ([1/3] … done, end=' ', flush=True)
  • print_directory_tree's fallback — display helper that already accepts an injected log_func (line-level noqa)
  • scripts/, tests/ — exempted via per-file-ignores

gas/cli.py uses click.echo, so it needs no exemption.

Test plan

  • pytest tests/ — 37 passed
  • ruff check --select E9,F63,F7,F82,T201 gas neurons tests (exact CI command) — clean
  • Verified T201 catches a stray library print() (negative test)

🤖 Generated with Claude Code

dylanuys added 2 commits July 9, 2026 00:52
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.
@dylanuys
dylanuys merged commit a08d3e1 into main Jul 9, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant