Skip to content

chore: add per-venv scan logging to Python project detector#144

Open
swarit-stepsecurity wants to merge 1 commit into
step-security:mainfrom
swarit-stepsecurity:swarit/chore/wt/add-logs-python
Open

chore: add per-venv scan logging to Python project detector#144
swarit-stepsecurity wants to merge 1 commit into
step-security:mainfrom
swarit-stepsecurity:swarit/chore/wt/add-logs-python

Conversation

@swarit-stepsecurity

Copy link
Copy Markdown
Member

Brings PythonProjectDetector to logging parity with NodeScanner.ScanProjects: search-dir progress, venv discovery count, truncation warning, per-venv scan progress, and pip-list failure warnings (previously dropped silently).

Adds a logger field (no-op default) and a WithLogger chained method; wired in at the telemetry and scan call sites.

What does this PR do?

Type of change

  • Bug fix
  • Enhancement
  • Documentation

Testing

  • Tested on macOS (version: ___)
  • Binary runs without errors: ./stepsecurity-dev-machine-guard --verbose
  • JSON output is valid: ./stepsecurity-dev-machine-guard --json | python3 -m json.tool
  • No secrets or credentials included
  • Lint passes: make lint
  • Tests pass: make test

Related Issues

Brings PythonProjectDetector to logging parity with NodeScanner.ScanProjects:
search-dir progress, venv discovery count, truncation warning, per-venv scan
progress, and pip-list failure warnings (previously dropped silently).

Adds a logger field (no-op default) and a WithLogger chained method; wired in
at the telemetry and scan call sites.

Copilot AI left a comment

Copy link
Copy Markdown

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 brings PythonProjectDetector’s runtime logging up to parity with the Node project scanner by adding search-dir progress logs, venv discovery/truncation summaries, per-venv scan progress, and warnings when pip list fails (previously silent). It does so by introducing an injectable progress.Logger (defaulting to a no-op) and wiring it into the telemetry and scan entry points.

Changes:

  • Add a log field plus WithLogger(...) chain method to PythonProjectDetector (no-op by default).
  • Emit progress/debug/warn logs for search-dir iteration, venv discovery counts, truncation, per-venv scans, and pip list failures.
  • Wire the logger into both telemetry and community scan call sites.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
internal/telemetry/telemetry.go Passes the run logger into PythonProjectDetector so telemetry runs surface per-dir/per-venv progress and warnings.
internal/scan/scanner.go Passes the run logger into PythonProjectDetector for community scan runs.
internal/detector/pythonproject.go Adds logger support and new logging for discovery/scan flow, plus warnings on pip list failures.

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

Comment on lines +191 to 196
start := time.Now()
stdout, _, exitCode, err := d.exec.RunWithTimeout(ctx, 15*time.Second, pipPath, "list", "--format", "json")
duration := time.Since(start).Milliseconds()
if errMsg := pmRunError("pip list", exitCode, err); errMsg != "" {
d.log.Warn("python venv scan failed: %s (venv=%s, exit=%d, %dms) — results may be incomplete", errMsg, venvPath, exitCode, duration)
return nil
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.

2 participants