mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Migrate to py3 style type annotation: sphinx.ext.imgconverter
This commit is contained in:
parent
462902aea6
commit
30ddf70742
@ -7,19 +7,17 @@
|
||||
:copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
import subprocess
|
||||
from subprocess import CalledProcessError, PIPE
|
||||
from typing import Any, Dict
|
||||
|
||||
from sphinx.application import Sphinx
|
||||
from sphinx.errors import ExtensionError
|
||||
from sphinx.locale import __
|
||||
from sphinx.transforms.post_transforms.images import ImageConverter
|
||||
from sphinx.util import logging
|
||||
|
||||
if False:
|
||||
# For type annotation
|
||||
from typing import Any, Dict # NOQA
|
||||
from sphinx.application import Sphinx # NOQA
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -31,8 +29,7 @@ class ImagemagickConverter(ImageConverter):
|
||||
('application/pdf', 'image/png'),
|
||||
]
|
||||
|
||||
def is_available(self):
|
||||
# type: () -> bool
|
||||
def is_available(self) -> bool:
|
||||
"""Confirms the converter is available or not."""
|
||||
try:
|
||||
args = [self.config.image_converter, '-version']
|
||||
@ -50,8 +47,7 @@ class ImagemagickConverter(ImageConverter):
|
||||
exc.stderr, exc.stdout)
|
||||
return False
|
||||
|
||||
def convert(self, _from, _to):
|
||||
# type: (str, str) -> bool
|
||||
def convert(self, _from: str, _to: str) -> bool:
|
||||
"""Converts the image to expected one."""
|
||||
try:
|
||||
# append an index 0 to source filename to pick up the first frame
|
||||
@ -75,8 +71,7 @@ class ImagemagickConverter(ImageConverter):
|
||||
(exc.stderr, exc.stdout))
|
||||
|
||||
|
||||
def setup(app):
|
||||
# type: (Sphinx) -> Dict[str, Any]
|
||||
def setup(app: Sphinx) -> Dict[str, Any]:
|
||||
app.add_post_transform(ImagemagickConverter)
|
||||
app.add_config_value('image_converter', 'convert', 'env')
|
||||
app.add_config_value('image_converter_args', [], 'env')
|
||||
|
Loading…
Reference in New Issue
Block a user