Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
af770a6
Drop support for EOL Python 2.7
hugovk Sep 26, 2019
538d9e2
Upgrade Python syntax with pyupgrade --py3-plus
hugovk Sep 30, 2019
74d2767
Remove duplicate line
hugovk Oct 2, 2019
810b61e
Reinstate and simplify parallel auto-detection
hugovk Oct 2, 2019
7e3156e
Updated IFDRational operators
radarhere Oct 7, 2019
865b17d
Remove Python 2-compatibility code
hugovk Oct 7, 2019
4382413
Remove redundant bytearray
hugovk Oct 7, 2019
6cd99fc
Merge branch 'master' into rm-2.7
radarhere Oct 8, 2019
84e53e3
Simplify using subprocess.DEVNULL
hugovk Oct 8, 2019
3a34081
Simplify temporary directory cleanup
hugovk Oct 8, 2019
0caa48b
Remove redundant __future__ from docs
hugovk Oct 8, 2019
e118de9
Remove redundant __ne__ method
hugovk Oct 8, 2019
3e24c5f
Replace isStringType(t) with isinstance(t, str)
hugovk Oct 8, 2019
4140cd8
Merge branch 'master' into rm-2.7
radarhere Oct 12, 2019
3e3a737
Merge remote-tracking branch 'upstream/master' into rm-2.7
hugovk Oct 12, 2019
23fa3c6
Remove outdated OS scripts, point docs to Dockerfiles
hugovk Oct 12, 2019
3dac6e2
Replace ImageShow.which() with stdlib
hugovk Oct 12, 2019
28ff798
Merge branch 'master' into rm-2.7
hugovk Oct 15, 2019
40133cf
Merge branch 'master' into rm-2.7
hugovk Oct 26, 2019
cc63f66
Merge remote-tracking branch 'upstream/master' into rm-2.7
hugovk Nov 1, 2019
b4f93cf
Upgrade Python syntax with pyupgrade --py3-plus
hugovk Nov 1, 2019
6f88d8d
black --target-version py35
hugovk Nov 2, 2019
58e6d12
In Python 3, 'next' is renamed to '__next__'
hugovk Nov 3, 2019
5006401
Merge branch 'master' into rm-2.7
hugovk Nov 3, 2019
24b8501
Remove handling for pre-3.3 wide/narrow builds
hugovk Nov 3, 2019
12a7259
Merge remote-tracking branch 'upstream/master' into rm-2.7
hugovk Nov 16, 2019
e5486b4
Merge remote-tracking branch 'upstream/master' into rm-2.7
hugovk Nov 18, 2019
a949d78
Merge branch 'master' into rm-2.7
hugovk Nov 20, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Simplify temporary directory cleanup
Co-Authored-By: Jon Dufresne <jon.dufresne@gmail.com>
  • Loading branch information
hugovk and jdufresne committed Oct 8, 2019
commit 3a34081db5762b18e630d7b313dc75e4bebe0c31
5 changes: 1 addition & 4 deletions 5 Tests/test_file_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,10 @@ def test_pdf_open(self):

def test_pdf_append_fails_on_nonexistent_file(self):
im = hopper("RGB")
temp_dir = tempfile.mkdtemp()
try:
with tempfile.TemporaryDirectory() as temp_dir:
self.assertRaises(
IOError, im.save, os.path.join(temp_dir, "nonexistent.pdf"), append=True
)
finally:
os.rmdir(temp_dir)

def check_pdf_pages_consistency(self, pdf):
pages_info = pdf.read_indirect(pdf.pages_ref)
Expand Down
63 changes: 31 additions & 32 deletions 63 src/PIL/IcnsImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,41 +314,40 @@ def _save(im, fp, filename):
fp.flush()

# create the temporary set of pngs
iconset = tempfile.mkdtemp(".iconset")
provided_images = {im.width: im for im in im.encoderinfo.get("append_images", [])}
last_w = None
second_path = None
for w in [16, 32, 128, 256, 512]:
prefix = "icon_{}x{}".format(w, w)

first_path = os.path.join(iconset, prefix + ".png")
if last_w == w:
shutil.copyfile(second_path, first_path)
else:
im_w = provided_images.get(w, im.resize((w, w), Image.LANCZOS))
im_w.save(first_path)

second_path = os.path.join(iconset, prefix + "@2x.png")
im_w2 = provided_images.get(w * 2, im.resize((w * 2, w * 2), Image.LANCZOS))
im_w2.save(second_path)
last_w = w * 2

# iconutil -c icns -o {} {}

convert_cmd = ["iconutil", "-c", "icns", "-o", filename, iconset]
convert_proc = subprocess.Popen(
convert_cmd, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL
)

convert_proc.stdout.close()
with tempfile.TemporaryDirectory(".iconset") as iconset:
provided_images = {
im.width: im for im in im.encoderinfo.get("append_images", [])
}
last_w = None
second_path = None
for w in [16, 32, 128, 256, 512]:
prefix = "icon_{}x{}".format(w, w)

first_path = os.path.join(iconset, prefix + ".png")
if last_w == w:
shutil.copyfile(second_path, first_path)
else:
im_w = provided_images.get(w, im.resize((w, w), Image.LANCZOS))
im_w.save(first_path)

second_path = os.path.join(iconset, prefix + "@2x.png")
im_w2 = provided_images.get(w * 2, im.resize((w * 2, w * 2), Image.LANCZOS))
im_w2.save(second_path)
last_w = w * 2

# iconutil -c icns -o {} {}

convert_cmd = ["iconutil", "-c", "icns", "-o", filename, iconset]
convert_proc = subprocess.Popen(
convert_cmd, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL
)

retcode = convert_proc.wait()
convert_proc.stdout.close()

# remove the temporary files
shutil.rmtree(iconset)
retcode = convert_proc.wait()

if retcode:
raise subprocess.CalledProcessError(retcode, convert_cmd)
if retcode:
raise subprocess.CalledProcessError(retcode, convert_cmd)


Image.register_open(IcnsImageFile.format, IcnsImageFile, lambda x: x[:4] == b"icns")
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.