55import io
66import os
77import shutil
8- import sys
98from typing import Dict , Tuple
109import warnings
1110
1716from docutils .parsers .rst import directives
1817
1918from . import documenters
20- from .backends import (
21- DEFAULT_FILE_PATTERNS ,
22- DEFAULT_IGNORE_PATTERNS ,
23- LANGUAGE_MAPPERS ,
24- LANGUAGE_REQUIREMENTS ,
25- )
2619from .directives import AutoapiSummary , NestedParse
2720from .inheritance_diagrams import AutoapiInheritanceDiagram
21+ from .mappers import PythonSphinxMapper
2822from .settings import API_ROOT
2923
3024LOGGER = sphinx .util .logging .getLogger (__name__ )
3125
26+ _DEFAULT_FILE_PATTERNS = ["*.py" , "*.pyi" ]
27+ _DEFAULT_IGNORE_PATTERNS = ["*migrations*" ]
3228_DEFAULT_OPTIONS = [
3329 "members" ,
3430 "undoc-members" ,
@@ -66,19 +62,6 @@ def _normalise_autoapi_dirs(autoapi_dirs, srcdir):
6662
6763def run_autoapi (app ): # pylint: disable=too-many-branches
6864 """Load AutoAPI data from the filesystem."""
69- if app .config .autoapi_type not in LANGUAGE_MAPPERS :
70- allowed = ", " .join (f'"{ api_type } "' for api_type in sorted (LANGUAGE_MAPPERS ))
71- raise ExtensionError (
72- f"Invalid autoapi_type setting, following values are allowed: { allowed } "
73- )
74-
75- if app .config .autoapi_type != "python" :
76- warnings .warn (
77- "Support for documenting languages other than Python "
78- "will be removed in AutoAPI v3." ,
79- RemovedInAutoAPI3Warning ,
80- )
81-
8265 if not app .config .autoapi_dirs :
8366 raise ExtensionError ("You must configure an autoapi_dirs setting" )
8467
@@ -105,20 +88,6 @@ def run_autoapi(app): # pylint: disable=too-many-branches
10588 )
10689 url_root = os .path .join ("/" , app .config .autoapi_root )
10790
108- if not all (
109- import_name in sys .modules
110- for _ , import_name in LANGUAGE_REQUIREMENTS [app .config .autoapi_type ]
111- ):
112- packages = ", " .join (
113- f'{ import_name } (available as "{ pkg_name } " on PyPI)'
114- for pkg_name , import_name in LANGUAGE_REQUIREMENTS [app .config .autoapi_type ]
115- )
116- raise ExtensionError (
117- f"AutoAPI of type `{ app .config .autoapi_type } ` requires following "
118- f"packages to be installed and included in extensions list: { packages } "
119- )
120-
121- sphinx_mapper = LANGUAGE_MAPPERS [app .config .autoapi_type ]
12291 template_dir = app .config .autoapi_template_dir
12392 if template_dir and not os .path .isabs (template_dir ):
12493 if not os .path .isdir (template_dir ):
@@ -130,17 +99,19 @@ def run_autoapi(app): # pylint: disable=too-many-branches
13099 "relative to where sphinx-build is run\n " ,
131100 RemovedInAutoAPI3Warning ,
132101 )
133- sphinx_mapper_obj = sphinx_mapper (app , template_dir = template_dir , url_root = url_root )
102+ sphinx_mapper_obj = PythonSphinxMapper (
103+ app , template_dir = template_dir , url_root = url_root
104+ )
134105
135106 if app .config .autoapi_file_patterns :
136107 file_patterns = app .config .autoapi_file_patterns
137108 else :
138- file_patterns = DEFAULT_FILE_PATTERNS . get ( app . config . autoapi_type , [])
109+ file_patterns = _DEFAULT_FILE_PATTERNS
139110
140111 if app .config .autoapi_ignore :
141112 ignore_patterns = app .config .autoapi_ignore
142113 else :
143- ignore_patterns = DEFAULT_IGNORE_PATTERNS . get ( app . config . autoapi_type , [])
114+ ignore_patterns = _DEFAULT_IGNORE_PATTERNS
144115
145116 if ".rst" in app .config .source_suffix :
146117 out_suffix = ".rst"
@@ -171,10 +142,6 @@ def build_finished(app, exception):
171142 )
172143 shutil .rmtree (normalized_root )
173144
174- sphinx_mapper = LANGUAGE_MAPPERS [app .config .autoapi_type ]
175- if hasattr (sphinx_mapper , "build_finished" ):
176- sphinx_mapper .build_finished (app , exception )
177-
178145
179146def source_read (app , docname , source ): # pylint: disable=unused-argument
180147 # temp_data is cleared after each source file has been processed,
@@ -289,7 +256,6 @@ def setup(app):
289256 app .connect ("viewcode-find-source" , viewcode_find )
290257 if "viewcode-follow-imported" in app .events .events :
291258 app .connect ("viewcode-follow-imported" , viewcode_follow_imported )
292- app .add_config_value ("autoapi_type" , "python" , "html" )
293259 app .add_config_value ("autoapi_root" , API_ROOT , "html" )
294260 app .add_config_value ("autoapi_ignore" , [], "html" )
295261 app .add_config_value ("autoapi_options" , _DEFAULT_OPTIONS , "html" )
0 commit comments