Skip to content

Commit

Permalink
Remove pillow from dependencies (#1745)
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksanderWWW authored Apr 17, 2024
1 parent dc3217b commit 352b1ad
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 28 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- Removed `boto3` from requirements ([#1743](https://github.com/neptune-ai/neptune-client/pull/1743))
- Disabled `StringSet` `remove` and `clear` methods ([#1732](https://github.com/neptune-ai/neptune-client/pull/1732))
- Disable `fetch_last` and `download_last` ([#1731](https://github.com/neptune-ai/neptune-client/pull/1731))
- Removed `pillow` from requirements ([#1745](https://github.com/neptune-ai/neptune-client/pull/1745))
- Disabled file related functionality ([#1726](https://github.com/neptune-ai/neptune-client/pull/1726))
- Disabled file logging ([#1733](https://github.com/neptune-ai/neptune-client/pull/1733))

Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ swagger-spec-validator = ">=2.7.4"
protobuf = "^4.0.0"

# Built-in integrations
Pillow = ">=1.1.6"
GitPython = ">=2.0.8"
psutil = "*"
pandas = "*"
Expand Down
10 changes: 5 additions & 5 deletions src/neptune/attributes/series/file_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@
Optional,
)

from PIL import (
Image,
UnidentifiedImageError,
)

from neptune.attributes.series.series import Series
from neptune.exceptions import (
FileNotFound,
Expand Down Expand Up @@ -84,6 +79,11 @@ def _get_base64_image_content(file: File) -> str:
else:
file_content = file.content

from PIL import (
Image,
UnidentifiedImageError,
)

try:
with Image.open(io.BytesIO(file_content)):
...
Expand Down
3 changes: 2 additions & 1 deletion tests/e2e/standard/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from contextlib import contextmanager

import pytest
from PIL import Image

from neptune.exceptions import NeptuneUnsupportedFunctionalityException
from neptune.objects import NeptuneObject
Expand All @@ -39,6 +38,8 @@
tmp_context,
)

Image = pytest.importorskip("PIL.Image")

BASIC_SERIES_TYPES = (
make_parameters(["strings", "floats", "files"])
.xfail("files", reason="File funcitonality disabled", raises=NeptuneUnsupportedFunctionalityException)
Expand Down
10 changes: 6 additions & 4 deletions tests/e2e/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@

import numpy
from attr import dataclass
from PIL import Image
from PIL.PngImagePlugin import PngImageFile

import neptune
from neptune.internal.container_type import ContainerType
Expand Down Expand Up @@ -95,14 +93,18 @@ def tmp_context():
yield tmp


def generate_image(*, size: int) -> Image:
def generate_image(*, size: int) -> "Image": # noqa: F821
"""generate image of size in bytes"""
from PIL import Image

width = int(sqrt(size / 3)) # 3 bytes per one pixel in square image
random_numbers = numpy.random.rand(width, width, 3) * 255
return Image.fromarray(random_numbers.astype("uint8")).convert("RGB")


def image_to_png(*, image: Image) -> PngImageFile:
def image_to_png(*, image: "Image") -> "PngImageFile": # noqa: F821
from PIL.PngImagePlugin import PngImageFile

png_buf = io.BytesIO()
image.save(png_buf, format="png")
png_buf.seek(0)
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/neptune/new/attributes/series/test_file_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.
#
import io
from importlib.util import find_spec
from unittest import mock

import numpy
Expand Down Expand Up @@ -51,6 +52,7 @@ def test_log_type_error(self):
with self.assertRaises(TypeError):
FileSeries(MagicMock(), MagicMock()).log(value)

@pytest.mark.skipif(condition=find_spec("PIL") is None, reason="PIL not installed")
@patch("neptune.objects.neptune_object.get_operation_processor")
def test_log_content(self, get_operation_processor):
# given
Expand Down Expand Up @@ -89,6 +91,7 @@ def test_log_content(self, get_operation_processor):
wait=wait,
)

@pytest.mark.skipif(condition=find_spec("PIL") is None, reason="PIL not installed")
@patch("neptune.objects.neptune_object.get_operation_processor")
def test_assign_content(self, get_operation_processor):
# given
Expand Down Expand Up @@ -125,6 +128,7 @@ def test_assign_content(self, get_operation_processor):
]
)

@pytest.mark.skipif(condition=find_spec("PIL") is None, reason="PIL not installed")
@patch("neptune.objects.neptune_object.get_operation_processor")
def test_log_path(self, get_operation_processor):
# given
Expand Down Expand Up @@ -181,6 +185,7 @@ def generate_expected_call(wait, step):
]
)

@pytest.mark.skipif(condition=find_spec("PIL") is None, reason="PIL not installed")
def test_log_raise_not_image(self):
# given
path = self._random_path()
Expand All @@ -201,6 +206,7 @@ def test_log_raise_not_image(self):
with self.assertRaises(OperationNotSupported):
attr.log(stream)

@pytest.mark.skipif(condition=find_spec("PIL") is None, reason="PIL not installed")
def test_assign_raise_not_image(self):
# given
path = self._random_path()
Expand All @@ -221,6 +227,7 @@ def test_assign_raise_not_image(self):
with self.assertRaises(OperationNotSupported):
attr.assign([stream])

@pytest.mark.skipif(condition=find_spec("PIL") is None, reason="PIL not installed")
@mock.patch("neptune.internal.utils.limits._LOGGED_IMAGE_SIZE_LIMIT_MB", (10**-3))
def test_image_limit(self):
"""Test if we prohibit logging images greater than mocked 1KB limit size"""
Expand Down
25 changes: 11 additions & 14 deletions tests/unit/neptune/new/internal/utils/test_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,11 @@
from uuid import uuid4

import altair as alt
import matplotlib
import numpy
import pandas
import plotly.express as px
import pytest
import seaborn as sns
from bokeh.plotting import figure
from matplotlib import pyplot
from matplotlib.figure import Figure
from PIL import Image
from vega_datasets import data

from neptune.internal.utils.images import (
Expand All @@ -46,9 +41,11 @@
)
from tests.unit.neptune.new.utils.logging import format_log

matplotlib.use("agg")
Image = pytest.importorskip("PIL.Image")
Figure = pytest.importorskip("matplotlib.figure.Figure")


@pytest.mark.xfail(reason="Removing PIL from dependencies", raises=ModuleNotFoundError)
class TestImage(unittest.TestCase):

TEST_DIR = "/tmp/neptune/{}".format(uuid4())
Expand Down Expand Up @@ -111,9 +108,9 @@ def test_get_image_content_from_rgba_array(self):

def test_get_image_content_from_figure(self):
# given
pyplot.plot([1, 2, 3, 4])
pyplot.ylabel("some interesting numbers")
fig = pyplot.gcf()
pyplot.plot([1, 2, 3, 4]) # noqa: F821
pyplot.ylabel("some interesting numbers") # noqa: F821
fig = pyplot.gcf() # noqa: F821

# expect
self.assertEqual(get_image_content(fig), self._encode_figure(fig))
Expand Down Expand Up @@ -151,14 +148,14 @@ def test_get_image_content_from_tensorflow_tensor(self):

def test_get_image_content_from_seaborn_figure(self):
# given
grid = sns.relplot(numpy.random.randn(6, 4))
grid = sns.relplot(numpy.random.randn(6, 4)) # noqa: F821

# then
self.assertEqual(get_image_content(grid), self._encode_figure(grid))

def test_get_html_from_matplotlib_figure(self):
# given
fig = pyplot.figure()
fig = pyplot.figure() # noqa: F821
x = [
21,
22,
Expand All @@ -182,7 +179,7 @@ def test_get_html_from_matplotlib_figure(self):
50,
100,
]
pyplot.hist(x, bins=5)
pyplot.hist(x, bins=5) # noqa: F821

# when
result = get_html_content(fig)
Expand Down Expand Up @@ -259,7 +256,7 @@ def test_get_html_from_pandas(self):

def test_get_html_from_seaborn(self):
# given
grid = sns.relplot(numpy.random.randn(6, 4))
grid = sns.relplot(numpy.random.randn(6, 4)) # noqa: F821

# when
result = get_html_content(grid)
Expand All @@ -274,7 +271,7 @@ def _encode_pil_image(image: Image) -> bytes:
return image_buffer.getvalue()

@staticmethod
def _encode_figure(fig: Figure) -> bytes:
def _encode_figure(fig: Figure) -> bytes: # noqa: F821
with io.BytesIO() as image_buffer:
fig.savefig(image_buffer, format="PNG", bbox_inches="tight")
return image_buffer.getvalue()
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/neptune/new/test_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
from tempfile import TemporaryDirectory
from unittest.mock import patch

import PIL
import pytest

from neptune import (
Expand Down Expand Up @@ -69,6 +68,8 @@
from neptune.types.sets.string_set import StringSet as StringSetVal
from tests.unit.neptune.new.utils.file_helpers import create_file

PIL = pytest.importorskip("PIL")


class Obj:
pass
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/neptune/new/types/atoms/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
)

import numpy
import pytest
from bokeh.plotting import figure
from PIL import Image

from neptune.exceptions import (
NeptuneException,
Expand All @@ -36,6 +36,8 @@
from neptune.types import File
from tests.e2e.utils import tmp_context

Image = pytest.importorskip("PIL.Image")


class TestFile(unittest.TestCase):
def test_file_constructor(self):
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/neptune/new/types/test_file_casting.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
from datetime import datetime

import numpy
import pytest
from bokeh.plotting import figure
from PIL import Image

from neptune.types import (
Datetime,
Expand All @@ -31,6 +31,8 @@
from neptune.types.type_casting import cast_value
from tests.unit.neptune.new.attributes.test_attribute_base import TestAttributeBase

Image = pytest.importorskip("PIL.Image")


class TestTypeCasting(TestAttributeBase):
def test_cast_neptune_values(self):
Expand Down

0 comments on commit 352b1ad

Please sign in to comment.