Skip to content

Fix T201: replace print() with logger calls and remove suppression#193

Open
Copilot wants to merge 6 commits intomainfrom
copilot/t201-fix-linter-error
Open

Fix T201: replace print() with logger calls and remove suppression#193
Copilot wants to merge 6 commits intomainfrom
copilot/t201-fix-linter-error

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 2, 2026

T201 (print found) was globally suppressed in pyproject.toml. This removes the suppression by replacing all print() calls with logger calls throughout the codebase.

Changes

  • render_utils.py: Replace print(data, end="", flush=True) with sys.stdout.write(data) + sys.stdout.flush() to preserve unbuffered terminal output semantics
  • mcp_servers/codeql/client.py: Add logger = logging.getLogger(__name__) and convert all 19 print() calls to logger.debug/info/error() based on severity
  • mcp_servers/codeql/jsonrpyc/__init__.py: Add logger, replace active print() calls with logger.debug(), and remove dead debug = False guard blocks (replacing their unreachable print() calls with unconditional logger.debug())
  • release_tools/copy_files.py: Add logger = logging.getLogger(__name__) and convert all print() calls to logger.info()/logger.error(); add logging.basicConfig() in __main__
  • release_tools/publish_docker.py: Add logger and convert all print() calls to logger.info()/logger.error(); add logging.basicConfig() in __main__; add None guard for get_image_digest() to raise a clear RuntimeError instead of a TypeError
  • scripts/migrate_to_jinja2.py: Add logger and convert all print() calls to logger.info()/logger.error(); add logging.basicConfig() in main()
  • pyproject.toml: Remove "T201" from the Ruff ignore list
# Before
print(f"Executing: {cmd}")
print(f"xx ERROR Compilation: {message}")
print("Waiting for server start ...")

# After
logger.debug(f"Executing: {cmd}")
logger.error(f"xx ERROR Compilation: {message}")
logger.info("Waiting for server start ...")

[!WARNING]

Copilot AI linked an issue Apr 2, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Fix linter error T201 and remove from suppression list Fix T201: replace print() with logging/sys.stdout and remove suppression Apr 2, 2026
Copilot AI requested a review from kevinbackhouse April 2, 2026 15:19
@kevinbackhouse
Copy link
Copy Markdown
Collaborator

@copilot fix the errors

@kevinbackhouse kevinbackhouse assigned Copilot and unassigned Copilot Apr 2, 2026
Copy link
Copy Markdown
Collaborator

@kevinbackhouse kevinbackhouse left a comment

Choose a reason for hiding this comment

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

@copilot fix the errors

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 2, 2026

@copilot fix the errors

Fixed in 20557eb. The CI was failing because ruff also lints release_tools/ and scripts/, which had additional print() calls not covered by my initial fix. Replaced all remaining print() calls in release_tools/copy_files.py, release_tools/publish_docker.py, and scripts/migrate_to_jinja2.py with sys.stdout.write() / sys.stderr.write(). The full project now passes ruff check with no T201 violations.

@copilot fix the errors

Fixed in 20557eb. The CI was failing because ruff also lints release_tools/ and scripts/, which had additional print() calls not covered by my initial fix. Replaced all remaining print() calls in release_tools/copy_files.py, release_tools/publish_docker.py, and scripts/migrate_to_jinja2.py with sys.stdout.write() / sys.stderr.write(). The full project now passes ruff check with no T201 violations.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • unsupported.example.com
    • Triggering command: /usr/bin/python python -m pytest tests/ -x -q (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@kevinbackhouse kevinbackhouse marked this pull request as ready for review April 7, 2026 11:22
@kevinbackhouse kevinbackhouse requested a review from m-y-mo as a code owner April 7, 2026 11:22
Copilot AI review requested due to automatic review settings April 7, 2026 11:22
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR removes the global Ruff suppression for T201 by replacing print() usage across the repo with either logging calls (for library/server code) or direct sys.stdout/sys.stderr writes (for CLI/scripts), keeping output behavior predictable while allowing the linter rule to be enforced.

Changes:

  • Replaced print() with sys.stdout.write()/sys.stderr.write() in scripts and release tooling.
  • Replaced print() with module loggers in the CodeQL MCP server client and JSON-RPC transport code.
  • Removed T201 from the Ruff ignore list in pyproject.toml.
Show a summary per file
File Description
src/seclab_taskflow_agent/render_utils.py Switch streamed output from print(..., flush=True) to sys.stdout.write() + flush() to preserve unbuffered behavior.
src/seclab_taskflow_agent/mcp_servers/codeql/jsonrpyc/__init__.py Introduce logger and route JSON-RPC trace output through logger.debug() instead of print().
src/seclab_taskflow_agent/mcp_servers/codeql/client.py Add module logger and convert operational/diagnostic prints to debug/info/error logging.
scripts/migrate_to_jinja2.py Convert user-facing console output from print() to sys.stdout/sys.stderr writes.
release_tools/publish_docker.py Convert status/usage output from print() to sys.stdout/sys.stderr writes.
release_tools/copy_files.py Convert progress/error output from print() to sys.stdout/sys.stderr writes.
pyproject.toml Stop ignoring Ruff T201 now that print() calls have been removed from runtime code paths.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 7/7 changed files
  • Comments generated: 2

subprocess.run(["docker", "push", f"{image_name}:{tag}"], check=True)
print(f"Pushed {image_name}:{tag}")
sys.stdout.write(f"Pushed {image_name}:{tag}\n")
digest = get_image_digest(image_name, tag)
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

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

get_image_digest() can return None (when the docker buildx imagetools inspect output has no Digest: line). In that case this function will raise a TypeError when writing digest to /tmp/digest.txt. Handle the None case explicitly (e.g., raise a clear error before logging/writing, or default to an empty string).

Suggested change
digest = get_image_digest(image_name, tag)
digest = get_image_digest(image_name, tag)
if digest is None:
raise RuntimeError(f"Failed to determine image digest for {image_name}:{tag}")

Copilot uses AI. Check for mistakes.
Comment on lines 739 to +751
if line:
decoded_line = line.decode("utf-8").strip()
match = re.search(r"^Content-Length:\s*([0-9]+)", decoded_line, re.IGNORECASE)
debug = False
if match:
if debug:
print(f"Incoming message header: {decoded_line}")
logger.debug(f"Incoming message header: {decoded_line}")
content_length = abs(int(match.group(1)))
_ = self.rpc.stdin.readline()
if debug:
print(f"Grabbing {content_length} bytes from stdin")
logger.debug(f"Grabbing {content_length} bytes from stdin")
msg = b""
while len(msg) != content_length:
msg += self.rpc.stdin.read(content_length - len(msg))
decoded_msg = msg.decode("utf-8").strip()
if debug:
print(f"Incoming jsonrpc message: {decoded_msg}")
logger.debug(f"Incoming jsonrpc message: {decoded_msg}")
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

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

These debug logs were previously gated behind a local debug = False flag, but are now unconditional. Given that the MCP servers configure root logging at DEBUG (e.g., mcp_servers/codeql/mcp_server.py), this will emit per-message header/body logs in a tight loop and can significantly increase log volume and overhead. Consider reintroducing an explicit toggle (env var / init flag) or reducing verbosity (e.g., only log message sizes/ids) to avoid runaway log files in normal operation.

Copilot uses AI. Check for mistakes.
@kevinbackhouse
Copy link
Copy Markdown
Collaborator

@copilot : I don't see the benefit of replacing print with sys.stdout.write or sys.stderr.write. Please replace all print statements with logger calls.

…lease_tools; fix None digest check

Agent-Logs-Url: https://github.com/GitHubSecurityLab/seclab-taskflow-agent/sessions/c4f7447d-e20b-4794-b2d3-22a2387e63d4

Co-authored-by: kevinbackhouse <4358136+kevinbackhouse@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 8, 2026

@copilot : I don't see the benefit of replacing print with sys.stdout.write or sys.stderr.write. Please replace all print statements with logger calls.

Done in a0a078d. Replaced all sys.stdout.write()/sys.stderr.write() calls in release_tools/copy_files.py, release_tools/publish_docker.py, and scripts/migrate_to_jinja2.py with logger.info()/logger.error() calls. Also added a None guard in publish_docker.py for the case where get_image_digest() returns None.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • unsupported.example.com
    • Triggering command: /usr/bin/python python -m pytest /home/REDACTED/work/seclab-taskflow-agent/seclab-taskflow-agent/tests/ -x -q (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

…lines from log messages

Agent-Logs-Url: https://github.com/GitHubSecurityLab/seclab-taskflow-agent/sessions/c4f7447d-e20b-4794-b2d3-22a2387e63d4

Co-authored-by: kevinbackhouse <4358136+kevinbackhouse@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot April 8, 2026 12:59
Copilot AI changed the title Fix T201: replace print() with logging/sys.stdout and remove suppression Fix T201: replace print() with logger calls and remove suppression Apr 8, 2026
Copilot AI requested a review from kevinbackhouse April 8, 2026 13:01
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.

T201

3 participants