Skip to content

Commit

Permalink
Dropped support for Python 2
Browse files Browse the repository at this point in the history
  • Loading branch information
claudep committed Jul 28, 2020
1 parent 0badc75 commit 1633cc3
Show file tree
Hide file tree
Showing 24 changed files with 327 additions and 454 deletions.
4 changes: 1 addition & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
#
# Wand documentation build configuration file, created by
# sphinx-quickstart on Wed Sep 28 18:27:30 2011.
#
Expand Down Expand Up @@ -31,7 +29,7 @@
except ImportError:
pass

class Mock(object):
class Mock:
def __init__(self, name):
self.name = name

Expand Down
7 changes: 2 additions & 5 deletions docs/guide/draw.rst
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ The following example will draw points following a math function across a given
import math
with Drawing() as draw:
for x in xrange(0, 100):
for x in range(0, 100):
y = math.tan(x) * 4
draw.point(x, y + 50)
with Image(width=100, height=100, background=Color('lightblue')) as image:
Expand Down Expand Up @@ -491,12 +491,9 @@ exist to match there pop counterparts.
from wand.color import Color
from wand.image import Image
from wand.drawing import Drawing
from wand.compat import nested
from math import cos, pi, sin

with nested(Color('lightblue'),
Color('transparent'),
Drawing()) as (bg, fg, draw):
with Color('lightblue') as bg, Color('transparent') as fg, Drawing() as draw:
draw.stroke_width = 3
draw.fill_color = fg
for degree in range(0, 360, 15):
Expand Down
3 changes: 1 addition & 2 deletions docs/guide/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,7 @@ You can install it using :program:`dnf` command:

.. code-block:: console
$ dnf install python-wand # Python 2
$ dnf install python3-wand # Python 3
$ dnf install python3-wand
__ https://admin.fedoraproject.org/pkgdb/package/python-wand/

Expand Down
7 changes: 2 additions & 5 deletions docs/guide/read.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ The most frequently used way is just to open an image by its filename.
:class:`~wand.image.Image`'s constructor can take the parameter named
``filename``::

from __future__ import print_function
from wand.image import Image

with Image(filename='pikachu.png') as img:
Expand Down Expand Up @@ -51,7 +50,6 @@ contained in :class:`~StringIO.StringIO`, read by :func:`urllib2.urlopen()`),
it can be read by :class:`~wand.image.Image` constructor's ``file`` parameter.
It takes all file-like objects which implements :meth:`~file.read()` method::

from __future__ import print_function
from urllib2 import urlopen
from wand.image import Image

Expand All @@ -73,13 +71,12 @@ so it also can be used as an input stream for a downloaded image.
Read a blob
-----------

If you have just a binary string (:class:`str`) of the image, you can pass
If you have just a binary string (:class:`bytes`) of the image, you can pass
it into :class:`~wand.image.Image` constructor's ``blob`` parameter to read::

from __future__ import print_function
from wand.image import Image

with open('pikachu.png') as f:
with open('pikachu.png', 'rb') as f:
image_binary = f.read()

with Image(blob=image_binary) as img:
Expand Down
3 changes: 1 addition & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@ are lacking something we need:
Requirements
------------

- Python 2.7 or higher
- Python 3.3 or higher

- CPython 2.7 or higher
- CPython 3.3 or higher
- PyPy 1.5 or higher

Expand Down
10 changes: 5 additions & 5 deletions docs/test.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Using tox_
----------

Wand should be compatible with various Python implementations including
CPython 2.7, 3.3, PyPy. tox_ is a testing software that helps Python
CPython 3.3, PyPy. tox_ is a testing software that helps Python
packages to test on various Python implementations at a time.

It can be installed using :program:`pip`:
Expand All @@ -89,10 +89,10 @@ on multiple Python interpreters:

$ tox
GLOB sdist-make: /Users/emcconville/Desktop/wand/setup.py
py26 create: /Users/emcconville/Desktop/wand/.tox/py26
py26 installdeps: pytest
py26 sdist-inst: /Users/emcconville/Desktop/wand/.tox/dist/Wand-0.2.2.zip
py26 runtests: commands[0]
py37 create: /Users/emcconville/Desktop/wand/.tox/py37
py37 installdeps: pytest
py37 sdist-inst: /Users/emcconville/Desktop/wand/.tox/dist/Wand-0.2.2.zip
py37 runtests: commands[0]
...

You can use a double ``--`` to pass options to pytest:
Expand Down
1 change: 0 additions & 1 deletion docs/whatsnew/0.3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ EXIF
Wand now can read EXIF metadata from images through :attr:`metadata
<wand.image.Image>` property which is a mapping:

>>> from __future__ import print_function
>>> url = 'http://farm9.staticflickr.com/8282/7874109806_3fe0080ae4_o_d.jpg'
>>> with Image(file=urllib2.urlopen(url)) as i:
... for key, value in i.metadata.items():
Expand Down
7 changes: 1 addition & 6 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import os
import os.path
try:
from setuptools import setup
except ImportError:
from distutils.core import setup
from setuptools import setup

from wand.version import VERSION

Expand Down Expand Up @@ -59,8 +56,6 @@ def run_tests(self):
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
Expand Down
3 changes: 1 addition & 2 deletions tests/color_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from pytest import mark, raises

from wand.color import Color
from wand.compat import xrange
from wand.version import QUANTUM_DEPTH, MAGICK_VERSION_INFO # noqa


Expand Down Expand Up @@ -307,7 +306,7 @@ def test_hsl():


def color_memory_leak():
for _ in xrange(5000):
for _ in range(5000):
with Color('orange'):
pass
time.sleep(0.02)
Expand Down
1 change: 0 additions & 1 deletion tests/image_methods_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# These test cover the Image methods that directly map to C-API function calls.
#
Expand Down
4 changes: 1 addition & 3 deletions tests/image_properties_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# These test cover the Image attributes that directly map to C-API functions.
#
Expand All @@ -8,7 +7,6 @@
from pytest import mark, raises

from wand.color import Color
from wand.compat import string_type
from wand.exceptions import DelegateError
from wand.font import Font
from wand.image import Image
Expand Down Expand Up @@ -372,7 +370,7 @@ def test_metadata(fx_asset):
with Image(filename=str(fx_asset.join('beach.jpg'))) as img:
assert 52 <= len(img.metadata) <= 55
for key in img.metadata:
assert isinstance(key, string_type)
assert isinstance(key, str)
assert 'exif:ApertureValue' in img.metadata
assert 'exif:UnknownValue' not in img.metadata
assert img.metadata['exif:ApertureValue'] == '192/32'
Expand Down
18 changes: 5 additions & 13 deletions tests/image_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# These tests cover the basic I/O & pythonic interfaces of the Image class.
#
Expand All @@ -15,7 +14,6 @@

from wand.image import ClosedImageError, Image
from wand.color import Color
from wand.compat import PY3, text, text_type

try:
filesystem_encoding = sys.getfilesystemencoding()
Expand Down Expand Up @@ -120,12 +118,10 @@ def test_read_from_filename(fx_asset):
def test_read_from_unicode_filename(fx_asset, tmpdir):
"""https://github.com/emcconville/wand/issues/122"""
filename = '모나리자.jpg'
if not PY3:
filename = filename.decode('utf-8')
path = os.path.join(text_type(tmpdir), filename) # workaround py.path bug
path = os.path.join(str(tmpdir), filename) # workaround py.path bug
shutil.copyfile(str(fx_asset.join('mona-lisa.jpg')), path)
with Image() as img:
img.read(filename=text(path))
img.read(filename=path)
assert img.width == 402


Expand Down Expand Up @@ -172,11 +168,9 @@ def test_new_from_filename(fx_asset):
def test_new_from_unicode_filename(fx_asset, tmpdir):
"""https://github.com/emcconville/wand/issues/122"""
filename = '모나리자.jpg'
if not PY3:
filename = filename.decode('utf-8')
path = os.path.join(text_type(tmpdir), filename) # workaround py.path bug
path = os.path.join(str(tmpdir), filename) # workaround py.path bug
shutil.copyfile(str(fx_asset.join('mona-lisa.jpg')), path)
with Image(filename=text(path)) as img:
with Image(filename=path) as img:
assert img.width == 402


Expand Down Expand Up @@ -255,9 +249,7 @@ def test_save_to_filename(fx_asset):
reason='Unicode filesystem encoding needed')
def test_save_to_unicode_filename(fx_asset, tmpdir):
filename = '모나리자.jpg'
if not PY3:
filename = filename.decode('utf-8')
path = os.path.join(text_type(tmpdir), filename) # workaround py.path bug
path = os.path.join(str(tmpdir), filename) # workaround py.path bug
with Image(filename=str(fx_asset.join('mona-lisa.jpg'))) as orig:
orig.save(filename=path)
with Image(filename=path) as img:
Expand Down
2 changes: 0 additions & 2 deletions tests/sequence_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import print_function

from pytest import mark, raises

from wand.api import library
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py27, py38
envlist = py38

[testenv]
deps =
Expand Down
9 changes: 2 additions & 7 deletions wand/assertions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@
"""

import numbers
try:
from collections.abc import Sequence
except ImportError:
from collections import Sequence

from .compat import string_type
from collections.abc import Sequence


def assert_bool(**kwargs):
Expand Down Expand Up @@ -132,7 +127,7 @@ def assert_coordinate(**kwargs):

def assert_string(**kwargs):
for label, subject in kwargs.items():
if not isinstance(subject, string_type):
if not isinstance(subject, str):
fmt = "{0} must be a string, not {1}"
msg = fmt.format(label, repr(subject))
raise TypeError(msg)
Expand Down
6 changes: 3 additions & 3 deletions wand/color.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Color(Resource):
:param string: a color name string e.g. ``'rgb(255, 255, 255)'``,
``'#fff'``, ``'white'``. see `ImageMagick Color Names`_
doc also
:type string: :class:`basestring`
:type string: :class:`str`
.. versionchanged:: 0.3.0
:class:`Color` objects become hashable.
Expand Down Expand Up @@ -605,7 +605,7 @@ def magenta_quantum(self, value):

@property
def normalized_string(self):
"""(:class:`basestring`) The normalized string representation of
"""(:class:`str`) The normalized string representation of
the color. The same color is always represented to the same
string.
Expand Down Expand Up @@ -664,7 +664,7 @@ def red_quantum(self, value):

@property
def string(self):
"""(:class:`basestring`) The string representation of the color."""
"""(:class:`str`) The string representation of the color."""
with self:
color_string = library.PixelGetColorAsString(self.resource)
return text(color_string.value)
Expand Down

0 comments on commit 1633cc3

Please sign in to comment.