|
| 1 | +# Migration to Runtime Dependency Management 🎉 |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +We have successfully migrated jNeqSim from bundled JAR files to **runtime dependency management**! This brings significant improvements: |
| 6 | + |
| 7 | +### ✅ Benefits |
| 8 | + |
| 9 | +- **📦 Smaller package size**: No more 50MB+ JAR files bundled in wheels |
| 10 | +- **⚡ Faster installs**: Package downloads and installs much faster |
| 11 | +- **🎯 Version flexibility**: Easy to specify NeqSim versions |
| 12 | +- **🏗️ Simpler CI/CD**: No JAR downloading during builds |
| 13 | +- **🔮 Streamlined architecture**: Direct GitHub downloads without complex caching |
| 14 | + |
| 15 | +## How It Works |
| 16 | + |
| 17 | +### Before (Old System) |
| 18 | +1. CI/CD downloads JAR files from GitHub releases |
| 19 | +2. JAR files bundled into Python package |
| 20 | +3. Large package distributed to users |
| 21 | +4. JARs loaded from package directory |
| 22 | + |
| 23 | +### After (New System) |
| 24 | +1. Dependencies resolved at **runtime** when first imported |
| 25 | +2. JARs downloaded directly from GitHub releases to temporary locations |
| 26 | +3. Support for multiple Java versions and NeqSim versions |
| 27 | +4. Simple, straightforward download process |
| 28 | + |
| 29 | +## Configuration |
| 30 | + |
| 31 | +Dependencies are configured in `jneqsim/dependencies.yaml`: |
| 32 | + |
| 33 | +```yaml |
| 34 | +neqsim: |
| 35 | + version: "latest" # or specific version like "3.1.0" |
| 36 | + |
| 37 | + # GitHub Releases source |
| 38 | + sources: |
| 39 | + github: |
| 40 | + enabled: true |
| 41 | + repository: "equinor/neqsim" |
| 42 | + # Different JARs for different Java versions |
| 43 | + assets: |
| 44 | + java8: "neqsim-{version}-Java8.jar" |
| 45 | + java11: "neqsim-{version}.jar" |
| 46 | + java21: "neqsim-{version}-Java21.jar" |
| 47 | + |
| 48 | +logging: |
| 49 | + level: "INFO" |
| 50 | + show_progress: true |
| 51 | +``` |
| 52 | +
|
| 53 | +## Usage (No Changes Required!) |
| 54 | +
|
| 55 | +The API remains exactly the same: |
| 56 | +
|
| 57 | +```python |
| 58 | +from jneqsim import neqsim |
| 59 | + |
| 60 | +# Works exactly as before! |
| 61 | +system = neqsim.thermo.system.SystemSrkEos() |
| 62 | +system.addComponent("methane", 100.0) |
| 63 | +``` |
| 64 | + |
| 65 | +### Advanced Usage |
| 66 | + |
| 67 | +```python |
| 68 | +from jneqsim.dependency_manager import NeqSimDependencyManager |
| 69 | + |
| 70 | +# Create manager |
| 71 | +manager = NeqSimDependencyManager() |
| 72 | + |
| 73 | +# Use specific version |
| 74 | +jar_path = manager.resolve_dependency(version="3.0.0", java_version=11) |
| 75 | +print(f"JAR downloaded to: {jar_path}") |
| 76 | +``` |
| 77 | + |
| 78 | +## Implementation Details |
| 79 | + |
| 80 | +### Core Components |
| 81 | + |
| 82 | +1. **`NeqSimDependencyManager`** (`jneqsim/dependency_manager.py`) |
| 83 | + - Handles dependency resolution |
| 84 | + - Downloads JARs from GitHub releases |
| 85 | + - Supports multiple Java versions |
| 86 | + - URL validation for security |
| 87 | + |
| 88 | +2. **Enhanced JVM Service** (`jneqsim/jvm_service.py`) |
| 89 | + - Uses dependency manager for JAR resolution |
| 90 | + - Maintains same API for backward compatibility |
| 91 | + - Graceful handling when JPype not available |
| 92 | + |
| 93 | +3. **Configuration** (`jneqsim/dependencies.yaml`) |
| 94 | + - YAML-based configuration |
| 95 | + - GitHub releases configuration |
| 96 | + - Logging configuration |
| 97 | + |
| 98 | +### Dependency Resolution Flow |
| 99 | + |
| 100 | +1. **Check version** - Determine NeqSim version to use |
| 101 | +2. **Resolve JAR type** - Select appropriate JAR for Java version |
| 102 | +3. **Download from GitHub** - Download JAR from GitHub releases |
| 103 | +4. **Validate security** - URL validation before download |
| 104 | +5. **Return path** - Provide path to downloaded JAR |
| 105 | + |
| 106 | +## Migration Impact |
| 107 | + |
| 108 | +### For Users |
| 109 | +- ✅ **No code changes required** - API remains the same |
| 110 | +- ✅ **Faster installation** - Much smaller package |
| 111 | +- ✅ **Automatic setup** - Dependency download on first use |
| 112 | +- ✅ **Simple architecture** - Direct downloads when needed |
| 113 | + |
| 114 | +### For Developers |
| 115 | +- ✅ **Simpler workflows** - No JAR downloading in CI/CD |
| 116 | +- ✅ **Easier testing** - Test with different NeqSim versions |
| 117 | +- ✅ **Better debugging** - Clear dependency resolution logs |
| 118 | +- ✅ **Streamlined code** - Simplified dependency manager |
| 119 | + |
| 120 | +### For CI/CD |
| 121 | +- ✅ **Faster builds** - No JAR downloads during build |
| 122 | +- ✅ **Smaller artifacts** - Package ~95% smaller |
| 123 | +- ✅ **Less complexity** - Fewer build steps |
| 124 | +- ✅ **Better reliability** - No dependency on external downloads during build |
| 125 | + |
| 126 | +## File Changes |
| 127 | + |
| 128 | +### Modified Files |
| 129 | +- `jneqsim/jvm_service.py` - Enhanced with dependency manager |
| 130 | +- `pyproject.toml` - Added PyYAML, removed JAR includes |
| 131 | +- `.github/workflows/tests.yaml` - Removed JAR download steps |
| 132 | +- `.github/workflows/publish.yaml` - Removed JAR download steps |
| 133 | + |
| 134 | +### New Files |
| 135 | +- `jneqsim/dependency_manager.py` - Core dependency management |
| 136 | +- `jneqsim/dependencies.yaml` - Configuration file |
| 137 | + |
| 138 | +### Removed Dependencies |
| 139 | +- No more bundled JAR files in package |
| 140 | +- Simplified CI/CD workflows |
| 141 | + |
| 142 | +## Future Enhancements |
| 143 | + |
| 144 | +Potential future improvements: |
| 145 | +1. Add local caching for frequently used JARs |
| 146 | +2. Support for Maven Central when NeqSim is published there |
| 147 | +3. Automatic cleanup of temporary files |
| 148 | +4. Version pinning and dependency locking |
| 149 | + |
| 150 | +## Testing |
| 151 | + |
| 152 | +Run the test script to verify everything works: |
| 153 | + |
| 154 | +```bash |
| 155 | +# Test basic dependency resolution |
| 156 | +python test_dependency_only.py |
| 157 | + |
| 158 | +# Test with full functionality (requires JPype1) |
| 159 | +python test_dependency_management.py |
| 160 | +``` |
| 161 | + |
| 162 | +## Troubleshooting |
| 163 | + |
| 164 | +### Manual Configuration |
| 165 | +Edit `jneqsim/dependencies.yaml` to customize: |
| 166 | +- NeqSim version |
| 167 | +- GitHub repository settings |
| 168 | +- Logging levels |
| 169 | + |
| 170 | +### Check Download Status |
| 171 | +```python |
| 172 | +from jneqsim.dependency_manager import NeqSimDependencyManager |
| 173 | +manager = NeqSimDependencyManager() |
| 174 | + |
| 175 | +# Test download |
| 176 | +jar_path = manager.resolve_dependency() |
| 177 | +print(f"Downloaded JAR to: {jar_path}") |
| 178 | +``` |
| 179 | + |
| 180 | +--- |
| 181 | + |
| 182 | +🎉 **Migration Complete!** Your Python package is now much more efficient with simplified runtime dependency management. |
0 commit comments