Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
- **`--fix-plan`, `--apply` and `fix-pr` for Poetry projects**, verified with Poetry's
resolver, for `[tool.poetry.dependencies]` and `[project]` requirements. Because
`poetry update --lock` never fails when another package holds a fix back, depquiet reads
the holders from `poetry.lock`, lets Poetry move them, and checks the resulting lock.
Exact pins stay exact; `^`, `~` and ranges keep their style. Verified with Poetry 2.5.1
and pip-audit on two projects where botocore holds urllib3 below its fix: 10 alerts
→ 0 (legacy table, exact pins) and 16 → 1 (PEP 621 ranges; the one left is a filtered
dev-only alert). Dependabot cannot make this change in Python projects
(dependabot-core#16337), and Renovate's maintainers say security fixes for transitive
packages in `poetry.lock` are not supported (renovate discussion #28776).

## [0.45.2] - 2026-11-14

### Changed
Expand Down
46 changes: 42 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ projects, uv's resolver rejects the nearest fix for 502 of 991 kept alerts (51%)
the 17 projects with alerts; in 81% of the blocked upgrades, the project's own pin is what
is in the way. See [`--check-fixes`](#can-the-fix-be-installed---check-fixes).

For uv projects depquiet goes one step further: [`--fix-plan`](#one-verified-change-for-all-the-fixes---fix-plan)
For uv and Poetry projects depquiet goes one step further: [`--fix-plan`](#one-verified-change-for-all-the-fixes---fix-plan)
computes the requirement changes that let the fixes install together and verifies them
with uv's resolver, and the GitHub Action's
with the project's own resolver, and the GitHub Action's
[`fix-pr`](#one-pull-request-with-every-fix-that-installs-fix-pr) opens one pull request
with them. That includes the case Dependabot reports as `update_not_possible`: a parent
package that must move before a vulnerable dependency can.
Expand Down Expand Up @@ -610,6 +610,43 @@ Real run on a small project pinning `requests==2.31.0` and `botocore==1.29.0` (w
After `git apply` and that command, pip-audit reports no known vulnerabilities in the
project's dependencies. Python-floor blocks are reported, not planned.

#### Poetry projects

`--fix-plan`, `--apply` and `fix-pr` work on Poetry projects too (a `poetry.lock` and no
`uv.lock`), verified with Poetry's own resolver, for both `[tool.poetry.dependencies]` and
`[project]` requirements. Real run with Poetry 2.5.1 on the same case, `requests = "2.31.0"`
and `botocore = "1.29.0"`:

```
🔧 Fix plan
✓ requests 2.31.0 → 2.33.0: widen your requirement
✓ urllib3 1.26.20 → 2.8.0: also move botocore → 1.44.3, which holds it back (major version change)

Verified with Poetry's resolver: all fixes resolve together.
Then run: poetry update --lock requests urllib3 botocore
```
```diff
[tool.poetry.dependencies]
python = "^3.11"
-requests = "2.31.0"
-botocore = "1.29.0"
+requests = "2.33.0"
+botocore = "1.44.3"
```

10 alerts before, 0 after. What differs from uv:

- `poetry update --lock urllib3` does not fail when botocore holds urllib3 back: it
resolves and leaves urllib3 where it was. depquiet reads the holders from `poetry.lock`,
lets Poetry move them, and checks the new lock.
- Poetry has no "upgrade to exactly this version": `poetry update` moves a package to the
newest version your constraints allow, so a range such as `^2.31` can land above the
fix. An exact pin stays exact, at the fix version. The plan shows where each package ends.
- `--check-fixes` on its own is for uv projects. For Poetry the plan is the check.
- Constraints with `||` and git or path dependencies are not rewritten: that fix is listed
as left out, with the reason.
- No `exclude-newer` handling: that is a uv setting.

#### One pull request with every fix that installs (`fix-pr`)

`--fix-plan --apply` applies the verified plan to the project: it edits the requirements
Expand Down Expand Up @@ -653,10 +690,11 @@ open as of November 2026): the alert ends in `update_not_possible`.

What to know before you turn it on:

- **uv projects only**, like `--fix-plan`.
- **uv and Poetry projects**, like `--fix-plan`. The Action installs Poetry when it finds
a `poetry.lock` and Poetry is not already on the runner.
- The branch (`depquiet/security-fixes`, or `fix-pr-branch`) is **force-pushed on every
run**: it is always your branch plus one commit. Do not commit to it by hand.
- The commit holds only `pyproject.toml`, `uv.toml` and `uv.lock` changes.
- The commit holds only `pyproject.toml`, `uv.toml`, `uv.lock` and `poetry.lock` changes.
- **Your CI does not start on a pull request opened with the default `GITHUB_TOKEN`**:
that is how GitHub works. Pass a personal access token or GitHub App token as
`fix-pr-token` to have your tests run on it.
Expand Down
1 change: 1 addition & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ from the project or its dependencies:
| npm scan | `npm audit --json` | No |
| `--check-fixes`, `--fix-plan` | `uv lock --dry-run` (on a temporary copy for `--fix-plan`) | Yes: uv can run build hooks |
| `--fix-plan --apply`, the Action's `fix-pr` | `uv lock --upgrade-package` on the project | Yes: uv can run build hooks |
| `--fix-plan` on a Poetry project (also with `--apply`, `fix-pr`) | `poetry update --lock`, on temporary copies and then on the project | Yes: Poetry can build a package to read its metadata |
| `--fix` | `uv lock --upgrade-package`, or `npm install pkg@version` | Yes: npm runs install scripts |

Run those modes on code you trust, as you would `pip install` or `npm install`. In CI,
Expand Down
16 changes: 11 additions & 5 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ inputs:
required: false
default: "true"
fix-pr:
description: "uv projects: open (or update) one pull request with every fix that uv's resolver confirms installs together: requirement changes in pyproject.toml/uv.toml plus uv.lock (true/false). Skipped on pull_request events. Needs contents: write and pull-requests: write. Runs uv lock: trusted code only."
description: "uv and Poetry projects: open (or update) one pull request with every fix that the project's resolver confirms installs together: requirement changes in pyproject.toml/uv.toml plus the lock file (true/false). Skipped on pull_request events. Needs contents: write and pull-requests: write. Runs uv lock or poetry update --lock: trusted code only."
required: false
default: "false"
fix-pr-branch:
Expand Down Expand Up @@ -163,6 +163,7 @@ runs:
INPUT_INSTALL_PIP_AUDIT: ${{ inputs.install-pip-audit }}
INPUT_CHECK_FIXES: ${{ inputs.check-fixes }}
INPUT_FIX_PR: ${{ inputs.fix-pr }}
INPUT_PATH: ${{ inputs.path }}
# Install the action's own code, so @v0.35.0 runs 0.35.0 and a fresh
# tag works before PyPI's index lists it. pip-audit is depquiet's
# scanner for Python projects; without it they fall back to OSV.dev.
Expand All @@ -174,6 +175,11 @@ runs:
if { [ "$INPUT_CHECK_FIXES" = "true" ] || [ "$INPUT_FIX_PR" = "true" ]; } && ! command -v uv >/dev/null 2>&1; then
python -m pip install --disable-pip-version-check uv
fi
# A Poetry project's fixes are verified with Poetry's own resolver.
if [ "$INPUT_FIX_PR" = "true" ] && [ -f "$INPUT_PATH/poetry.lock" ] && [ ! -f "$INPUT_PATH/uv.lock" ] \
&& ! command -v poetry >/dev/null 2>&1; then
python -m pip install --disable-pip-version-check poetry
fi
depquiet --version

- name: Run depquiet
Expand Down Expand Up @@ -482,10 +488,10 @@ runs:
run: |
set -euo pipefail
if [ ! -s "$FIX_REPORT" ]; then
if [ ! -f "$INPUT_PATH/uv.lock" ]; then
echo "::warning::depquiet: fix-pr works on uv projects, and $INPUT_PATH has no uv.lock; no pull request."
if [ ! -f "$INPUT_PATH/uv.lock" ] && [ ! -f "$INPUT_PATH/poetry.lock" ]; then
echo "::warning::depquiet: fix-pr works on uv and Poetry projects, and $INPUT_PATH has no uv.lock or poetry.lock; no pull request."
else
echo "depquiet: no fix that uv's resolver confirms installs; no pull request."
echo "depquiet: no fix that the resolver confirms installs; no pull request."
fi
exit 0
fi
Expand All @@ -502,7 +508,7 @@ runs:
cd "$INPUT_PATH"
# Only what the plan changes: requirement files and the lockfile.
# ls-files, not "git add" with pathspecs: add fails when one matches nothing.
git ls-files -z -m -- ':(glob)**/pyproject.toml' ':(glob)**/uv.toml' ':(glob)**/uv.lock' \
git ls-files -z -m -- ':(glob)**/pyproject.toml' ':(glob)**/uv.toml' ':(glob)**/uv.lock' ':(glob)**/poetry.lock' \
| xargs -0 -r git add --
if git diff --cached --quiet; then
echo "depquiet: the plan changed no tracked file; no pull request."
Expand Down
18 changes: 15 additions & 3 deletions src/depquiet/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
from depquiet.license import LicenseReport, print_license_report, scan_licenses
from depquiet.models import ScanResult
from depquiet.output import print_scan_result
from depquiet.poetryplan import build_poetry_plan, is_poetry_project
from depquiet.policy import load_policy
from depquiet.sarif import write_sarif
from depquiet.sbom import write_sbom
Expand Down Expand Up @@ -454,8 +455,8 @@ def main(argv: list[str] | None = None) -> int:
depquiet scan the project in this directory
depquiet --json machine-readable report
depquiet --check-fixes uv: can each fix be installed, and what blocks it
depquiet --fix-plan plan.diff uv: one verified pyproject.toml change for all fixes
depquiet --fix-plan --apply uv: apply that change and relock (restored on failure)
depquiet --fix-plan plan.diff uv, Poetry: one verified pyproject.toml change for all fixes
depquiet --fix-plan --apply uv, Poetry: apply that change and relock (restored on failure)
depquiet --fail-on high fail CI on high or critical ACTION alerts

other commands:
Expand Down Expand Up @@ -842,6 +843,16 @@ def _has(flag: str) -> bool:
flag = "--fix-plan" if args.fix_plan is not None else "--check-fixes"
if merged.offline:
print(f"depquiet: {flag} needs network access; skipped (--offline).", file=sys.stderr)
elif is_poetry_project(args.path):
# Poetry has no per-fix dry run to report on: the plan is the check.
if args.fix_plan is not None:
fix_plan = build_poetry_plan(result, args.path)
else:
print(
"depquiet: --check-fixes works on uv projects; for a Poetry project use "
"--fix-plan, which verifies the fixes with Poetry's resolver.",
file=sys.stderr,
)
else:
checks, check_note = check_fixes(result, args.path)
if check_note:
Expand Down Expand Up @@ -876,12 +887,13 @@ def _has(flag: str) -> bool:
fix_plan_markdown(fix_plan, result, __version__), encoding="utf-8"
)
if args.apply and fix_plan.included:
lockfile = "poetry.lock" if fix_plan.tool == "poetry" else "uv.lock"
problem = apply_fix_plan(fix_plan, args.path)
if problem:
print(f"Error: --apply: {problem}", file=sys.stderr)
return 2
print(
" Applied: the files above are edited and uv.lock is updated. "
f" Applied: the files above are edited and {lockfile} is updated. "
"Run your tests before you commit.",
file=sys.stderr,
)
Expand Down
90 changes: 77 additions & 13 deletions src/depquiet/fixplan.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from __future__ import annotations

import difflib
import os
import re
import shutil
import subprocess
Expand Down Expand Up @@ -111,6 +112,7 @@ class FixPlan:
items: list[PlanItem] = field(default_factory=list)
diff: str = ""
note: str = ""
tool: str = "uv" # the resolver that verified it: "uv" or "poetry"

@property
def included(self) -> list[PlanItem]:
Expand All @@ -122,6 +124,13 @@ def left_out(self) -> list[PlanItem]:

@property
def command(self) -> str:
if self.tool == "poetry":
names: list[str] = []
for item in self.included:
for name in [item.package, *[s.split("==")[0] for s in item.also_upgrade]]:
if name not in names:
names.append(name)
return "poetry update --lock " + " ".join(names) if names else ""
specs: list[str] = []
for item in self.included:
specs.append(f"{item.package}=={item.version}")
Expand All @@ -131,6 +140,7 @@ def command(self) -> str:
def to_dict(self) -> dict[str, Any]:
return {
"status": self.status,
"tool": self.tool,
"command": self.command,
"diff": self.diff,
"note": self.note,
Expand Down Expand Up @@ -281,9 +291,49 @@ def _edits_for(project: Path, package: str, version: str) -> list[PlanEdit]:
return edits


def _set_poetry_constraint(text: str, package: str, old: str, new: str) -> str:
"""Replace one package's constraint in the ``[tool.poetry...]`` tables.

Only on that package's own line: another package pinned to the same
version string must not change with it.
"""
key = _pep503(package)
entry = re.compile(r"^\s*(?P<q>[\"']?)(?P<name>[A-Za-z0-9_.-]+)(?P=q)\s*=\s*(?P<value>.*)$")
in_poetry = False
lines = text.splitlines(keepends=True)
for i, line in enumerate(lines):
stripped = line.strip()
if stripped.startswith("["):
in_poetry = stripped.lstrip("[").strip().startswith("tool.poetry")
continue
match = entry.match(line.rstrip("\r\n")) if in_poetry else None
if match is None or _pep503(match.group("name")) != key:
continue
for quote in ('"', "'"):
if f"{quote}{old}{quote}" in match.group("value"):
value = match.group("value").replace(
f"{quote}{old}{quote}", f"{quote}{new}{quote}", 1
)
lines[i] = line[: match.start("value")] + value + line[len(line.rstrip("\r\n")) :]
break
return "".join(lines)


def unique_edits(edits: list[PlanEdit]) -> list[PlanEdit]:
"""Edits without repeats: two fixes can ask for the same change to a shared holder."""
seen: list[PlanEdit] = []
for edit in edits:
key = (edit.file, edit.package, edit.old, edit.kind)
if all((e.file, e.package, e.old, e.kind) != key for e in seen):
seen.append(edit)
return seen


def _edit_text(text: str, edit: PlanEdit) -> str:
if edit.kind == "cooldown":
return _set_cooldown(text, edit.file, edit.package, edit.new)
if edit.kind == "poetry":
return _set_poetry_constraint(text, edit.package, edit.old, edit.new)
for quote in ('"', "'"):
text = text.replace(f"{quote}{edit.old}{quote}", f"{quote}{edit.new}{quote}")
return text
Expand Down Expand Up @@ -796,27 +846,34 @@ def apply_fix_plan(plan: FixPlan, project: Path, *, timeout: int = 900) -> str:
"""Apply a verified plan to the project itself: edit the files, then relock.

Returns "" on success, or what went wrong. On any failure every file is
put back exactly as it was, ``uv.lock`` included, so a failed apply never
put back exactly as it was, the lock file included, so a failed apply never
leaves the project half-changed.
"""
executable = shutil.which("uv")
tool = plan.tool
lockfile = "poetry.lock" if tool == "poetry" else "uv.lock"
executable = shutil.which(tool)
if executable is None:
return "uv is not on PATH."
return f"{tool} is not on PATH."
if not plan.included:
return "the plan has no fix to apply."
edits = [e for item in plan.included for e in item.edits]
touched = sorted({e.file for e in edits} | {"uv.lock"})
seen = unique_edits(edits)
touched = sorted({e.file for e in seen} | {lockfile})
before = {name: (project / name).read_bytes() for name in touched if (project / name).is_file()}

def restore() -> None:
for name, data in before.items():
(project / name).write_bytes(data)

env = dict(os.environ)
if tool == "poetry":
# Only the lock file changes: never create or touch a virtualenv.
env.update(POETRY_VIRTUALENVS_CREATE="false", NO_COLOR="1")
cmd = [executable, *plan.command.split()[1:], "--no-interaction", "--no-ansi"]
else:
cmd = [executable, "lock", *plan.command.split()[2:]]
try:
_apply(project, edits)
cmd = [executable, "lock"]
for spec in plan.command.split()[2:]:
cmd.append(spec)
_apply(project, seen)
r = subprocess.run(
cmd,
cwd=project,
Expand All @@ -825,17 +882,18 @@ def restore() -> None:
encoding="utf-8",
errors="replace",
timeout=timeout,
env=env,
)
except subprocess.TimeoutExpired:
restore()
return f"uv lock timed out after {timeout} s; nothing was changed."
return f"{tool} timed out after {timeout} s; nothing was changed."
except OSError as e:
restore()
return f"could not apply the plan ({e}); nothing was changed."
if r.returncode != 0:
restore()
tail = " ".join((r.stderr or r.stdout).split())[-300:]
return f"uv lock failed, nothing was changed: {tail}"
return f"{tool} lock failed, nothing was changed: {tail}"
return ""


Expand Down Expand Up @@ -868,12 +926,17 @@ def cell(text: str) -> str:
if r.vuln.cve not in known:
known.append(r.vuln.cve)
n = len(plan.included)
resolver = "Poetry's" if plan.tool == "poetry" else "uv's"
files = (
"`pyproject.toml` requirements and `poetry.lock`"
if plan.tool == "poetry"
else "`pyproject.toml`/`uv.toml` requirements and `uv.lock`"
)
confirmed = "this fix installs" if n == 1 else f"these {n} fixes install together"
lines = [
"## Security fixes verified by depquiet",
"",
f"uv's resolver confirmed that {confirmed}. This pull request changes only "
"`pyproject.toml`/`uv.toml` requirements and `uv.lock`.",
f"{resolver} resolver confirmed that {confirmed}. This pull request changes only {files}.",
"",
"| Package | From | To | Advisories | How |",
"|---|---|---|---|---|",
Expand Down Expand Up @@ -940,6 +1003,7 @@ def print_fix_plan(plan: FixPlan, file: Any) -> None:
if plan.status == "verified"
else (f"{len(plan.included)} of {len(plan.items)} fixes resolve together")
)
print(f"\n Verified with uv's resolver: {verdict}.", file=file)
resolver = "Poetry's" if plan.tool == "poetry" else "uv's"
print(f"\n Verified with {resolver} resolver: {verdict}.", file=file)
print(f" Then run: {plan.command}", file=file)
print(f" {plan.note}", file=file)
Loading
Loading