Skip to content

Commit

Permalink
Remove image extras
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenburns committed Nov 10, 2022
1 parent 4cd39c3 commit 48ed9b3
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 30 deletions.
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`:
Expand Down
4 changes: 0 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion rich_pixels/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from rich_pixels._pixel import Pixels, PixelsError
from rich_pixels._pixel import Pixels
22 changes: 3 additions & 19 deletions rich_pixels/_pixel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 48ed9b3

Please sign in to comment.