chacc-dependency-manager 1.0.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.
- chacc_dependency_manager-1.0.0/LICENSE +21 -0
- chacc_dependency_manager-1.0.0/PKG-INFO +559 -0
- chacc_dependency_manager-1.0.0/README.md +502 -0
- chacc_dependency_manager-1.0.0/pyproject.toml +153 -0
- chacc_dependency_manager-1.0.0/setup.cfg +4 -0
- chacc_dependency_manager-1.0.0/src/chacc_dependency_manager.egg-info/PKG-INFO +559 -0
- chacc_dependency_manager-1.0.0/src/chacc_dependency_manager.egg-info/SOURCES.txt +14 -0
- chacc_dependency_manager-1.0.0/src/chacc_dependency_manager.egg-info/dependency_links.txt +1 -0
- chacc_dependency_manager-1.0.0/src/chacc_dependency_manager.egg-info/entry_points.txt +4 -0
- chacc_dependency_manager-1.0.0/src/chacc_dependency_manager.egg-info/requires.txt +32 -0
- chacc_dependency_manager-1.0.0/src/chacc_dependency_manager.egg-info/top_level.txt +1 -0
- chacc_dependency_manager-1.0.0/src/package/README.md +32 -0
- chacc_dependency_manager-1.0.0/src/package/__init__.py +38 -0
- chacc_dependency_manager-1.0.0/src/package/chacc.py +469 -0
- chacc_dependency_manager-1.0.0/src/package/cli.py +195 -0
- chacc_dependency_manager-1.0.0/tests/test_chacc_compatibility.py +52 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 ChaCC API Platform
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,559 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: chacc-dependency-manager
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Intelligent, incremental dependency resolution and caching for Python applications
|
|
5
|
+
Author-email: ChaCC API Platform <contact@chacc-api.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/Jonas1015/chacc-dependency-manager
|
|
8
|
+
Project-URL: Repository, https://github.com/Jonas1015/chacc-dependency-manager
|
|
9
|
+
Project-URL: Documentation, https://github.com/Jonas1015/chacc-dependency-manager/blob/main/src/package/README.md
|
|
10
|
+
Project-URL: Issues, https://github.com/Jonas1015/chacc-dependency-manager/issues
|
|
11
|
+
Keywords: dependency,resolution,pip,packaging,cache,requirements
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
23
|
+
Classifier: Topic :: System :: Software Distribution
|
|
24
|
+
Classifier: Topic :: Software Development :: Build Tools
|
|
25
|
+
Classifier: Topic :: System :: Archiving :: Packaging
|
|
26
|
+
Requires-Python: >=3.8
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
License-File: LICENSE
|
|
29
|
+
Requires-Dist: pip-tools>=7.0.0
|
|
30
|
+
Provides-Extra: full
|
|
31
|
+
Requires-Dist: pip-tools>=7.0.0; extra == "full"
|
|
32
|
+
Requires-Dist: pytest>=7.0.0; extra == "full"
|
|
33
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == "full"
|
|
34
|
+
Requires-Dist: black>=22.0.0; extra == "full"
|
|
35
|
+
Requires-Dist: flake8>=4.0.0; extra == "full"
|
|
36
|
+
Requires-Dist: mypy>=1.0.0; extra == "full"
|
|
37
|
+
Requires-Dist: twine>=4.0.0; extra == "full"
|
|
38
|
+
Requires-Dist: build>=1.0.0; extra == "full"
|
|
39
|
+
Provides-Extra: resolver
|
|
40
|
+
Requires-Dist: pip-tools>=7.0.0; extra == "resolver"
|
|
41
|
+
Provides-Extra: dev
|
|
42
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
43
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
|
|
44
|
+
Requires-Dist: black>=22.0.0; extra == "dev"
|
|
45
|
+
Requires-Dist: flake8>=4.0.0; extra == "dev"
|
|
46
|
+
Requires-Dist: mypy>=1.0.0; extra == "dev"
|
|
47
|
+
Requires-Dist: twine>=4.0.0; extra == "dev"
|
|
48
|
+
Requires-Dist: build>=1.0.0; extra == "dev"
|
|
49
|
+
Provides-Extra: test
|
|
50
|
+
Requires-Dist: pytest>=7.0.0; extra == "test"
|
|
51
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == "test"
|
|
52
|
+
Provides-Extra: lint
|
|
53
|
+
Requires-Dist: black>=22.0.0; extra == "lint"
|
|
54
|
+
Requires-Dist: flake8>=4.0.0; extra == "lint"
|
|
55
|
+
Requires-Dist: mypy>=1.0.0; extra == "lint"
|
|
56
|
+
Dynamic: license-file
|
|
57
|
+
|
|
58
|
+
# ChaCC Dependency Manager
|
|
59
|
+
|
|
60
|
+
**Smart dependency resolution with intelligent caching** - 20x faster than pip for repeated installs.
|
|
61
|
+
|
|
62
|
+
## 🎯 When to Use This
|
|
63
|
+
|
|
64
|
+
**Use this instead of pip when you:**
|
|
65
|
+
- Build Docker images frequently
|
|
66
|
+
- Have large/complex dependency trees
|
|
67
|
+
- Work with modular applications
|
|
68
|
+
- Need faster CI/CD pipelines
|
|
69
|
+
- Want automatic cache management
|
|
70
|
+
|
|
71
|
+
**Keep using pip for:**
|
|
72
|
+
- Simple single-file projects
|
|
73
|
+
- One-off dependency installs
|
|
74
|
+
- Basic development workflows
|
|
75
|
+
|
|
76
|
+
## 📦 Installation
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
# Basic installation (library only)
|
|
80
|
+
pip install chacc-dependency-manager
|
|
81
|
+
|
|
82
|
+
# With CLI commands (recommended)
|
|
83
|
+
pip install chacc-dependency-manager[resolver]
|
|
84
|
+
|
|
85
|
+
# Full development setup
|
|
86
|
+
pip install chacc-dependency-manager[full]
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## 🚀 Quick Usage
|
|
90
|
+
|
|
91
|
+
### Command Line (Easiest)
|
|
92
|
+
```bash
|
|
93
|
+
# Install from requirements.txt
|
|
94
|
+
cdm install -r requirements.txt
|
|
95
|
+
|
|
96
|
+
# Install specific packages
|
|
97
|
+
cdm install fastapi uvicorn
|
|
98
|
+
|
|
99
|
+
# Check cache status
|
|
100
|
+
cdm cache --info
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Python Code
|
|
104
|
+
```python
|
|
105
|
+
from chacc import DependencyManager
|
|
106
|
+
|
|
107
|
+
dm = DependencyManager()
|
|
108
|
+
await dm.resolve_dependencies()
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Docker
|
|
112
|
+
```dockerfile
|
|
113
|
+
FROM python:3.11-slim
|
|
114
|
+
RUN pip install chacc-dependency-manager[resolver]
|
|
115
|
+
COPY requirements.txt .
|
|
116
|
+
RUN cdm install
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## 💻 Command Reference
|
|
120
|
+
|
|
121
|
+
**Available commands:** `chacc-dependency-manager`, `chacc-dm`, or `cdm`
|
|
122
|
+
One of these can be used. A good example can be `cdm install -r requirements.txt` or `chacc-dependency-manager install -r requirements.txt`
|
|
123
|
+
|
|
124
|
+
### Install Dependencies
|
|
125
|
+
```bash
|
|
126
|
+
# From requirements file
|
|
127
|
+
cdm install -r requirements.txt
|
|
128
|
+
|
|
129
|
+
# Specific packages
|
|
130
|
+
cdm install fastapi uvicorn sqlalchemy
|
|
131
|
+
|
|
132
|
+
# Auto-discover all requirements
|
|
133
|
+
cdm install
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Resolve Only (No Install)
|
|
137
|
+
```bash
|
|
138
|
+
# Check what would be installed
|
|
139
|
+
cdm resolve
|
|
140
|
+
|
|
141
|
+
# Specific file
|
|
142
|
+
cdm resolve -r requirements-dev.txt
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Cache Management
|
|
146
|
+
```bash
|
|
147
|
+
# View cache info
|
|
148
|
+
cdm cache --info
|
|
149
|
+
|
|
150
|
+
# Clear all cache
|
|
151
|
+
cdm cache --clear
|
|
152
|
+
|
|
153
|
+
# Clear specific module
|
|
154
|
+
cdm cache --clear --module auth
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## 🚀 Why Use This Over Pip?
|
|
158
|
+
|
|
159
|
+
**Perfect for Docker builds and complex dependency trees:**
|
|
160
|
+
|
|
161
|
+
| Scenario | pip install | chacc-dependency-manager | Speed Improvement |
|
|
162
|
+
|----------|-------------|---------------------------|-------------------|
|
|
163
|
+
| **Docker rebuild (no changes)** | 45s | <2s | **22x faster** ⚡ |
|
|
164
|
+
| **CI/CD pipeline** | 60s | 3s | **20x faster** ⚡ |
|
|
165
|
+
| **Large monorepo** | 120s | 15s | **8x faster** ⚡ |
|
|
166
|
+
| **First run** | 45s | 45s | Same (expected) |
|
|
167
|
+
|
|
168
|
+
**Additional Benefits:**
|
|
169
|
+
- 🧠 **Smart caching** - Only resolves changed dependencies
|
|
170
|
+
- 📦 **Multi-file support** - Handles complex requirement structures
|
|
171
|
+
- 🔄 **Incremental updates** - No full reinstalls
|
|
172
|
+
- 🐳 **Docker-optimized** - Layer caching friendly
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
## 🔍 Auto-Discovery Patterns
|
|
176
|
+
|
|
177
|
+
### Supported Patterns
|
|
178
|
+
- `"requirements.txt"` - Single file (default)
|
|
179
|
+
- `"*.txt"` - All .txt files in search directories
|
|
180
|
+
- `"requirements-*.txt"` - Pattern matching
|
|
181
|
+
- `"deps.txt"` - Custom filename
|
|
182
|
+
- `"pyproject.toml"` - Future support planned
|
|
183
|
+
|
|
184
|
+
### Search Directories
|
|
185
|
+
1. Specified `modules_dir` (if exists)
|
|
186
|
+
2. Current directory (`.`)
|
|
187
|
+
|
|
188
|
+
### Example Directory Structures
|
|
189
|
+
|
|
190
|
+
```
|
|
191
|
+
# Single app
|
|
192
|
+
myapp/
|
|
193
|
+
├── requirements.txt # Auto-discovered
|
|
194
|
+
└── main.py
|
|
195
|
+
|
|
196
|
+
# Modular app
|
|
197
|
+
myapp/
|
|
198
|
+
├── modules/
|
|
199
|
+
│ ├── auth/
|
|
200
|
+
│ │ └── requirements.txt
|
|
201
|
+
│ ├── api/
|
|
202
|
+
│ │ └── requirements.txt
|
|
203
|
+
│ └── db/
|
|
204
|
+
│ └── requirements.txt
|
|
205
|
+
└── main.py
|
|
206
|
+
|
|
207
|
+
# Custom naming
|
|
208
|
+
myapp/
|
|
209
|
+
├── deps-web.txt # Web dependencies
|
|
210
|
+
├── deps-db.txt # Database dependencies
|
|
211
|
+
└── deps-dev.txt # Development dependencies
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
## 🐳 Pipeline & Container Caching
|
|
215
|
+
|
|
216
|
+
### 🐳 Docker Usage
|
|
217
|
+
|
|
218
|
+
**Simple, Cache-Friendly Docker Builds:**
|
|
219
|
+
|
|
220
|
+
```dockerfile
|
|
221
|
+
FROM python:3.11-slim
|
|
222
|
+
|
|
223
|
+
# Install the dependency manager
|
|
224
|
+
RUN pip install chacc-dependency-manager[resolver]
|
|
225
|
+
|
|
226
|
+
# Copy requirements files
|
|
227
|
+
COPY requirements*.txt ./
|
|
228
|
+
|
|
229
|
+
# Install with intelligent caching (only resolves when requirements change)
|
|
230
|
+
RUN cdm install
|
|
231
|
+
|
|
232
|
+
# Copy your application
|
|
233
|
+
COPY . .
|
|
234
|
+
|
|
235
|
+
# Run your app
|
|
236
|
+
CMD ["python", "app.py"]
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### CI/CD Pipeline Caching
|
|
240
|
+
|
|
241
|
+
#### GitHub Actions
|
|
242
|
+
```yaml
|
|
243
|
+
- name: Cache dependencies
|
|
244
|
+
uses: actions/cache@v3
|
|
245
|
+
with:
|
|
246
|
+
path: .dependency_cache
|
|
247
|
+
key: deps-${{ hashFiles('requirements*.txt', 'pyproject.toml') }}
|
|
248
|
+
restore-keys: |
|
|
249
|
+
deps-
|
|
250
|
+
|
|
251
|
+
- name: Install dependencies
|
|
252
|
+
run: cdm install
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
### Cache Persistence Strategies
|
|
256
|
+
|
|
257
|
+
#### 1. **Volume Mounts (Docker)**
|
|
258
|
+
```bash
|
|
259
|
+
# Mount cache volume
|
|
260
|
+
docker run -v $(pwd)/.dependency_cache:/app/.dependency_cache \
|
|
261
|
+
-v $(pwd):/app \
|
|
262
|
+
myapp cdm install
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
#### 2. **Multi-Stage Builds**
|
|
266
|
+
```dockerfile
|
|
267
|
+
# Stage 1: Resolve dependencies
|
|
268
|
+
FROM python:3.11-slim AS deps
|
|
269
|
+
RUN pip install chacc-dependency-manager[resolver]
|
|
270
|
+
COPY requirements*.txt ./
|
|
271
|
+
RUN cdm install
|
|
272
|
+
|
|
273
|
+
# Stage 2: Runtime
|
|
274
|
+
FROM python:3.11-slim
|
|
275
|
+
COPY --from=deps /root/.dependency_cache /app/.dependency_cache
|
|
276
|
+
# ... rest of your app
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
#### 3. **Cache Warming**
|
|
280
|
+
```bash
|
|
281
|
+
# Pre-warm cache for common scenarios
|
|
282
|
+
cdm install pip-tools setuptools pytest pytest-cov black flake8 mypy
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
### Cache Invalidation
|
|
286
|
+
|
|
287
|
+
The dependency manager automatically invalidates cache when:
|
|
288
|
+
- Requirements content changes (hash-based detection)
|
|
289
|
+
- Manual cache clearing via `dm.invalidate_cache()`
|
|
290
|
+
- Module-specific clearing via `dm.invalidate_module_cache(module_name)`
|
|
291
|
+
|
|
292
|
+
For forced rebuilds in pipelines:
|
|
293
|
+
```bash
|
|
294
|
+
# Force clean install
|
|
295
|
+
rm -rf .dependency_cache
|
|
296
|
+
cdm install
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
### Best Practices
|
|
300
|
+
|
|
301
|
+
1. **Cache Location**: Use consistent cache directories across environments
|
|
302
|
+
2. **Cache Keys**: Include all requirement files in cache keys
|
|
303
|
+
3. **Fallback**: Always have fallback to full resolution if cache fails
|
|
304
|
+
4. **Monitoring**: Log cache hit/miss ratios for optimization
|
|
305
|
+
5. **Security**: Clear cache when switching between branches with different deps
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
## 🛠️ Programmatic Resolution Features
|
|
309
|
+
|
|
310
|
+
### DependencyManager Class / API Referrence
|
|
311
|
+
|
|
312
|
+
#### Constructor
|
|
313
|
+
```python
|
|
314
|
+
DependencyManager(
|
|
315
|
+
cache_dir: Optional[str] = None, # Cache directory (default: ".dependency_cache")
|
|
316
|
+
logger: Optional[logging.Logger] = None, # Custom logger (default: built-in logging)
|
|
317
|
+
pre_resolve_hook: Optional[Callable] = None, # Pre-resolution callback
|
|
318
|
+
post_resolve_hook: Optional[Callable] = None, # Post-resolution callback
|
|
319
|
+
install_hook: Optional[Callable] = None # Custom installation callback
|
|
320
|
+
)
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
#### Methods
|
|
324
|
+
- `resolve_dependencies(modules_requirements=None, requirements_file_pattern="requirements.txt", search_dirs=None)`
|
|
325
|
+
- `invalidate_cache()`
|
|
326
|
+
- `invalidate_module_cache(module_name)`
|
|
327
|
+
- `calculate_module_hash(module_name, content)`
|
|
328
|
+
- `get_installed_packages()`
|
|
329
|
+
|
|
330
|
+
### Convenience Functions
|
|
331
|
+
- `re_resolve_dependencies(modules_requirements=None, requirements_file_pattern="requirements.txt", search_dirs=None)`
|
|
332
|
+
- `invalidate_dependency_cache()`
|
|
333
|
+
- `invalidate_module_cache(module_name)`
|
|
334
|
+
|
|
335
|
+
### Integration Custom Hooks
|
|
336
|
+
- `pre_resolve_hook`
|
|
337
|
+
- `post_resolve_hook`
|
|
338
|
+
- `install_hook`
|
|
339
|
+
|
|
340
|
+
For advanced use in applications:
|
|
341
|
+
|
|
342
|
+
```python
|
|
343
|
+
from chacc import DependencyManager
|
|
344
|
+
|
|
345
|
+
# Basic usage
|
|
346
|
+
dm = DependencyManager()
|
|
347
|
+
await dm.resolve_dependencies()
|
|
348
|
+
|
|
349
|
+
# With custom options
|
|
350
|
+
dm = DependencyManager(
|
|
351
|
+
cache_dir="/tmp/.cache",
|
|
352
|
+
logger=logging.getLogger("myapp")
|
|
353
|
+
)
|
|
354
|
+
|
|
355
|
+
# With integration hooks
|
|
356
|
+
dm = DependencyManager(
|
|
357
|
+
pre_resolve_hook=lambda name, reqs: print(f"Resolving {name}"),
|
|
358
|
+
post_resolve_hook=lambda name, packages: print(f"Resolved {len(packages)} packages")
|
|
359
|
+
)
|
|
360
|
+
|
|
361
|
+
await dm.resolve_dependencies()
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
### Custom Logger Integration
|
|
365
|
+
```python
|
|
366
|
+
import logging
|
|
367
|
+
from chacc import DependencyManager
|
|
368
|
+
|
|
369
|
+
logger = logging.getLogger("myapp")
|
|
370
|
+
dm = DependencyManager(logger=logger)
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
### Custom Search Directories
|
|
374
|
+
```python
|
|
375
|
+
# Search in specific directories
|
|
376
|
+
await dm.resolve_dependencies(
|
|
377
|
+
requirements_file_pattern="requirements.txt",
|
|
378
|
+
search_dirs=["./src", "./plugins", "./libs"]
|
|
379
|
+
)
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
### Selective Resolution
|
|
383
|
+
```python
|
|
384
|
+
# Only resolve specific modules
|
|
385
|
+
await dm.resolve_dependencies({
|
|
386
|
+
"web": "fastapi\nuvicorn",
|
|
387
|
+
"db": "sqlalchemy\npsycopg2"
|
|
388
|
+
})
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
The DependencyManager can be extended with custom hooks for integration with other systems:
|
|
392
|
+
|
|
393
|
+
### Pre/Post Resolution Hooks
|
|
394
|
+
```python
|
|
395
|
+
def log_resolution_start(module_name: str, requirements: str):
|
|
396
|
+
"""Called before resolving dependencies for a module."""
|
|
397
|
+
print(f"Starting resolution for {module_name}")
|
|
398
|
+
|
|
399
|
+
def log_resolution_complete(module_name: str, resolved_packages: dict):
|
|
400
|
+
"""Called after resolving dependencies for a module."""
|
|
401
|
+
print(f"Resolved {len(resolved_packages)} packages for {module_name}")
|
|
402
|
+
|
|
403
|
+
dm = DependencyManager(
|
|
404
|
+
pre_resolve_hook=log_resolution_start,
|
|
405
|
+
post_resolve_hook=log_resolution_complete
|
|
406
|
+
)
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
### Custom Installation Hook
|
|
410
|
+
```python
|
|
411
|
+
def custom_installer(resolved_packages: dict, installed_packages: set) -> bool:
|
|
412
|
+
"""Custom installation logic. Return True if successful."""
|
|
413
|
+
try:
|
|
414
|
+
# Your custom installation logic here
|
|
415
|
+
for package, version in resolved_packages.items():
|
|
416
|
+
if package.lower() not in installed_packages:
|
|
417
|
+
# Custom install logic
|
|
418
|
+
pass
|
|
419
|
+
return True
|
|
420
|
+
except Exception:
|
|
421
|
+
return False
|
|
422
|
+
|
|
423
|
+
dm = DependencyManager(install_hook=custom_installer)
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
## Integration Examples
|
|
427
|
+
|
|
428
|
+
### FastAPI Integration
|
|
429
|
+
```python
|
|
430
|
+
from fastapi import FastAPI
|
|
431
|
+
from chacc import DependencyManager
|
|
432
|
+
|
|
433
|
+
app = FastAPI()
|
|
434
|
+
|
|
435
|
+
@app.on_event("startup")
|
|
436
|
+
async def startup_event():
|
|
437
|
+
# Initialize dependency manager
|
|
438
|
+
dm = DependencyManager(
|
|
439
|
+
cache_dir=".fastapi_cache",
|
|
440
|
+
modules_dir="fastapi_modules"
|
|
441
|
+
)
|
|
442
|
+
|
|
443
|
+
# Resolve dependencies on startup
|
|
444
|
+
await dm.resolve_dependencies()
|
|
445
|
+
|
|
446
|
+
# Or resolve specific module dependencies
|
|
447
|
+
modules = {
|
|
448
|
+
"auth": "fastapi-security>=0.8.0\npython-jose>=3.3.0",
|
|
449
|
+
"database": "sqlalchemy>=1.4.0\nalembic>=1.7.0"
|
|
450
|
+
}
|
|
451
|
+
await dm.resolve_dependencies(modules)
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
### Django Integration
|
|
455
|
+
```python
|
|
456
|
+
# In Django settings.py or apps.py
|
|
457
|
+
from chacc import DependencyManager
|
|
458
|
+
|
|
459
|
+
# Initialize with Django-specific paths
|
|
460
|
+
dm = DependencyManager(
|
|
461
|
+
cache_dir=os.path.join(BASE_DIR, '.django_cache'),
|
|
462
|
+
modules_dir=os.path.join(BASE_DIR, 'django_apps'),
|
|
463
|
+
)
|
|
464
|
+
|
|
465
|
+
# In management command or startup hook
|
|
466
|
+
await dm.resolve_dependencies()
|
|
467
|
+
```
|
|
468
|
+
|
|
469
|
+
### Flask Integration
|
|
470
|
+
```python
|
|
471
|
+
from flask import Flask
|
|
472
|
+
from chacc import DependencyManager
|
|
473
|
+
|
|
474
|
+
app = Flask(__name__)
|
|
475
|
+
|
|
476
|
+
# Initialize dependency manager
|
|
477
|
+
dm = DependencyManager(
|
|
478
|
+
cache_dir=".flask_cache",
|
|
479
|
+
modules_dir="flask_plugins"
|
|
480
|
+
)
|
|
481
|
+
|
|
482
|
+
with app.app_context():
|
|
483
|
+
# Resolve dependencies
|
|
484
|
+
await dm.resolve_dependencies()
|
|
485
|
+
```
|
|
486
|
+
|
|
487
|
+
### Any Other App Integration Example
|
|
488
|
+
```python
|
|
489
|
+
from chacc import DependencyManager
|
|
490
|
+
|
|
491
|
+
# Another system can inject its own logger and hooks
|
|
492
|
+
dm = DependencyManager(
|
|
493
|
+
logger=custom_logger,
|
|
494
|
+
pre_resolve_hook=chacc_pre_resolve,
|
|
495
|
+
post_resolve_hook=chacc_post_resolve,
|
|
496
|
+
install_hook=chacc_installer
|
|
497
|
+
)
|
|
498
|
+
|
|
499
|
+
# Use as normal - hooks will be called automatically
|
|
500
|
+
await dm.resolve_dependencies()
|
|
501
|
+
```
|
|
502
|
+
|
|
503
|
+
## Architecture
|
|
504
|
+
|
|
505
|
+
### Cache Structure
|
|
506
|
+
|
|
507
|
+
```json
|
|
508
|
+
{
|
|
509
|
+
"module_caches": {
|
|
510
|
+
"authentication": {
|
|
511
|
+
"hash": "abc123...",
|
|
512
|
+
"packages": {"fastapi": "==0.116.1", "pydantic": "==2.5.0"},
|
|
513
|
+
"last_updated": "2024-01-01T12:00:00"
|
|
514
|
+
},
|
|
515
|
+
"feature_x": {
|
|
516
|
+
"hash": "def456...",
|
|
517
|
+
"packages": {"requests": "==2.31.0"},
|
|
518
|
+
"last_updated": "2024-01-01T12:05:00"
|
|
519
|
+
}
|
|
520
|
+
},
|
|
521
|
+
"backbone_hash": "ghi789...",
|
|
522
|
+
"combined_hash": "jkl012...",
|
|
523
|
+
"resolved_packages": {
|
|
524
|
+
"fastapi": "==0.116.1",
|
|
525
|
+
"pydantic": "==2.5.0",
|
|
526
|
+
"requests": "==2.31.0"
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
```
|
|
530
|
+
|
|
531
|
+
## Error Handling
|
|
532
|
+
|
|
533
|
+
The dependency manager provides comprehensive error handling:
|
|
534
|
+
|
|
535
|
+
- **Cache Corruption**: Automatically recreates corrupted cache files
|
|
536
|
+
- **Network Issues**: Graceful fallback for pip network problems
|
|
537
|
+
- **Version Conflicts**: Intelligent conflict resolution with logging
|
|
538
|
+
- **Permission Issues**: Clear error messages for file system problems
|
|
539
|
+
|
|
540
|
+
## Future Enhancements
|
|
541
|
+
|
|
542
|
+
- **Parallel Resolution**: Resolve multiple modules concurrently
|
|
543
|
+
- **Dependency Graph**: Visualize module dependencies
|
|
544
|
+
- **Security Scanning**: Integrate with vulnerability scanners
|
|
545
|
+
- **Container Optimization**: Optimize for containerized deployments
|
|
546
|
+
|
|
547
|
+
## Contributing
|
|
548
|
+
|
|
549
|
+
This dependency manager is designed to be published as a standalone package. To contribute:
|
|
550
|
+
|
|
551
|
+
1. Ensure all tests pass
|
|
552
|
+
2. Add comprehensive documentation
|
|
553
|
+
3. Follow semantic versioning
|
|
554
|
+
4. Maintain backward compatibility
|
|
555
|
+
|
|
556
|
+
|
|
557
|
+
## 📄 License
|
|
558
|
+
|
|
559
|
+
MIT License - See [LICENSE](LICENSE) file for details.
|