Skip to content

feat: add Python language support with venv and manifest modes#51

Open
kbsteere wants to merge 10 commits intochainguard-dev:mainfrom
kbsteere:python-support
Open

feat: add Python language support with venv and manifest modes#51
kbsteere wants to merge 10 commits intochainguard-dev:mainfrom
kbsteere:python-support

Conversation

@kbsteere
Copy link
Copy Markdown
Member

Manifest mode: Edit pyproject.toml, requirements.txt, setup.cfg, or Pipfile. Supports pip, uv, poetry, hatch, pdm, maturin, scikit-build-core, setuptools with --tool override.

Venv mode: Upgrade packages in staged virtualenv using uv pip install or venv pip. Validates == pinning, rejects downgrades, verifies with pip check.

Changes:

  • Resolve merge conflict: include both PHP and Python imports
  • Add --tool and --venv CLI flags
  • Implement DetectManifestWithHint for tool hints
  • Implement venv.go with updateVenv/validateVenv
  • Add 99 unit tests

Manifest mode: Edit pyproject.toml, requirements.txt, setup.cfg, or Pipfile. Supports pip, uv, poetry, hatch, pdm, maturin, scikit-build-core, setuptools with --tool override.

Venv mode: Upgrade packages in staged virtualenv using uv pip install or venv pip. Validates == pinning, rejects downgrades, verifies with pip check.

Changes:
- Resolve merge conflict: include both PHP and Python imports
- Add --tool and --venv CLI flags
- Implement DetectManifestWithHint for tool hints
- Implement venv.go with updateVenv/validateVenv
- Add 99 unit tests
- Replace dynamic error messages with wrapped static errors (err113)
- Add error checking and logging to deferred cleanup operations (errcheck)
- Extract manifest and build tool detection logic to reduce nesting (nestif)
- Use manifest type constants instead of string literals (goconst)
- Add doc comments to all exported constants (revive)
- Validate manifest paths explicitly in read/write operations (gosec)
- Add validation for subprocess executable paths before execution (gosec)
- Preallocate slices with proper capacity (prealloc)
- Fix import formatting with goimports and gofumpt (gci/gofmt/goimports)
- Remove unused function parameters with underscore naming

Remaining: 15 issues (2 gci import formatting, 13 gosec subprocess/path validation)
Reorder imports to match gci's preference: omnibump internal imports before external
third-party imports. This follows Go convention and satisfies the gci formatter.
- Use filepath.Clean() on all file path operations to prevent path traversal
- Create safeWriteFile() helper with explicit path validation
- Replace dynamic error messages with wrapped static errors
- Add nolint comments for gosec G204 with clear justifications
- Use command constants (UVCommand, PipCommand) instead of string literals
- Verify subprocess executables exist before execution with os.Stat()

All 71 golangci-lint errors resolved. Build passes with 0 issues.
…tandards

- Create example_test.go with Example functions demonstrating public API
- Add compile-time assertions for Language and Analyzer interfaces
- Ensures compliance with Go code standards and documentation requirements
@kbsteere kbsteere requested a review from a team April 15, 2026 18:27
corridor-security[bot]

This comment was marked as resolved.

…ard registry requests

Only add the Chainguard authentication token to requests whose Host matches
the configured registryBaseURL. PyPI requests and any other cross-host requests
will not include the Authorization header, preventing unintended token disclosure
to third-party services.
corridor-security[bot]

This comment was marked as resolved.

Place nolint directives directly before the problematic code lines
rather than on function signatures. This ensures gosec errors are
properly suppressed while avoiding false positive nolintlint warnings.
… option injection

Add strict validation to reject package names starting with '-' or not matching
PEP 503 format, and reject version strings with invalid characters. This prevents
argument injection attacks where malicious package names could be interpreted as
command-line options (e.g., --index-url=https://evil.com).

Also fixes linting issues:
- Replace dynamic errors with wrapped static errors
- Use #nosec G703 for validated path operations
- Fix revive comment format for exported constant
Move defer cleanup setup before error-prone operations so cleanup is
guaranteed regardless of error path. This eliminates G703 warnings without
needing linter suppression. Cleaner approach: centralize all cleanup in one
defer statement.
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