pysentry-rs 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of pysentry-rs might be problematic. Click here for more details.

Files changed (36) hide show
  1. pysentry_rs-0.1.0/.gitignore +52 -0
  2. pysentry_rs-0.1.0/CLAUDE.md +145 -0
  3. pysentry_rs-0.1.0/Cargo.lock +2464 -0
  4. pysentry_rs-0.1.0/Cargo.toml +43 -0
  5. pysentry_rs-0.1.0/LICENSE +674 -0
  6. pysentry_rs-0.1.0/PKG-INFO +297 -0
  7. pysentry_rs-0.1.0/PUBLISHING.md +367 -0
  8. pysentry_rs-0.1.0/README.md +271 -0
  9. pysentry_rs-0.1.0/pyproject.toml +41 -0
  10. pysentry_rs-0.1.0/python/pysentry-rs/__init__.py +46 -0
  11. pysentry_rs-0.1.0/python/pysentry-rs/__main__.py +6 -0
  12. pysentry_rs-0.1.0/src/cache/audit.rs +76 -0
  13. pysentry_rs-0.1.0/src/cache/mod.rs +7 -0
  14. pysentry_rs-0.1.0/src/cache/storage.rs +85 -0
  15. pysentry_rs-0.1.0/src/dependency/mod.rs +5 -0
  16. pysentry_rs-0.1.0/src/dependency/scanner.rs +253 -0
  17. pysentry_rs-0.1.0/src/error.rs +53 -0
  18. pysentry_rs-0.1.0/src/lib.rs +142 -0
  19. pysentry_rs-0.1.0/src/main.rs +346 -0
  20. pysentry_rs-0.1.0/src/output/mod.rs +7 -0
  21. pysentry_rs-0.1.0/src/output/report.rs +517 -0
  22. pysentry_rs-0.1.0/src/output/sarif.rs +811 -0
  23. pysentry_rs-0.1.0/src/parsers/lock.rs +471 -0
  24. pysentry_rs-0.1.0/src/parsers/mod.rs +246 -0
  25. pysentry_rs-0.1.0/src/parsers/pyproject.rs +387 -0
  26. pysentry_rs-0.1.0/src/providers/mod.rs +86 -0
  27. pysentry_rs-0.1.0/src/providers/osv.rs +644 -0
  28. pysentry_rs-0.1.0/src/providers/pypa.rs +796 -0
  29. pysentry_rs-0.1.0/src/providers/pypi.rs +290 -0
  30. pysentry_rs-0.1.0/src/python.rs +110 -0
  31. pysentry_rs-0.1.0/src/types.rs +88 -0
  32. pysentry_rs-0.1.0/src/vulnerability/database.rs +163 -0
  33. pysentry_rs-0.1.0/src/vulnerability/matcher.rs +485 -0
  34. pysentry_rs-0.1.0/src/vulnerability/mod.rs +9 -0
  35. pysentry_rs-0.1.0/test-project/pyproject.toml +74 -0
  36. pysentry_rs-0.1.0/test-project/uv.lock +14350 -0
@@ -0,0 +1,52 @@
1
+ # Rust build artifacts
2
+ /target
3
+
4
+ # Python
5
+ __pycache__/
6
+ *.py[cod]
7
+ *$py.class
8
+ *.so
9
+ *.egg-info/
10
+ build/
11
+ dist/
12
+ .Python
13
+ .venv/
14
+ venv/
15
+ ENV/
16
+ env/
17
+ .env
18
+
19
+ # PyO3/Maturin artifacts
20
+ python/**/*.so
21
+ python/**/*.pyd
22
+ python/**/*.dylib
23
+ *.whl
24
+
25
+ # IDE
26
+ .vscode/
27
+ .idea/
28
+ *.swp
29
+ *.swo
30
+ *~
31
+
32
+ # OS
33
+ .DS_Store
34
+ .DS_Store?
35
+ ._*
36
+ .Spotlight-V100
37
+ .Trashes
38
+ ehthumbs.db
39
+ Thumbs.db
40
+
41
+ # Cache directories
42
+ .cache/
43
+ .pytest_cache/
44
+ .mypy_cache/
45
+ .tox/
46
+ .coverage
47
+ htmlcov/
48
+
49
+ # Temporary files
50
+ *.tmp
51
+ *.bak
52
+ *.log
@@ -0,0 +1,145 @@
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ ## Project Overview
6
+
7
+ `pysentry` is a Rust-based security vulnerability auditing tool for Python packages. It's a standalone version inspired by `pip-audit` that works with uv lock files and various vulnerability databases (PyPA, PyPI JSON API, OSV.dev).
8
+
9
+ ## Development Commands
10
+
11
+ ### Build and Test
12
+ - `cargo build` - Build the project in debug mode
13
+ - `cargo build --release` - Build optimized release version
14
+ - `cargo test` - Run all unit and integration tests
15
+ - `cargo test [TESTNAME]` - Run specific test containing the name
16
+ - `cargo test --no-run` - Compile tests without running them
17
+ - `cargo check` - Fast compilation check without building binaries
18
+
19
+ ### Running the Tool
20
+ - `cargo run -- <path>` - Run audit on a directory (debug build)
21
+ - `cargo run --release -- <path>` - Run with release optimizations
22
+ - `cargo run -- --help` - Show complete CLI help
23
+ - `cargo run -- test-project/` - Audit the test project
24
+ - `cargo run -- test-project/ --format json` - JSON output
25
+ - `cargo run -- test-project/ --format sarif` - SARIF output
26
+
27
+ ### Testing with Test Project
28
+ The `test-project/` directory contains a large benchmark project with 100+ dependencies:
29
+ - Contains both `pyproject.toml` and `uv.lock` for comprehensive testing
30
+ - Useful for performance testing and validating real-world scenarios
31
+
32
+ ## Architecture Overview
33
+
34
+ ### High-Level Data Flow
35
+ The tool follows a 4-phase pipeline:
36
+ 1. **Dependency Discovery**: Parse project files → extract dependency graph → apply filters
37
+ 2. **Vulnerability Fetching**: Select source → check cache → fetch/parse vulnerability data
38
+ 3. **Vulnerability Matching**: Match dependencies → apply version constraints → filter by severity
39
+ 4. **Report Generation**: Generate statistics → format output → write results
40
+
41
+ ### Core Module Architecture
42
+
43
+ **Entry Points**:
44
+ - `main.rs`: CLI interface using clap with comprehensive argument parsing
45
+ - `lib.rs`: High-level API orchestration and `AuditEngine` for programmatic use
46
+
47
+ **Dependency Scanning** (`dependency/` + `parsers/`):
48
+ - Registry pattern for auto-detecting project file formats
49
+ - `UvLockParser` (priority 1): Full dependency graph with exact versions
50
+ - `PyProjectParser` (priority 5): Fallback for pyproject.toml parsing
51
+ - Handles dependency classification (main/dev/optional) and graph analysis
52
+
53
+ **Vulnerability Sources** (`providers/`):
54
+ - Trait-based provider system for extensibility: `VulnerabilityProvider`
55
+ - **PyPA**: Downloads ZIP archives, parses YAML advisories
56
+ - **PyPI**: Queries JSON API for vulnerability data
57
+ - **OSV**: Batch API interface for OSV.dev database
58
+ - Factory pattern via `VulnerabilitySource` enum
59
+
60
+ **Caching System** (`cache/`):
61
+ - Two-tier: `storage.rs` (file operations) + `audit.rs` (audit-specific logic)
62
+ - TTL-based cache invalidation with separate buckets per vulnerability source
63
+ - Atomic operations to prevent cache corruption
64
+ - Cache directory: `~/.cache/pysentry/` (or system temp)
65
+
66
+ **Vulnerability Processing** (`vulnerability/`):
67
+ - `database.rs`: In-memory vulnerability database with efficient lookups
68
+ - `matcher.rs`: Version constraint matching using PEP 440, severity filtering
69
+ - Supports ignore lists and fix analysis with upgrade suggestions
70
+
71
+ **Output Generation** (`output/`):
72
+ - Unified `ReportGenerator` supporting Human/JSON/SARIF formats
73
+ - `report.rs`: Console output with color coding and statistical summaries
74
+ - `sarif.rs`: Static Analysis Results Interchange Format for IDE integration
75
+
76
+ ### Key Architectural Patterns
77
+
78
+ **Async-First Design**: All I/O operations use tokio for concurrent processing
79
+
80
+ **Type Safety**:
81
+ - Custom `PackageName` type with normalization (underscores → hyphens)
82
+ - `Version` wrapper around `pep440_rs::Version`
83
+ - Strong typing prevents common string-based errors
84
+
85
+ **Error Handling**:
86
+ - Comprehensive `AuditError` enum covering all failure modes
87
+ - Uses `thiserror` for structured error messages and context
88
+
89
+ **Extensibility**:
90
+ - Trait-based providers allow adding new vulnerability databases
91
+ - Parser registry enables supporting additional project file formats
92
+ - Format generators can be extended for new output types
93
+
94
+ ## Testing Strategy
95
+
96
+ The codebase has **29 unit tests** distributed across modules:
97
+ - Each module includes `#[cfg(test)]` blocks with focused unit tests
98
+ - Integration testing uses the realistic `test-project/` directory
99
+ - Tests cover parsing, caching, matching logic, and all output formats
100
+ - Run specific module tests: `cargo test cache::` or `cargo test parsers::`
101
+
102
+ ## Cache Behavior
103
+
104
+ Cache is critical for performance with large projects:
105
+ - **Location**: `~/.cache/pysentry/` or `$TEMP/pysentry/` if cache dir unavailable
106
+ - **Structure**: Separate buckets for each vulnerability source (PyPA/PyPI/OSV)
107
+ - **Invalidation**: TTL-based, configurable per source
108
+ - **Disable**: Use `--no-cache` flag for testing or CI environments
109
+ - **Custom location**: Use `--cache-dir` to specify directory
110
+
111
+ ## CLI Design Patterns
112
+
113
+ The CLI uses structured enums that convert to library types:
114
+ - `AuditFormat` → `pysentry::AuditFormat`
115
+ - `SeverityLevel` → `pysentry::SeverityLevel`
116
+ - `VulnerabilitySourceType` → `pysentry::VulnerabilitySourceType`
117
+
118
+ This pattern ensures CLI arguments are validated and type-safe before reaching the library layer.
119
+
120
+ ## Dependency Graph Analysis
121
+
122
+ The tool builds comprehensive dependency graphs from `uv.lock`:
123
+ - **Direct dependencies**: Listed in pyproject.toml
124
+ - **Transitive dependencies**: Resolved by uv, tracked with parent relationships
125
+ - **Reachability analysis**: Determines which transitive deps are reachable from which direct deps
126
+ - **Source tracking**: Identifies package sources (PyPI, Git, Path, URL)
127
+
128
+ This enables filtering strategies like `--direct-only` while maintaining accurate vulnerability reporting.
129
+
130
+ ## Performance Considerations
131
+
132
+ - **Concurrent fetching**: Async operations for vulnerability data retrieval
133
+ - **Efficient matching**: In-memory indexing of vulnerability databases
134
+ - **Smart caching**: Reduces redundant API calls and parsing
135
+ - **Streaming**: Large ZIP files (PyPA database) processed incrementally
136
+ - **Memory usage**: Vulnerability databases kept in memory for fast matching
137
+
138
+ ## Common Development Tasks
139
+
140
+ When adding new functionality, consider these architectural touchpoints:
141
+ - **New vulnerability source**: Implement `VulnerabilityProvider` trait
142
+ - **New project format**: Implement `ProjectParser` trait and register
143
+ - **New output format**: Add variant to `AuditFormat` and implement generator
144
+ - **Performance optimization**: Focus on cache efficiency and async operations
145
+ - **Error handling**: Add new variants to `AuditError` enum as needed