Skip to content

Commit

Permalink
Merge pull request #9242 from tk0miya/refactor_env2
Browse files Browse the repository at this point in the history
refactor: Make the app argument for BuildEnvironment required
  • Loading branch information
tk0miya committed May 21, 2021
2 parents aba3a33 + 63fbfb0 commit abe5ab4
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Incompatible changes
Deprecated
----------

* The ``app`` argument of ``sphinx.environment.BuildEnvironment`` becomes
required
* ``sphinx.application.Sphinx.html_theme``
* ``sphinx.util.docstrings.extract_metadata()``

Expand Down
5 changes: 5 additions & 0 deletions doc/extdev/deprecated.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ The following is a list of deprecated interfaces.
- (will be) Removed
- Alternatives

* - The optional argument ``app`` for ``sphinx.environment.BuildEnvironment``
- 4.1
- 6.0
- The required argument

* - ``sphinx.application.Sphinx.html_theme``
- 4.1
- 6.0
Expand Down
3 changes: 1 addition & 2 deletions sphinx/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,7 @@ def _init_i18n(self) -> None:
def _init_env(self, freshenv: bool) -> None:
filename = path.join(self.doctreedir, ENV_PICKLE_FILENAME)
if freshenv or not os.path.exists(filename):
self.env = BuildEnvironment()
self.env.setup(self)
self.env = BuildEnvironment(self)
self.env.find_files(self.config, self.builder)
else:
try:
Expand Down
5 changes: 5 additions & 0 deletions sphinx/environment/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import os
import pickle
import warnings
from collections import defaultdict
from copy import copy
from datetime import datetime
Expand All @@ -22,6 +23,7 @@

from sphinx import addnodes
from sphinx.config import Config
from sphinx.deprecation import RemovedInSphinx60Warning
from sphinx.domains import Domain
from sphinx.environment.adapters.toctree import TocTree
from sphinx.errors import BuildEnvironmentError, DocumentError, ExtensionError, SphinxError
Expand Down Expand Up @@ -181,6 +183,9 @@ def __init__(self, app: "Sphinx" = None):
# set up environment
if app:
self.setup(app)
else:
warnings.warn("The 'app' argument for BuildEnvironment() becomes required now.",
RemovedInSphinx60Warning, stacklevel=2)

def __getstate__(self) -> Dict:
"""Obtains serializable data for pickling."""
Expand Down
19 changes: 16 additions & 3 deletions sphinx/ext/autosummary/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@
from sphinx.ext.autodoc.importer import import_module
from sphinx.ext.autodoc.mock import mock
from sphinx.locale import __
from sphinx.project import Project
from sphinx.pycode import ModuleAnalyzer, PycodeError
from sphinx.registry import SphinxComponentRegistry
from sphinx.util import logging, rst
from sphinx.util.docutils import (NullReporter, SphinxDirective, SphinxRole, new_document,
switch_source_input)
Expand Down Expand Up @@ -168,13 +170,24 @@ def autosummary_table_visit_html(self: HTMLTranslator, node: autosummary_table)
_app: Sphinx = None


class FakeApplication:
def __init__(self):
self.doctreedir = None
self.events = None
self.extensions = {}
self.srcdir = None
self.config = Config()
self.project = Project(None, None)
self.registry = SphinxComponentRegistry()


class FakeDirective(DocumenterBridge):
def __init__(self) -> None:
settings = Struct(tab_width=8)
document = Struct(settings=settings)
env = BuildEnvironment()
env.config = Config()
env.config.add('autodoc_class_signature', 'mixed', True, None)
app = FakeApplication()
app.config.add('autodoc_class_signature', 'mixed', True, None)
env = BuildEnvironment(app) # type: ignore
state = Struct(document=document)
super().__init__(env, None, Options(), 0, state)

Expand Down

0 comments on commit abe5ab4

Please sign in to comment.