|
| 1 | +# PythonDepManager |
| 2 | + |
| 3 | +Python dependency management system for CommunityScripts plugins. |
| 4 | + |
| 5 | +This plugin provides an easy way to install and manage Python package dependencies in your plugins without manual user interaction. |
| 6 | + |
| 7 | +Don't worry about missing dependencies and wrong or conflicting versions anymore. |
| 8 | + |
| 9 | +## Features |
| 10 | + |
| 11 | +- 🚀 Automatic dependency installation and management |
| 12 | + - Users won't have to manually install dependencies |
| 13 | + |
| 14 | +- 🔒 Isolated dependency versions |
| 15 | + - Specify exact version of your dependencies without worrying about conflicts with other plugin installs |
| 16 | + |
| 17 | +- 📦 Support for multiple package sources: |
| 18 | + - PyPI packages with version constraints |
| 19 | + - Git repositories (with branch/tag/commit support) |
| 20 | + - Custom import names for metapackages |
| 21 | +- 🔄 Automatic version resolution and compatibility checking |
| 22 | +- 🧹 Easy dependency cleanup and flushing |
| 23 | + |
| 24 | +## Installation |
| 25 | + |
| 26 | +1. Add PythonDepManager as a requirement in your plugin's YAML file: |
| 27 | + |
| 28 | +```yaml |
| 29 | +name: YourPlugin |
| 30 | +# requires: PythonDepManager |
| 31 | +description: Your plugin description |
| 32 | +``` |
| 33 | +
|
| 34 | +## Usage |
| 35 | +
|
| 36 | +### Basic Usage |
| 37 | +
|
| 38 | +In your plugin's Python code, import and use the dependency manager: |
| 39 | +
|
| 40 | +```python |
| 41 | +from PythonDepManager import ensure_import |
| 42 | +# Install and import a package with specific version |
| 43 | +ensure_import("requests==2.26.0") |
| 44 | + |
| 45 | +# Afterwards imports will use only the requested versions |
| 46 | +import requests |
| 47 | +``` |
| 48 | + |
| 49 | +### Advanced Usage |
| 50 | + |
| 51 | +#### Minimum Versions |
| 52 | + |
| 53 | +Define a minimum version to use. This will either use any cached version |
| 54 | +which matches or install the latest |
| 55 | + |
| 56 | +```python |
| 57 | +from PythonDepManager import ensure_import |
| 58 | +ensure_import("requests>=2.26.0") |
| 59 | +``` |
| 60 | + |
| 61 | +#### Custom Import Names/Meta Packages |
| 62 | + |
| 63 | +Use custom import names for packages with different import names or meta packages |
| 64 | + |
| 65 | +```python |
| 66 | +from PythonDepManager import ensure_import |
| 67 | +# Install beautifulsoup4 but import as bs4 |
| 68 | +ensure_import("bs4:beautifulsoup4==4.9.3") |
| 69 | +``` |
| 70 | + |
| 71 | +```python |
| 72 | +from PythonDepManager import ensure_import |
| 73 | +# Install stashapp-tools but import as stashapi |
| 74 | +ensure_import("stashapi:stashapp-tools==0.2.58") |
| 75 | +``` |
| 76 | + |
| 77 | +#### Git Repository Dependencies |
| 78 | + |
| 79 | +Install packages directly from Git repositories: |
| 80 | + |
| 81 | +```python |
| 82 | +from PythonDepManager import ensure_import |
| 83 | +# Install from a Git repository |
| 84 | +ensure_import("stashapi@git+https://github.com/user/repo.git") |
| 85 | + |
| 86 | +# Install specific branch/tag |
| 87 | +ensure_import("stashapi@git+https://github.com/user/repo.git@main") |
| 88 | + |
| 89 | +# Install specific commit |
| 90 | +ensure_import("stashapi@git+https://github.com/user/repo.git@ad483dc") |
| 91 | +``` |
| 92 | + |
| 93 | +### Multiple Imports |
| 94 | + |
| 95 | +Handle multiple different requirements for imports: |
| 96 | + |
| 97 | +```python |
| 98 | +from PythonDepManager import ensure_import |
| 99 | +ensure_import( |
| 100 | + "requests" |
| 101 | + "bs4:beautifulsoup4==4.9.3" |
| 102 | + "stashapi:stashapp-tools==0.2.58" |
| 103 | + "someothermodule>=0.1" |
| 104 | +) |
| 105 | +``` |
| 106 | + |
| 107 | +### Managing Dependencies |
| 108 | + |
| 109 | +To flush all cached dependencies: |
| 110 | + |
| 111 | +```python |
| 112 | +from PythonDepManager import flush_dependencies |
| 113 | +flush_dependencies() |
| 114 | +``` |
| 115 | + |
| 116 | +## Requirements |
| 117 | + |
| 118 | +- Git (for Git repository dependencies) |
| 119 | +- pip (Python package installer) |
0 commit comments