Skip to content

Commit

Permalink
Remove legacy PIL/Pillow compatibility try/except blocks
Browse files Browse the repository at this point in the history
Pillow is a managed dependency of omero-py
  • Loading branch information
sbesson committed Feb 7, 2024
1 parent cd3a1a6 commit c1f88b9
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 52 deletions.
12 changes: 1 addition & 11 deletions src/omero/gateway/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,7 @@
logger = logging.getLogger(__name__)
THISPATH = os.path.dirname(os.path.abspath(__file__))

try:
from PIL import Image, ImageDraw, ImageFont # see ticket:2597
except: # pragma: nocover
try:
# see ticket:2597
import Image
import ImageDraw
import ImageFont
except:
logger.error(
'No Pillow installed, line plots and split channel will fail!')
from PIL import Image, ImageDraw, ImageFont


def omero_type(val):
Expand Down
11 changes: 2 additions & 9 deletions src/omero/util/ROIDrawingUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@
Example code to draw a polyline on an image an display it in PIL::
try:
from PIL import Image, ImageDraw # see ticket:2597
except ImportError:
import Image, ImageDraw # see ticket:2597
from PIL import Image, ImageDraw
import ROI_utils
import ROIDrawingUtils
Expand All @@ -72,11 +69,7 @@
"""


try:
from PIL import Image, ImageDraw # see ticket:2597
except ImportError:
import Image
import ImageDraw # see ticket:2597
from PIL import Image, ImageDraw

import warnings

Expand Down
6 changes: 1 addition & 5 deletions src/omero/util/figureUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@
publication type of figures.
"""

try:
from PIL import Image, ImageDraw # see ticket:2597
except ImportError:
import Image
import ImageDraw
from PIL import Image, ImageDraw

WHITE = (255, 255, 255)

Expand Down
7 changes: 1 addition & 6 deletions src/omero/util/imageUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,7 @@
used for making figures.
"""

try:
from PIL import Image, ImageDraw, ImageFont # see ticket:2597
except ImportError:
import Image
import ImageDraw
import ImageFont # see ticket:2597
from PIL import Image, ImageDraw, ImageFont

import os.path
import omero.gateway
Expand Down
7 changes: 1 addition & 6 deletions src/omero/util/image_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@
Utility methods for dealing with scripts.
"""

try:
from PIL import Image, ImageDraw, ImageFont # see ticket:2597
except ImportError:
import Image
import ImageDraw
import ImageFont # see ticket:2597
from PIL import Image, ImageDraw, ImageFont

import os.path
import omero.gateway
Expand Down
13 changes: 2 additions & 11 deletions src/omero/util/script_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,7 @@
import sha
hash_sha1 = sha.new

try:
from PIL import Image # see ticket:2597
except: # pragma: nocover
try:
import Image # see ticket:2597
except:
logging.error('No Pillow installed')
from PIL import Image

# r,g,b,a colours for use in scripts.
COLOURS = {
Expand Down Expand Up @@ -918,10 +912,7 @@ def split_image(client, imageId, dir,
raw_pixels_store = session.createRawPixelsStore()
pixels_service = session.getPixelsService()

try:
from PIL import Image # see ticket:2597
except:
import Image # see ticket:2597
from PIL import Image

query_string = "select p from Pixels p join fetch p.image " \
"as i join fetch p.pixelsType where i.id='%s'" % imageId
Expand Down
5 changes: 1 addition & 4 deletions test/unit/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@
get_omero_userdir, get_omero_user_cache_dir, get_user_dir)
from omero_version import omero_version
import omero.util.image_utils as image_utils
try:
from PIL import Image
except ImportError:
import Image
from PIL import Image
import numpy


Expand Down

0 comments on commit c1f88b9

Please sign in to comment.