Skip to content

Commit

Permalink
Improve the error message when Pillow is not installed (#131)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jowilf authored Nov 27, 2023
1 parent fc91c90 commit d22ae8d
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 8 deletions.
24 changes: 23 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,29 @@ jobs:
MINIO_PORT: 9000
MINIO_SECURE: false
run: hatch run test:run
- name: store coverage files
uses: actions/upload-artifact@v3
with:
name: coverage
path: .coverage*
retention-days: 1
coverage:
needs:
- tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: "3.10"
cache: "pip"
- name: get coverage files
uses: actions/download-artifact@v3
with:
name: coverage
- name: Install Dependencies
run: pip install hatch
- name: Coverage Report
run: hatch run test:cov
run: hatch run cov:report
- name: Upload coverage
uses: codecov/codecov-action@v3
24 changes: 18 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,19 @@ test = [
"mypy ==1.5.1",
"ruff ==0.0.292",
"black ==23.9.1",
"coverage >=7.0.0, <7.4.0",
"fasteners ==0.19",
"PyMySQL[rsa] >=1.0.2, <1.2.0",
"psycopg2-binary >=2.9.5, <3.0.0",
"Pillow >=9.4.0, <10.1.0",
"python-multipart ==0.0.6",
"fastapi >=0.92, <0.104",
"sqlmodel >=0.0.11, <0.0.13",
"fastapi >=0.92, <0.105",
"Flask >=2.2, <2.3",
"Flask-SQLAlchemy >=3.0,<3.2"
]
cov = [
"coverage[toml] >=7.0.0, <7.4.0"
]
doc = [
"mkdocs-material >=9.0.0, <10.0.0",
"mkdocstrings[python] >=0.19.0, <0.24.0"
Expand All @@ -69,6 +72,7 @@ dev = [
[tool.hatch.envs.default]
features = [
"test",
"cov",
"dev"
]
[tool.hatch.envs.default.scripts]
Expand All @@ -80,6 +84,7 @@ format = [
[tool.hatch.envs.test]
features = [
"test",
"cov",
]
[tool.hatch.envs.test.scripts]
lint = [
Expand All @@ -101,11 +106,17 @@ sqla_version = ["1.4.x", "2.0.x"]
matrix.sqla_version.dependencies = [
{ value = "SQLAlchemy >=2.0, <2.1", if = ["2.0.x"] },
{ value = "SQLAlchemy >=1.4, <1.5", if = ["1.4.x"] },
{ value = "sqlmodel ==0.0.8", if = ["1.4.x"] },
]
matrix.sqla_version.scripts = [
{ key = "run", value = 'coverage run -m pytest tests --ignore=tests/test_sqlmodel.py', if = ["2.0.x"] },
{ key = "cov", value = '', if = ["2.0.x"] },

[tool.hatch.envs.cov]
features = [
"cov",
]
[tool.hatch.envs.cov.scripts]
report = [
"coverage combine",
"coverage report --show-missing",
"coverage xml"
]

[tool.hatch.envs.docs]
Expand All @@ -126,6 +137,7 @@ show_missing = true
exclude_lines = [
"pragma: no cover",
"if TYPE_CHECKING:",
"except ImportError"
]

[tool.coverage.run]
Expand Down
8 changes: 7 additions & 1 deletion sqlalchemy_file/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,13 @@ def __init__(
max_aspect_ratio: Optional[float] = None,
allowed_content_types: Optional[List[str]] = None,
):
from PIL import Image # type: ignore
try:
from PIL import Image # type: ignore
except ImportError as e:
raise ImportError(
"The 'PIL' module is required for image processing, "
"you can install it using 'pip install Pillow'."
) from e

Image.init()
super().__init__(
Expand Down

0 comments on commit d22ae8d

Please sign in to comment.