Enable automatic formatting for `sphinx/ext/imgconverter.py`

This commit is contained in:
Adam Turner 2024-12-23 20:01:28 +00:00
parent 437a31d199
commit f592962b8d
2 changed files with 32 additions and 20 deletions

View File

@ -415,7 +415,6 @@ exclude = [
"sphinx/domains/python/_object.py", "sphinx/domains/python/_object.py",
"sphinx/domains/rst.py", "sphinx/domains/rst.py",
"sphinx/domains/std/__init__.py", "sphinx/domains/std/__init__.py",
"sphinx/ext/imgconverter.py",
"sphinx/ext/imgmath.py", "sphinx/ext/imgmath.py",
"sphinx/ext/inheritance_diagram.py", "sphinx/ext/inheritance_diagram.py",
"sphinx/ext/linkcode.py", "sphinx/ext/linkcode.py",

View File

@ -37,18 +37,24 @@ class ImagemagickConverter(ImageConverter):
subprocess.run(args, capture_output=True, check=True) subprocess.run(args, capture_output=True, check=True)
return True return True
except OSError as exc: except OSError as exc:
logger.warning(__( logger.warning(
"Unable to run the image conversion command %r. " __(
"'sphinx.ext.imgconverter' requires ImageMagick by default. " 'Unable to run the image conversion command %r. '
"Ensure it is installed, or set the 'image_converter' option " "'sphinx.ext.imgconverter' requires ImageMagick by default. "
"to a custom conversion command.\n\n" "Ensure it is installed, or set the 'image_converter' option "
"Traceback: %s", 'to a custom conversion command.\n\n'
), self.config.image_converter, exc) 'Traceback: %s',
),
self.config.image_converter,
exc,
)
return False return False
except CalledProcessError as exc: except CalledProcessError as exc:
logger.warning(__('convert exited with error:\n' logger.warning(
'[stderr]\n%r\n[stdout]\n%r'), __('convert exited with error:\n[stderr]\n%r\n[stdout]\n%r'),
exc.stderr, exc.stdout) exc.stderr,
exc.stdout,
)
return False return False
def convert(self, _from: str, _to: str) -> bool: def convert(self, _from: str, _to: str) -> bool:
@ -58,21 +64,28 @@ class ImagemagickConverter(ImageConverter):
# (or first page) of image (ex. Animation GIF, PDF) # (or first page) of image (ex. Animation GIF, PDF)
_from += '[0]' _from += '[0]'
args = ([ args = [
self.config.image_converter, *self.config.image_converter_args, _from, _to, self.config.image_converter,
]) *self.config.image_converter_args,
_from,
_to,
]
logger.debug('Invoking %r ...', args) logger.debug('Invoking %r ...', args)
subprocess.run(args, capture_output=True, check=True) subprocess.run(args, capture_output=True, check=True)
return True return True
except OSError: except OSError:
logger.warning(__('convert command %r cannot be run, ' logger.warning(
'check the image_converter setting'), __(
self.config.image_converter) 'convert command %r cannot be run, check the image_converter setting'
),
self.config.image_converter,
)
return False return False
except CalledProcessError as exc: except CalledProcessError as exc:
raise ExtensionError(__('convert exited with error:\n' raise ExtensionError(
'[stderr]\n%r\n[stdout]\n%r') % __('convert exited with error:\n[stderr]\n%r\n[stdout]\n%r')
(exc.stderr, exc.stdout)) from exc % (exc.stderr, exc.stdout)
) from exc
def setup(app: Sphinx) -> ExtensionMetadata: def setup(app: Sphinx) -> ExtensionMetadata: