-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Manual update from ferrocene/ferrocene
mirrored-commit: 71e22d4e212241da6d5ae4c5f951bc6899958e41
- Loading branch information
Showing
11 changed files
with
500 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# SPDX-License-Identifier: MIT OR Apache-2.0 | ||
# SPDX-FileCopyrightText: The Ferrocene Developers | ||
|
||
# This module adds some helpers needed to integrate Ferrocene's build system | ||
# with InterSphinx. More specifically, the extension: | ||
# | ||
# - Defines the "ferrocene-intersphinx" Sphinx builder, which only produces the | ||
# objects.inv file required by InterSphinx. This is used to gather all the | ||
# inventories for all of our documentation before actually building anything, | ||
# as we have circular references between documents. | ||
# | ||
# - Defines the "ferrocene_intersphinx_mappings" configuration, which this | ||
# extension deserializes from JSON and then adds to the intersphinx_mapping | ||
# configuration. This is needed because the format of intersphinx_mapping is | ||
# too complex to be provided with the -D flag. | ||
|
||
from sphinx.builders import Builder | ||
from sphinx.builders.html import StandaloneHTMLBuilder | ||
import json | ||
import sphinx | ||
import sphinx.ext.intersphinx | ||
|
||
|
||
class IntersphinxBuilder(Builder): | ||
name = "ferrocene-intersphinx" | ||
format = "" | ||
epilog = "InterSphinx inventory file generated." | ||
allow_parallel = True | ||
|
||
def init(self): | ||
self.standalone_html_builder = StandaloneHTMLBuilder(self.app, self.env) | ||
|
||
# Do not emit any warning in the ferrocene-intersphinx builder: there | ||
# will be warnings when using the builder, as the rest of the documents | ||
# won't be built yet, but we don't care about them. | ||
# | ||
# Keeping the warnings will confuse people who read the build logs, | ||
# thinking they should fix them while they're expected to happen. | ||
# | ||
# Unfortunately the only reliable way to suppress the warnings is | ||
# monkey-patching Sphinx's code, as you cannot set a global filter in | ||
# Python's logging module. | ||
sphinx.util.logging.WarningStreamHandler.emit = lambda _self, _record: None | ||
|
||
def build(self, *args, **kwargs): | ||
# Normally you're not supposed to override the build() method, as | ||
# Sphinx calls all the relevant overrideable methods from it. | ||
# | ||
# Unfortunately though, Sphinx doesn't execute the finish() method if | ||
# there are no outdated docs (as we're simulating in this builder). | ||
# | ||
# Returning all documents from get_outdated_docs() would fix that | ||
# problem, but would also execute all the post_transforms for all | ||
# documents, which on large documents can take a while. | ||
# | ||
# Instead, we're returning an empty list of outdated documents, and | ||
# manually dumping the inventory here after the parent build() returns. | ||
super().build(*args, **kwargs) | ||
self.standalone_html_builder.dump_inventory() | ||
|
||
def get_outdated_docs(self): | ||
return [] | ||
|
||
def prepare_writing(self, docnames): | ||
pass | ||
|
||
def write_doc(self, docname, doctree): | ||
pass | ||
|
||
def get_target_uri(self, docname, typ=None): | ||
# Defer to the standalone HTML builder to generate builders. | ||
return self.standalone_html_builder.get_target_uri(docname, typ) | ||
|
||
|
||
def inject_intersphinx_mappings(app, config): | ||
if config.ferrocene_intersphinx_mappings is not None: | ||
for inventory in json.loads(config.ferrocene_intersphinx_mappings): | ||
config.intersphinx_mapping[inventory["name"]] = ( | ||
inventory["html_root"], | ||
inventory["inventory"], | ||
) | ||
|
||
|
||
def setup(app): | ||
# Automatically enable the sphinx.ext.intersphinx extension without | ||
# requiring users to configure it in their conf.py. | ||
sphinx.ext.intersphinx.setup(app) | ||
|
||
app.add_builder(IntersphinxBuilder) | ||
|
||
app.add_config_value("ferrocene_intersphinx_mappings", None, "env", [str]) | ||
app.connect("config-inited", inject_intersphinx_mappings, priority=1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# SPDX-License-Identifier: MIT OR Apache-2.0 | ||
# SPDX-FileCopyrightText: The Ferrocene Developers | ||
|
||
import sphinx_needs | ||
import json | ||
|
||
|
||
def configure_sphinx_needs(app, config): | ||
config.needs_types = [ | ||
{ | ||
"directive": "hazop-use", | ||
"title": "Use Case", | ||
"prefix": "USE_", | ||
"color": "", | ||
"style": "", | ||
}, | ||
{ | ||
"directive": "hazop-error", | ||
"title": "Potential error", | ||
"prefix": "ERR_", | ||
"color": "", | ||
"style": "", | ||
}, | ||
{ | ||
"directive": "constraint", | ||
"title": "Constraint", | ||
"prefix": "CONSTR_", | ||
"color": "", | ||
"style": "", | ||
}, | ||
{ | ||
"directive": "req", | ||
"title": "Requirement", | ||
"prefix": "REQ_", | ||
"color": "", | ||
"style": "", | ||
}, | ||
] | ||
|
||
config.needs_extra_links = [ | ||
{ | ||
"option": "caused_by", | ||
"incoming": "causes", | ||
"outgoing": "caused by", | ||
}, | ||
{ | ||
"option": "mitigates", | ||
"incoming": "mitigated by", | ||
"outgoing": "mitigates", | ||
}, | ||
{ | ||
"option": "implements", | ||
"incoming": "implemented by", | ||
"outgoing": "implements", | ||
}, | ||
] | ||
|
||
config.needs_default_layout = "ferrocene" | ||
config.needs_layouts = { | ||
# Forked from the builtin "clean" layout, but without the arrow to | ||
# collapse the meta information. That arrow generates HTML that | ||
# linkchecker doesn't like, unfortunately :( | ||
"ferrocene": { | ||
"grid": "simple", | ||
"layout": { | ||
"head": ['<<meta("type_name")>>: **<<meta("title")>>** <<meta_id()>>'], | ||
"meta": ["<<meta_all(no_links=True)>>", "<<meta_links_all()>>"], | ||
}, | ||
}, | ||
} | ||
|
||
if config.ferrocene_external_needs is not None: | ||
config.needs_external_needs = json.loads(config.ferrocene_external_needs) | ||
|
||
config.needs_title_optional = True | ||
config.needs_build_json = True | ||
config.needs_reproducible_json = True | ||
|
||
|
||
def setup(app): | ||
sphinx_needs.setup(app) | ||
|
||
app.add_config_value("ferrocene_external_needs", None, "env", str) | ||
app.connect("config-inited", configure_sphinx_needs, priority=100) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.