Skip to content

Commit 3594337

Browse files
radarherelatosha-maltba
authored andcommitted
Removed CONVERT helper variables
1 parent bb88d8d commit 3594337

File tree

2 files changed

+21
-37
lines changed

2 files changed

+21
-37
lines changed

Tests/helper.py

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -257,16 +257,22 @@ def netpbm_available():
257257
return bool(shutil.which("ppmquant") and shutil.which("ppmtogif"))
258258

259259

260-
def convert_available():
261-
return imagemagick_available() or graphicsmagick_available()
262-
263-
264-
def imagemagick_available():
265-
return bool(IMCONVERT and shutil.which(IMCONVERT[0]))
266-
260+
def magick_command():
261+
if sys.platform == "win32":
262+
imagemagick = os.environ.get("MAGICK_HOME", "")
263+
if imagemagick:
264+
imagemagick = [os.path.join(imagemagick, "convert.exe")]
265+
graphicsmagick = [os.path.join(imagemagick, "gm.exe"), "convert"]
266+
else:
267+
graphicsmagick = None
268+
else:
269+
imagemagick = ["convert"]
270+
graphicsmagick = ["gm", "convert"]
267271

268-
def graphicsmagick_available():
269-
return bool(GMCONVERT and shutil.which(GMCONVERT[0]))
272+
if imagemagick and shutil.which(imagemagick[0]):
273+
return imagemagick
274+
elif graphicsmagick and shutil.which(graphicsmagick[0]):
275+
return graphicsmagick
270276

271277

272278
def on_appveyor():
@@ -304,24 +310,6 @@ def is_mingw():
304310
return sysconfig.get_platform() == "mingw"
305311

306312

307-
if sys.platform == "win32":
308-
IMCONVERT = os.environ.get("MAGICK_HOME", "")
309-
GMCONVERT = None
310-
if IMCONVERT:
311-
IMCONVERT = [os.path.join(IMCONVERT, "convert.exe")]
312-
GMCONVERT = [os.path.join(IMCONVERT, "gm.exe"), "convert"]
313-
else:
314-
IMCONVERT = ["convert"]
315-
GMCONVERT = ["gm", "convert"]
316-
317-
if imagemagick_available():
318-
CONVERT = IMCONVERT
319-
elif graphicsmagick_available():
320-
CONVERT = GMCONVERT
321-
else:
322-
CONVERT = None
323-
324-
325313
class cached_property:
326314
def __init__(self, func):
327315
self.func = func

Tests/test_file_palm.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55

66
from PIL import Image
77

8-
from .helper import CONVERT, assert_image_equal, convert_available, hopper
9-
10-
_roundtrip = convert_available()
8+
from .helper import assert_image_equal, hopper, magick_command
119

1210

1311
def helper_save_as_palm(tmp_path, mode):
@@ -23,28 +21,26 @@ def helper_save_as_palm(tmp_path, mode):
2321
assert os.path.getsize(outfile) > 0
2422

2523

26-
def open_with_convert(tmp_path, f):
27-
if not convert_available():
28-
raise OSError()
29-
24+
def open_with_magick(magick, tmp_path, f):
3025
outfile = str(tmp_path / "temp.png")
3126
rc = subprocess.call(
32-
CONVERT + [f, outfile], stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT
27+
magick + [f, outfile], stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT
3328
)
3429
if rc:
3530
raise OSError
3631
return Image.open(outfile)
3732

3833

3934
def roundtrip(tmp_path, mode):
40-
if not _roundtrip:
35+
magick = magick_command()
36+
if not magick:
4137
return
4238

4339
im = hopper(mode)
4440
outfile = str(tmp_path / "temp.palm")
4541

4642
im.save(outfile)
47-
converted = open_with_convert(tmp_path, outfile)
43+
converted = open_with_magick(magick, tmp_path, outfile)
4844
assert_image_equal(converted, im)
4945

5046

0 commit comments

Comments
 (0)