Skip to content

Commit 7168a4b

Browse files
authored
Refactor package installation (#8)
2 parents 03ba7c3 + 9c585f9 commit 7168a4b

File tree

5 files changed

+154
-87
lines changed

5 files changed

+154
-87
lines changed

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,31 @@ migration flow.
3232

3333
## 📦 Installation
3434

35-
You can install this package using pip:
35+
You can install this package using pip with different feature sets:
36+
37+
### Standard Installation (Validation Only)
38+
For basic migration validation without graph visualization:
39+
40+
```bash
41+
pip install pylembic[standard]
42+
```
43+
44+
### Full Installation (All Features)
45+
For complete functionality including graph visualization:
46+
47+
```bash
48+
pip install pylembic[all]
49+
```
50+
51+
### Basic Installation
52+
You can also install the basic package without optional dependencies:
3653

3754
```bash
3855
pip install pylembic
3956
```
4057

58+
**Note:** The `show_graph` functionality requires the `[all]` installation option as it depends on `matplotlib`. The core validation features (including branch detection) work with all installation options as they use `networkx` which is included by default.
59+
4160
## ⚙️ Usage
4261

4362
### 🧪 Testing

pyproject.toml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,24 @@ license = { file = "LICENSE" }
1010
requires-python = ">=3.11"
1111

1212
dependencies = [
13-
"alembic==1.16.4",
14-
"matplotlib==3.10.3",
13+
"alembic==1.16.5",
1514
"networkx==3.5",
16-
"typer==0.16.0",
15+
"typer==0.17.4",
16+
]
17+
18+
[project.optional-dependencies]
19+
standard = []
20+
all = [
21+
"matplotlib==3.10.6",
1722
]
1823

1924
[tool.uv]
2025
dev-dependencies = [
21-
"pytest-cov==6.2.1",
22-
"pytest-mock==3.14.1",
23-
"pytest==8.4.1",
24-
"ruff==0.12.4",
25-
"pre-commit==4.2.0",
26+
"pytest-cov==6.3.0",
27+
"pytest-mock==3.15.0",
28+
"pytest==8.4.2",
29+
"ruff==0.12.12",
30+
"pre-commit==4.3.0",
2631
]
2732

2833
[tool.ruff]

src/pylembic/cli.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ def show_graph(
5656
validator = Validator(migrations_path)
5757

5858
typer.echo("Visualizing migration graph...")
59-
validator.show_graph()
59+
try:
60+
validator.show_graph()
61+
except ImportError as exc:
62+
typer.secho(str(exc), fg=typer.colors.RED)
63+
raise typer.Exit(1) from exc
6064

6165

6266
if __name__ == "__main__":

src/pylembic/validator.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
from os import path
22

3-
import matplotlib.pyplot as plt
43
import networkx as nx
4+
5+
try:
6+
import matplotlib.pyplot as plt
7+
8+
HAS_MATPLOTLIB = True
9+
except ImportError:
10+
HAS_MATPLOTLIB = False
11+
512
from alembic.config import Config
613
from alembic.script import ScriptDirectory
714
from alembic.util import CommandError
@@ -183,6 +190,12 @@ def show_graph(self) -> None:
183190
"""
184191
Visualizes the migration dependency graph.
185192
"""
193+
if not HAS_MATPLOTLIB:
194+
raise ImportError(
195+
"Graph visualization requires matplotlib. "
196+
"Install with 'pip install pylembic[all]' to enable this feature."
197+
)
198+
186199
plt.figure(figsize=(12, 8))
187200
pos = nx.spring_layout(self.graph)
188201
labels = {node: f"{node[:8]}" for node in self.graph.nodes} # Short revision ID

0 commit comments

Comments
 (0)