Skip to content

Commit dedfbb7

Browse files
committed
The WandAnalyzer class has been removed, some documentation is also updated, #112, #113
1 parent 6f04d22 commit dedfbb7

File tree

6 files changed

+7
-154
lines changed

6 files changed

+7
-154
lines changed

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
dependencies = [
1313
'sqlalchemy >= 1.1.0b3',
14+
'pillow',
1415
]
1516

1617

sqlalchemy_media/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
StreamCloserDescriptor, LocalFileSystemDescriptor, UrlDescriptor, \
88
CgiFieldStorageDescriptor, AttachableDescriptor
99
from .processors import Processor, ImageProcessor, Analyzer, MagicAnalyzer, \
10-
WandAnalyzer, Validator, ContentTypeValidator, ImageValidator, \
11-
ImageAnalyzer
10+
Validator, ContentTypeValidator, ImageValidator, ImageAnalyzer
1211

1312

1413
__version__ = '0.16.0'

sqlalchemy_media/exceptions.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ class OptionalPackageRequirementError(SqlAlchemyMediaException):
9797

9898
__optional_packages__ = [
9999
'python-magic >= 0.4.12',
100-
'wand >= 0.4.3',
101100
'requests-aws4auth >= 0.9',
102101
'requests-aliyun >= 0.2.5'
103102
]

sqlalchemy_media/optionals.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,6 @@ def magic_mime_from_buffer(buffer: bytes) -> str:
4040
return magic.from_buffer(buffer, mime=True)
4141

4242

43-
# wand image
44-
45-
try:
46-
import wand
47-
except ImportError: # pragma: no cover
48-
wand = None
49-
50-
51-
def ensure_wand():
52-
"""
53-
54-
.. warning:: :exc:`.OptionalPackageRequirementError` will be raised if
55-
``wand`` is not installed.
56-
57-
"""
58-
59-
if wand is None: # pragma: no cover
60-
raise OptionalPackageRequirementError('wand')
61-
62-
6343
# requests-aws4auth
6444
try:
6545
from requests_aws4auth import AWS4Auth

sqlalchemy_media/processors.py

Lines changed: 4 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
AspectRatioValidationError, AnalyzeError
99
from .helpers import validate_width_height_ratio, deprecated
1010
from .mimetypes_ import guess_extension, guess_type
11-
from .optionals import magic_mime_from_buffer, ensure_wand
11+
from .optionals import magic_mime_from_buffer
1212
from .typing_ import Dimension
1313

1414

@@ -95,89 +95,6 @@ def process(self, descriptor: StreamDescriptor, context: dict):
9595
)
9696

9797

98-
@deprecated
99-
class WandAnalyzer(Analyzer):
100-
"""
101-
.. deprecated:: 0.16
102-
103-
.. versionadded:: 0.4
104-
105-
.. versionchanged:: 0.5
106-
107-
- Inherited from :class:`.Analyzer`
108-
- The ``analyze`` method renamed to ``process`` to override the parent
109-
method.
110-
111-
Analyze an image using ``wand``.
112-
113-
.. warning:: Installing ``wand`` is required for using this class.
114-
otherwise, an :exc:`.OptionalPackageRequirementError` will be
115-
raised.
116-
117-
Use it as follow
118-
119-
.. testcode::
120-
121-
from sqlalchemy import TypeDecorator, Unicode, Column, Integer
122-
from sqlalchemy.ext.declarative import declarative_base
123-
from sqlalchemy.dialects.postgresql import JSONB
124-
125-
from sqlalchemy_media import Image, WandAnalyzer
126-
127-
128-
class ProfileImage(Image):
129-
__pre_processors__ = WandAnalyzer()
130-
131-
Base = declarative_base()
132-
133-
class Member(Base):
134-
__tablename__ = 'person'
135-
136-
id = Column(Integer, primary_key=True)
137-
avatar = Column(ProfileImage.as_mutable(JSONB))
138-
139-
The use it inside :class:`.ContextManager` context:
140-
141-
::
142-
143-
from sqlalchemy_media import ContextManager
144-
145-
session = <....>
146-
147-
with ContextManager(session):
148-
me = Member(avatar=ProfileImage.create_from('donkey.jpg'))
149-
print(me.avatar.width)
150-
print(me.avatar.height)
151-
print(me.avatar.content_type)
152-
153-
.. note:: This object currently selects ``width``, ``height`` and
154-
``mimetype`` of the image.
155-
156-
"""
157-
158-
def process(self, descriptor: StreamDescriptor, context: dict):
159-
ensure_wand()
160-
from wand.image import Image as WandImage
161-
from wand.exceptions import WandException
162-
163-
# This processor requires seekable stream.
164-
descriptor.prepare_to_read(backend='memory')
165-
166-
try:
167-
with WandImage(file=descriptor)as img:
168-
context.update(
169-
width=img.width,
170-
height=img.height,
171-
content_type=img.mimetype
172-
)
173-
174-
except WandException:
175-
raise AnalyzeError(str(WandException))
176-
177-
# prepare for next processor, calling this method is not bad.
178-
descriptor.prepare_to_read(backend='memory')
179-
180-
18198
class Validator(Processor):
18299
"""
183100
@@ -360,39 +277,16 @@ class ImageProcessor(Processor):
360277
- If you pass both ``width`` and ``height``, aspect ratio may not be
361278
preserved.
362279
363-
:param fmt: This argument will be directly passing to ``Wand`` or
364-
``Pillow``. so, for list of available choices, see:
365-
`ImageMagic Documentation
366-
<http://www.imagemagick.org/script/formats.php>`_
367-
280+
:param format: The image format. i.e jpeg, gif, png
368281
:param width: The new image width.
369282
:param height: The new image height.
370283
:param crop: Used to crop the image.
371284
372285
.. versionadded:: 0.6
373286
374-
The crop dimension as a dictionary containing the keys described
375-
`here <http://docs.wand-py.org/en/0.4.1/wand/image.html#wand.image.BaseImage.crop>`_.
376-
377-
Including you can
378-
use percent ``%`` sing to automatically calculate the values from original
379-
image dimension::
287+
The crop argument is 4-tuple of (left, top, right, bottom)
380288
381-
ImageProcessor(crop=dict(width='50%', height='50%', gravity='center'))
382-
ImageProcessor(crop=dict(width='10%', height='10%', gravity='south_east'))
383-
384-
Or::
385-
386-
ImageProcessor(crop=dict(
387-
top='10%',
388-
bottom='10%',
389-
left='10%',
390-
right='10%',
391-
width='80%',
392-
height='80%'
393-
))
394-
395-
Included from wand documentation::
289+
ImageProcessor(crop=(10, 10, 120, 230))
396290
397291
+--------------------------------------------------+
398292
| ^ ^ |
@@ -410,12 +304,6 @@ class ImageProcessor(Processor):
410304
| <--------------- right ----------> |
411305
+--------------------------------------------------+
412306
413-
.. seealso::
414-
415-
- ``crop`` `method <http://docs.wand-py.org/en/0.4.1/wand/image.html#wand.image.BaseImage.crop>`_. # noqa
416-
- ``gravity`` `argument <http://docs.wand-py.org/en/0.4.1/wand/image.html#wand.image.GRAVITY_TYPES>`_.
417-
- `Wand <http://docs.wand-py.org/>`_
418-
419307
"""
420308

421309
def __init__(self, fmt: str = None, width: int = None, height: int = None, crop=None):
@@ -489,9 +377,6 @@ class ImageAnalyzer(Analyzer):
489377
Analyze an image using available image library by calling the
490378
:classmethod:`.imaging.ImagingLibrary.get_available()
491379
492-
.. warning:: If none of ``Wand`` or ``Pillow`` are installed the
493-
:exc:`.OptionalPackageRequirementError` will be raised.
494-
495380
.. note:: This object currently selects ``width``, ``height`` and
496381
``mimetype`` of an image.
497382

sqlalchemy_media/tests/test_analyzers.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import io
44
from os.path import dirname, abspath, join
55

6-
from sqlalchemy_media.processors import MagicAnalyzer, WandAnalyzer
6+
from sqlalchemy_media.processors import MagicAnalyzer
77
from sqlalchemy_media.descriptors import AttachableDescriptor
88

99

@@ -36,17 +36,6 @@ def test_magic(self):
3636
analyzer.process(d, ctx)
3737
self.assertEqual(ctx['content_type'], 'image/png')
3838

39-
def test_wand(self):
40-
analyzer = WandAnalyzer()
41-
with AttachableDescriptor(self.cat_jpeg) as d:
42-
ctx = {}
43-
analyzer.process(d, ctx)
44-
self.assertDictEqual(ctx, {
45-
'width': 640,
46-
'height': 480,
47-
'content_type': 'image/jpeg'
48-
})
49-
5039

5140
if __name__ == '__main__': # pragma: no cover
5241
unittest.main()

0 commit comments

Comments
 (0)