diff --git a/README.md b/README.md index ebe621d..86f6b5f 100644 --- a/README.md +++ b/README.md @@ -12,18 +12,13 @@ terminal. Get `rich-pixels` from PyPI. ``` -pip install "rich-pixels[image]" +pip install rich-pixels ``` -Be sure to install the `image` extras if you want to display images! -Most functionality (currently) depends on these extras, so you'll probably need them. - ## Basic Usage ### Images -Requires the `image` extras to be installed (this will install `Pillow`). - #### Image from a file You can load an image file from a path using `from_image_path`: diff --git a/pyproject.toml b/pyproject.toml index f6dcc8a..2303287 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,12 +9,8 @@ packages = [{ include = "rich_pixels" }] [tool.poetry.dependencies] python = "^3.8" rich = "^12.0.0" -# -- 'image' extras -- pillow = "^9.0.0" -[tool.poetry.extras] -image = ["Pillow"] - [tool.poetry.group.dev.dependencies] black = "^22.10.0" mypy = "^0.990" diff --git a/rich_pixels/__init__.py b/rich_pixels/__init__.py index 5d27291..95bf8c6 100644 --- a/rich_pixels/__init__.py +++ b/rich_pixels/__init__.py @@ -1 +1 @@ -from rich_pixels._pixel import Pixels, PixelsError +from rich_pixels._pixel import Pixels diff --git a/rich_pixels/_pixel.py b/rich_pixels/_pixel.py index 19b3835..9449bb3 100644 --- a/rich_pixels/_pixel.py +++ b/rich_pixels/_pixel.py @@ -3,22 +3,12 @@ from pathlib import Path, PurePath from typing import Iterable, Mapping +from PIL import Image +from PIL.Image import Resampling from rich.console import Console, ConsoleOptions, RenderResult from rich.segment import Segment, Segments from rich.style import Style -try: - from PIL import Image - from PIL.Image import Resampling - - _PIL_INSTALLED = True -except ImportError: - _PIL_INSTALLED = False - - -class PixelsError(Exception): - pass - class Pixels: def __init__(self) -> None: @@ -51,12 +41,6 @@ def from_image_path( def _segments_from_image( image: "Image", resize: tuple[int, int] | None = None ) -> list[Segment]: - if not _PIL_INSTALLED: - raise PixelsError( - "Methods like from_image and from_image_path require " - "the 'image' extra dependencies to be installed." - ) - if resize: image = image.resize(resize, resample=Resampling.NEAREST) @@ -126,7 +110,7 @@ def __rich_console__( if __name__ == '__main__': console = Console() - images_path = Path(__file__).parent / "../.sample_data/images" + images_path = Path(__file__).parent / "../tests/.sample_data/images" pixels = Pixels.from_image_path(images_path / "bulbasaur.png") console.print(pixels)