def __init__(self, app: Union[Builder, Sphinx], template_dir: str = None) -> None: if isinstance(app, Builder): warnings.warn( 'The first argument for AutosummaryRenderer has been ' 'changed to Sphinx object', RemovedInSphinx50Warning, stacklevel=2) if template_dir: warnings.warn( 'template_dir argument for AutosummaryRenderer is deprecated.', RemovedInSphinx50Warning, stacklevel=2) system_templates_path = [ os.path.join(package_dir, 'ext', 'autosummary', 'templates') ] loader = SphinxTemplateLoader(app.srcdir, app.config.templates_path, system_templates_path) self.env = SandboxedEnvironment(loader=loader) self.env.filters['escape'] = rst.escape self.env.filters['e'] = rst.escape self.env.filters['underline'] = _underline if isinstance(app, (Sphinx, DummyApplication)): if app.translator: self.env.add_extension("jinja2.ext.i18n") self.env.install_gettext_translations(app.translator) elif isinstance(app, Builder): if app.app.translator: self.env.add_extension("jinja2.ext.i18n") self.env.install_gettext_translations(app.app.translator)
def __init__(self, app: Sphinx) -> None: if isinstance(app, Builder): raise ValueError('Expected a Sphinx application object!') system_templates_path = [os.path.join(package_dir, 'ext', 'autosummary', 'templates')] loader = SphinxTemplateLoader(app.srcdir, app.config.templates_path, system_templates_path) self.env = SandboxedEnvironment(loader=loader) self.env.filters['escape'] = rst.escape self.env.filters['e'] = rst.escape self.env.filters['underline'] = _underline if app.translator: self.env.add_extension("jinja2.ext.i18n") self.env.install_gettext_translations(app.translator)