Skip to content

Commit d22ae8d

Browse files
authored
Improve the error message when Pillow is not installed (#131)
* Improve the error message when Pillow is not installed * Improve the message * exclude `except ImportError` from coverage * Improve the test suite workflow * Improve the test suite workflow
1 parent fc91c90 commit d22ae8d

File tree

3 files changed

+48
-8
lines changed

3 files changed

+48
-8
lines changed

.github/workflows/test.yml

+23-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,29 @@ jobs:
8484
MINIO_PORT: 9000
8585
MINIO_SECURE: false
8686
run: hatch run test:run
87+
- name: store coverage files
88+
uses: actions/upload-artifact@v3
89+
with:
90+
name: coverage
91+
path: .coverage*
92+
retention-days: 1
93+
coverage:
94+
needs:
95+
- tests
96+
runs-on: ubuntu-latest
97+
steps:
98+
- uses: actions/checkout@v4
99+
- uses: actions/setup-python@v4
100+
with:
101+
python-version: "3.10"
102+
cache: "pip"
103+
- name: get coverage files
104+
uses: actions/download-artifact@v3
105+
with:
106+
name: coverage
107+
- name: Install Dependencies
108+
run: pip install hatch
87109
- name: Coverage Report
88-
run: hatch run test:cov
110+
run: hatch run cov:report
89111
- name: Upload coverage
90112
uses: codecov/codecov-action@v3

pyproject.toml

+18-6
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,19 @@ test = [
4747
"mypy ==1.5.1",
4848
"ruff ==0.0.292",
4949
"black ==23.9.1",
50-
"coverage >=7.0.0, <7.4.0",
5150
"fasteners ==0.19",
5251
"PyMySQL[rsa] >=1.0.2, <1.2.0",
5352
"psycopg2-binary >=2.9.5, <3.0.0",
5453
"Pillow >=9.4.0, <10.1.0",
5554
"python-multipart ==0.0.6",
56-
"fastapi >=0.92, <0.104",
55+
"sqlmodel >=0.0.11, <0.0.13",
56+
"fastapi >=0.92, <0.105",
5757
"Flask >=2.2, <2.3",
5858
"Flask-SQLAlchemy >=3.0,<3.2"
5959
]
60+
cov = [
61+
"coverage[toml] >=7.0.0, <7.4.0"
62+
]
6063
doc = [
6164
"mkdocs-material >=9.0.0, <10.0.0",
6265
"mkdocstrings[python] >=0.19.0, <0.24.0"
@@ -69,6 +72,7 @@ dev = [
6972
[tool.hatch.envs.default]
7073
features = [
7174
"test",
75+
"cov",
7276
"dev"
7377
]
7478
[tool.hatch.envs.default.scripts]
@@ -80,6 +84,7 @@ format = [
8084
[tool.hatch.envs.test]
8185
features = [
8286
"test",
87+
"cov",
8388
]
8489
[tool.hatch.envs.test.scripts]
8590
lint = [
@@ -101,11 +106,17 @@ sqla_version = ["1.4.x", "2.0.x"]
101106
matrix.sqla_version.dependencies = [
102107
{ value = "SQLAlchemy >=2.0, <2.1", if = ["2.0.x"] },
103108
{ value = "SQLAlchemy >=1.4, <1.5", if = ["1.4.x"] },
104-
{ value = "sqlmodel ==0.0.8", if = ["1.4.x"] },
105109
]
106-
matrix.sqla_version.scripts = [
107-
{ key = "run", value = 'coverage run -m pytest tests --ignore=tests/test_sqlmodel.py', if = ["2.0.x"] },
108-
{ key = "cov", value = '', if = ["2.0.x"] },
110+
111+
[tool.hatch.envs.cov]
112+
features = [
113+
"cov",
114+
]
115+
[tool.hatch.envs.cov.scripts]
116+
report = [
117+
"coverage combine",
118+
"coverage report --show-missing",
119+
"coverage xml"
109120
]
110121

111122
[tool.hatch.envs.docs]
@@ -126,6 +137,7 @@ show_missing = true
126137
exclude_lines = [
127138
"pragma: no cover",
128139
"if TYPE_CHECKING:",
140+
"except ImportError"
129141
]
130142

131143
[tool.coverage.run]

sqlalchemy_file/validators.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,13 @@ def __init__(
169169
max_aspect_ratio: Optional[float] = None,
170170
allowed_content_types: Optional[List[str]] = None,
171171
):
172-
from PIL import Image # type: ignore
172+
try:
173+
from PIL import Image # type: ignore
174+
except ImportError as e:
175+
raise ImportError(
176+
"The 'PIL' module is required for image processing, "
177+
"you can install it using 'pip install Pillow'."
178+
) from e
173179

174180
Image.init()
175181
super().__init__(

0 commit comments

Comments
 (0)