Skip to content

Add Python toolchain with uv, ruff, ty, and security scanning - #41

Closed
waynesun09 wants to merge 6 commits into
mainfrom
add-python-toolchain-ci-security
Closed

Add Python toolchain with uv, ruff, ty, and security scanning#41
waynesun09 wants to merge 6 commits into
mainfrom
add-python-toolchain-ci-security

Conversation

@waynesun09

Copy link
Copy Markdown
Member

Summary

  • Add pre-commit configuration with ruff (lint/format), ty (type check), bandit (Python security), gitleaks (secret detection), and actionlint (workflow validation)
  • Add CI workflow using uv + pre-commit with explicit permissions: contents: read
  • Apply ruff lint and format fixes to existing experiment Python code

Why

The repo has Python code in experiments/ with no linting, no formatting, no type checking, and no security scanning. The CI workflow (from PR #39) doesn't install Python dependencies and has no security hardening.

Design choices

  • No pyproject.toml — this repo is not a Python package. Tool config lives in ruff.toml and .pre-commit-config.yaml. When PR Add lightweight ADR process with Undecided state and CI linting #39 merges, hack/lint-adr-frontmatter can adopt PEP 723 inline script metadata so uv run auto-installs its PyYAML dependency.
  • Pattern borrowed from cicaddy-action — same ruff + ty + bandit + gitleaks + actionlint stack.

Security scanning coverage

Tool What it catches
bandit Hardcoded passwords, SQL injection, unsafe deserialization, shell injection
gitleaks API keys, tokens, credentials committed to git
detect-private-key SSH/PGP private keys
actionlint Workflow injection risks, expression syntax, action version issues

Add pre-commit configuration with:
- ruff for linting and formatting
- ty for type checking (via uvx)
- bandit for Python security scanning
- gitleaks for secret detection
- actionlint for GitHub Actions workflow validation
- pre-commit-hooks for YAML/JSON/TOML validation and private key detection

Add CI workflow using uv + pre-commit on GitHub Actions with explicit
permissions: contents: read.

Add ruff.toml and .python-version for local development. No pyproject.toml
since this repo is not a Python package.

Signed-off-by: Wayne Sun <gsun@redhat.com>
Auto-fix import sorting (I001), unused imports (F401), and format
long lines (E501) across experiment Python code.

Signed-off-by: Wayne Sun <gsun@redhat.com>
@waynesun09
waynesun09 requested a review from a team as a code owner March 20, 2026 16:08
B603 (subprocess_without_shell_equals_true) flags subprocess.run with
a list of args, which is the safe pattern. False positive in test code.

Signed-off-by: Wayne Sun <gsun@redhat.com>
Fix pre-existing trailing whitespace in contributor-guidance.md.
Skip B404 (import-subprocess) alongside B101 and B603 — flagging
the subprocess import itself is noise in test code.

Signed-off-by: Wayne Sun <gsun@redhat.com>
Signed-off-by: Wayne Sun <gsun@redhat.com>
Experiment code has heavy dependencies (torch, transformers, anthropic)
that aren't installed in CI. ty runs locally via pre-commit where
developers have their venv. The CI ty step can be added back when
hack/ scripts land (PR #39) as a lightweight target.

Signed-off-by: Wayne Sun <gsun@redhat.com>
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