Skip to content

Commit

Permalink
Downgrading the ImagingLibrary class to a function named get_image_fa…
Browse files Browse the repository at this point in the history
…ctory, #101
  • Loading branch information
pylover committed Mar 26, 2018
1 parent d021096 commit aa2b880
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
22 changes: 9 additions & 13 deletions sqlalchemy_media/imaginglibs.py
@@ -1,19 +1,15 @@
from abc import ABCMeta, abstractmethod

from .exceptions import OptionalPackageRequirementError
from .optionals import ensure_wand


class ImagingLibrary(metaclass=ABCMeta):

@classmethod
def get_image_factory(self):
try:
ensure_wand()
from wand.image import Image as WandImage
return WandImage
except OptionalPackageRequirementError:
# Raising the exception again, because currently there is only one image library
# available, but after implementing the #97 the exception should be passed silently.
raise
def get_image_factory():
try:
ensure_wand()
from wand.image import Image as WandImage
return WandImage
except OptionalPackageRequirementError:
# Raising the exception again, because currently there is only one image library
# available, but after implementing the #97 the exception should be passed silently.
raise

5 changes: 3 additions & 2 deletions sqlalchemy_media/processors.py
Expand Up @@ -8,7 +8,7 @@
from sqlalchemy_media.mimetypes_ import guess_extension
from sqlalchemy_media.optionals import magic_mime_from_buffer, ensure_wand
from sqlalchemy_media.typing_ import Dimension
from sqlalchemy_media.imaginglibs import ImagingLibrary
from sqlalchemy_media.imaginglibs import get_image_factory


class Processor(object):
Expand Down Expand Up @@ -401,6 +401,7 @@ def process(self, descriptor: StreamDescriptor, context: dict):
# Ensuring the wand package is installed.
ensure_wand()
# noinspection PyPackageRequirements
from .imaginglibs import get_image_factory
from wand.image import Image as WandImage

# Copy the original info
Expand Down Expand Up @@ -472,7 +473,7 @@ class ImageAnalyzer(Analyzer):

def process(self, descriptor: StreamDescriptor, context: dict):

Image = ImagingLibrary.get_image_factory()
Image = get_image_factory()

# This processor requires seekable stream.
descriptor.prepare_to_read(backend='memory')
Expand Down

0 comments on commit aa2b880

Please sign in to comment.