Merge pull request #4797 from tk0miya/4789_imgconverter_misdetects_convert_command

Fix #4789: imgconverter: confused by converter.exe of Windows
This commit is contained in:
Takeshi KOMIYA 2018-04-01 17:59:44 +09:00 committed by GitHub
commit 095b178cc3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 5 deletions

View File

@ -19,6 +19,7 @@ Bugs fixed
* #4769: autodoc loses the first staticmethod parameter
* #4790: autosummary: too wide two column tables in PDF builds
* #4795: Latex customization via ``_templates/longtable.tex_t`` is broken
* #4789: imgconverter: confused by convert.exe of Windows
Testing
--------

View File

@ -37,17 +37,28 @@ class ImagemagickConverter(ImageConverter):
try:
args = [self.config.image_converter, '-version']
logger.debug('Invoking %r ...', args)
ret = subprocess.call(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
if ret == 0:
return True
else:
return False
p = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
except (OSError, IOError):
logger.warning(__('convert command %r cannot be run.'
'check the image_converter setting'),
self.config.image_converter)
return False
try:
stdout, stderr = p.communicate()
except (OSError, IOError) as err:
if err.errno not in (EPIPE, EINVAL):
raise
stdout, stderr = p.stdout.read(), p.stderr.read()
p.wait()
if p.returncode != 0:
logger.warning(__('convert exited with error:\n'
'[stderr]\n%s\n[stdout]\n%s'),
(stderr, stdout))
return False
return True
def convert(self, _from, _to):
# type: (unicode, unicode) -> bool
"""Converts the image to expected one."""