Commit 601178a
feat(python): add uv package manager support (TC-3855) (guacsec#428)
## Summary
- Add `PythonUvProvider` and `PythonProviderFactory` for automatic uv
package manager detection via `uv.lock` presence
- Dependency resolution uses `uv pip list --format=json` + `uv pip show`
for CycloneDX SBOM generation (stack + component)
- Extract shared TOML parsing into `PyprojectTomlUtils`, refactor both
`PythonPyprojectProvider` and `PythonUvProvider` to use it
- Fix PEP 508 extras stripping bug in `getDependencyName()` (e.g.
`requests[security]` → `requests`) affecting all Python providers
- Document uv support, `TRUSTIFY_DA_UV_PATH`, and CLI examples in README
## Test plan
- [x] `mvn test -Dtest="Python_Uv_Provider_Test"
-Dskip.junit_platform=true` — 15 uv provider tests pass
- [x] `mvn test -Dtest="Python_Pyproject_Provider_Test"
-Dskip.junit_platform=true` — 22 existing pyproject tests pass
(regression)
- [x] `mvn test
-Dtest="PythonControllerRealEnvTest#get_Dependency_Name*"
-Dskip.junit_platform=true` — extras fix tests pass
- [x] `mvn spotless:check` — formatting passes
- [x] Manual CLI test: `java -jar trustify-da-java-client-cli.jar sbom
/path/to/uv-project/pyproject.toml` produces correct CycloneDX SBOM
## Acceptance Criteria
- [x] `PythonProviderFactory.create()` returns `PythonUvProvider` when
`uv.lock` exists
- [x] `PythonProviderFactory.create()` falls back to
`PythonPyprojectProvider` when no `uv.lock`
- [x] `PythonUvProvider` discovers uv binary via
`Operations.getExecutable("uv", "--version")`
- [x] Custom binary path supported via `TRUSTIFY_DA_UV_PATH`
- [x] `validateLockFile()` throws `IllegalStateException` when `uv.lock`
missing
- [x] `provideStack()` and `provideComponent()` generate valid CycloneDX
SBOMs
- [x] Existing `requirements.txt` and `pyproject.toml` flows unchanged
- [x] `#trustify-da-ignore` / `#exhortignore` patterns work in uv
context
- [x] README documents uv support
🤖 Generated with [Claude Code](https://claude.com/claude-code)
## Summary by Sourcery
Add uv-based Python provider selection and shared pyproject.toml
utilities while preserving existing pip/pyproject behavior.
New Features:
- Introduce PythonUvProvider to generate CycloneDX SBOMs for uv-managed
pyproject.toml projects based on uv export output.
- Add PythonProviderFactory to automatically choose between uv and
pip-based pyproject providers using uv.lock detection, including
workspace-aware lock-file lookup.
Bug Fixes:
- Ensure Python dependency name parsing strips PEP 508 extras before
extracting the base package name, preventing incorrect identifiers like
requests[security].
Enhancements:
- Refactor pyproject.toml parsing and metadata extraction into shared
PyprojectTomlUtils used by both pip and uv Python providers.
- Extend Python pyproject provider to reuse shared canonicalization,
license lookup, and ignore-pattern handling logic.
CI:
- Install the uv tool in the pull request workflow to support uv-related
tests.
Documentation:
- Document uv package manager support for Python, including automatic
lock-file based selection, custom TRUSTIFY_DA_UV_PATH configuration, and
CLI SBOM usage examples.
Tests:
- Add comprehensive unit tests for PythonUvProvider, including graph
parsing, SBOM generation, and ignore patterns for uv projects.
- Add tests for PythonProviderFactory lock-file discovery across
workspaces and for dependency name parsing with PEP 508 extras in real
Python environments.
---------
Signed-off-by: Adva Oren <aoren@redhat.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>1 parent c0688e0 commit 601178a
18 files changed
Lines changed: 1619 additions & 63 deletions
File tree
- .github/workflows
- src
- main/java/io/github/guacsec/trustifyda
- providers
- tools
- utils
- test
- java/io/github/guacsec/trustifyda
- providers
- utils
- resources/tst_manifests/pip
- pip_pyproject_toml_uv_ignore
- pip_pyproject_toml_uv
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
| 47 | + | |
46 | 48 | | |
47 | 49 | | |
48 | 50 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
182 | 182 | | |
183 | 183 | | |
184 | 184 | | |
185 | | - | |
| 185 | + | |
186 | 186 | | |
187 | 187 | | |
188 | 188 | | |
| |||
393 | 393 | | |
394 | 394 | | |
395 | 395 | | |
| 396 | + | |
396 | 397 | | |
397 | 398 | | |
398 | 399 | | |
| |||
504 | 505 | | |
505 | 506 | | |
506 | 507 | | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
507 | 513 | | |
508 | 514 | | |
509 | 515 | | |
| |||
600 | 606 | | |
601 | 607 | | |
602 | 608 | | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
603 | 617 | | |
604 | 618 | | |
605 | 619 | | |
| |||
683 | 697 | | |
684 | 698 | | |
685 | 699 | | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
686 | 706 | | |
687 | 707 | | |
688 | 708 | | |
| |||
Lines changed: 121 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
Lines changed: 15 additions & 55 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| |||
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
45 | | - | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
49 | 48 | | |
50 | 49 | | |
51 | 50 | | |
| |||
133 | 132 | | |
134 | 133 | | |
135 | 134 | | |
136 | | - | |
| 135 | + | |
137 | 136 | | |
138 | 137 | | |
139 | 138 | | |
| |||
266 | 265 | | |
267 | 266 | | |
268 | 267 | | |
269 | | - | |
| 268 | + | |
270 | 269 | | |
271 | 270 | | |
272 | 271 | | |
| |||
285 | 284 | | |
286 | 285 | | |
287 | 286 | | |
288 | | - | |
| 287 | + | |
289 | 288 | | |
290 | 289 | | |
291 | 290 | | |
| |||
299 | 298 | | |
300 | 299 | | |
301 | 300 | | |
302 | | - | |
| 301 | + | |
303 | 302 | | |
304 | 303 | | |
305 | 304 | | |
| |||
317 | 316 | | |
318 | 317 | | |
319 | 318 | | |
320 | | - | |
| 319 | + | |
321 | 320 | | |
322 | 321 | | |
323 | 322 | | |
| |||
338 | 337 | | |
339 | 338 | | |
340 | 339 | | |
341 | | - | |
342 | | - | |
343 | | - | |
344 | | - | |
345 | 340 | | |
346 | 341 | | |
347 | | - | |
348 | | - | |
349 | | - | |
350 | | - | |
351 | | - | |
352 | | - | |
| 342 | + | |
353 | 343 | | |
354 | 344 | | |
355 | 345 | | |
356 | 346 | | |
357 | 347 | | |
358 | 348 | | |
359 | 349 | | |
360 | | - | |
361 | | - | |
362 | | - | |
| 350 | + | |
| 351 | + | |
363 | 352 | | |
364 | 353 | | |
365 | 354 | | |
| |||
371 | 360 | | |
372 | 361 | | |
373 | 362 | | |
374 | | - | |
375 | | - | |
376 | | - | |
| 363 | + | |
| 364 | + | |
377 | 365 | | |
378 | 366 | | |
379 | 367 | | |
| |||
385 | 373 | | |
386 | 374 | | |
387 | 375 | | |
388 | | - | |
389 | | - | |
390 | | - | |
| 376 | + | |
| 377 | + | |
391 | 378 | | |
392 | 379 | | |
393 | | - | |
394 | | - | |
395 | | - | |
396 | | - | |
397 | | - | |
398 | 380 | | |
399 | 381 | | |
400 | 382 | | |
| |||
416 | 398 | | |
417 | 399 | | |
418 | 400 | | |
419 | | - | |
420 | | - | |
421 | | - | |
| 401 | + | |
422 | 402 | | |
423 | 403 | | |
424 | 404 | | |
425 | 405 | | |
426 | 406 | | |
427 | 407 | | |
428 | 408 | | |
429 | | - | |
430 | | - | |
431 | | - | |
432 | | - | |
433 | | - | |
434 | | - | |
435 | | - | |
436 | | - | |
437 | | - | |
438 | | - | |
439 | | - | |
440 | | - | |
| 409 | + | |
441 | 410 | | |
442 | 411 | | |
443 | 412 | | |
| |||
455 | 424 | | |
456 | 425 | | |
457 | 426 | | |
458 | | - | |
459 | | - | |
460 | | - | |
461 | | - | |
462 | | - | |
463 | | - | |
464 | | - | |
465 | | - | |
466 | | - | |
467 | 427 | | |
468 | 428 | | |
469 | 429 | | |
| |||
0 commit comments