summaryrefslogtreecommitdiff
path: root/sphinx/environment
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2019-07-06 12:27:42 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2019-07-06 12:42:25 +0900
commit17c719c8de872cc9747040f886e81086641b8cce (patch)
treee8676e9fdf9886f93c580b2452df203286180032 /sphinx/environment
parent0cad96233b8b6e6e821183cf28f476ed6f53836e (diff)
downloadsphinx-git-17c719c8de872cc9747040f886e81086641b8cce.tar.gz
Migrate to py3 style type annotation: sphinx.environment.collectors.asset
Diffstat (limited to 'sphinx/environment')
-rw-r--r--sphinx/environment/collectors/asset.py36
1 files changed, 15 insertions, 21 deletions
diff --git a/sphinx/environment/collectors/asset.py b/sphinx/environment/collectors/asset.py
index fed8280c1..e1d3abef1 100644
--- a/sphinx/environment/collectors/asset.py
+++ b/sphinx/environment/collectors/asset.py
@@ -11,22 +11,21 @@
import os
from glob import glob
from os import path
+from typing import Any, Dict, List, Set
from docutils import nodes
+from docutils.nodes import Node
from docutils.utils import relative_path
from sphinx import addnodes
+from sphinx.application import Sphinx
+from sphinx.environment import BuildEnvironment
from sphinx.environment.collectors import EnvironmentCollector
from sphinx.locale import __
from sphinx.util import logging
from sphinx.util.i18n import get_image_filename_for_language, search_image_for_language
from sphinx.util.images import guess_mimetype
-if False:
- # For type annotation
- from typing import Dict, List, Set # NOQA
- from sphinx.sphinx import Sphinx # NOQA
- from sphinx.environment import BuildEnvironment # NOQA
logger = logging.getLogger(__name__)
@@ -34,16 +33,14 @@ logger = logging.getLogger(__name__)
class ImageCollector(EnvironmentCollector):
"""Image files collector for sphinx.environment."""
- def clear_doc(self, app, env, docname):
- # type: (Sphinx, BuildEnvironment, str) -> None
+ def clear_doc(self, app: Sphinx, env: BuildEnvironment, docname: str) -> None:
env.images.purge_doc(docname)
- def merge_other(self, app, env, docnames, other):
- # type: (Sphinx, BuildEnvironment, Set[str], BuildEnvironment) -> None
+ def merge_other(self, app: Sphinx, env: BuildEnvironment,
+ docnames: Set[str], other: BuildEnvironment) -> None:
env.images.merge_other(docnames, other.images)
- def process_doc(self, app, doctree):
- # type: (Sphinx, nodes.document) -> None
+ def process_doc(self, app: Sphinx, doctree: nodes.document) -> None:
"""Process and rewrite image URIs."""
docname = app.env.docname
@@ -92,8 +89,8 @@ class ImageCollector(EnvironmentCollector):
continue
app.env.images.add_file(docname, imgpath)
- def collect_candidates(self, env, imgpath, candidates, node):
- # type: (BuildEnvironment, str, Dict[str, str], nodes.Node) -> None
+ def collect_candidates(self, env: BuildEnvironment, imgpath: str,
+ candidates: Dict[str, str], node: Node) -> None:
globbed = {} # type: Dict[str, List[str]]
for filename in glob(imgpath):
new_imgpath = relative_path(path.join(env.srcdir, 'dummy'),
@@ -115,16 +112,14 @@ class ImageCollector(EnvironmentCollector):
class DownloadFileCollector(EnvironmentCollector):
"""Download files collector for sphinx.environment."""
- def clear_doc(self, app, env, docname):
- # type: (Sphinx, BuildEnvironment, str) -> None
+ def clear_doc(self, app: Sphinx, env: BuildEnvironment, docname: str) -> None:
env.dlfiles.purge_doc(docname)
- def merge_other(self, app, env, docnames, other):
- # type: (Sphinx, BuildEnvironment, Set[str], BuildEnvironment) -> None
+ def merge_other(self, app: Sphinx, env: BuildEnvironment,
+ docnames: Set[str], other: BuildEnvironment) -> None:
env.dlfiles.merge_other(docnames, other.dlfiles)
- def process_doc(self, app, doctree):
- # type: (Sphinx, nodes.document) -> None
+ def process_doc(self, app: Sphinx, doctree: nodes.document) -> None:
"""Process downloadable file paths. """
for node in doctree.traverse(addnodes.download_reference):
targetname = node['reftarget']
@@ -140,8 +135,7 @@ class DownloadFileCollector(EnvironmentCollector):
node['filename'] = app.env.dlfiles.add_file(app.env.docname, rel_filename)
-def setup(app):
- # type: (Sphinx) -> Dict
+def setup(app: Sphinx) -> Dict[str, Any]:
app.add_env_collector(ImageCollector)
app.add_env_collector(DownloadFileCollector)