summaryrefslogtreecommitdiffstats
path: root/doc/development/tutorials/examples/recipe.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-05 16:20:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-05 16:20:58 +0000
commit5bb0bb4be543fd5eca41673696a62ed80d493591 (patch)
treead2c464f140e86c7f178a6276d7ea4a93e3e6c92 /doc/development/tutorials/examples/recipe.py
parentAdding upstream version 7.2.6. (diff)
downloadsphinx-5bb0bb4be543fd5eca41673696a62ed80d493591.tar.xz
sphinx-5bb0bb4be543fd5eca41673696a62ed80d493591.zip
Adding upstream version 7.3.7.upstream/7.3.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'doc/development/tutorials/examples/recipe.py')
-rw-r--r--doc/development/tutorials/examples/recipe.py46
1 files changed, 26 insertions, 20 deletions
diff --git a/doc/development/tutorials/examples/recipe.py b/doc/development/tutorials/examples/recipe.py
index c7ebf2a..28d25f2 100644
--- a/doc/development/tutorials/examples/recipe.py
+++ b/doc/development/tutorials/examples/recipe.py
@@ -3,10 +3,12 @@ from collections import defaultdict
from docutils.parsers.rst import directives
from sphinx import addnodes
+from sphinx.application import Sphinx
from sphinx.directives import ObjectDescription
from sphinx.domains import Domain, Index
from sphinx.roles import XRefRole
from sphinx.util.nodes import make_refnode
+from sphinx.util.typing import ExtensionMetadata
class RecipeDirective(ObjectDescription):
@@ -25,8 +27,7 @@ class RecipeDirective(ObjectDescription):
def add_target_and_index(self, name_cls, sig, signode):
signode['ids'].append('recipe' + '-' + sig)
if 'contains' in self.options:
- ingredients = [
- x.strip() for x in self.options.get('contains').split(',')]
+ ingredients = [x.strip() for x in self.options.get('contains').split(',')]
recipes = self.env.get_domain('recipe')
recipes.add_recipe(sig, ingredients)
@@ -42,9 +43,10 @@ class IngredientIndex(Index):
def generate(self, docnames=None):
content = defaultdict(list)
- recipes = {name: (dispname, typ, docname, anchor)
- for name, dispname, typ, docname, anchor, _
- in self.domain.get_objects()}
+ recipes = {
+ name: (dispname, typ, docname, anchor)
+ for name, dispname, typ, docname, anchor, _ in self.domain.get_objects()
+ }
recipe_ingredients = self.domain.data['recipe_ingredients']
ingredient_recipes = defaultdict(list)
@@ -60,8 +62,7 @@ class IngredientIndex(Index):
for ingredient, recipe_names in ingredient_recipes.items():
for recipe_name in recipe_names:
dispname, typ, docname, anchor = recipes[recipe_name]
- content[ingredient].append(
- (dispname, 0, docname, anchor, docname, '', typ))
+ content[ingredient].append((dispname, 0, docname, anchor, docname, '', typ))
# convert the dict to the sorted list of tuples expected
content = sorted(content.items())
@@ -88,8 +89,15 @@ class RecipeIndex(Index):
#
# name, subtype, docname, anchor, extra, qualifier, description
for _name, dispname, typ, docname, anchor, _priority in recipes:
- content[dispname[0].lower()].append(
- (dispname, 0, docname, anchor, docname, '', typ))
+ content[dispname[0].lower()].append((
+ dispname,
+ 0,
+ docname,
+ anchor,
+ docname,
+ '',
+ typ,
+ ))
# convert the dict to the sorted list of tuples expected
content = sorted(content.items())
@@ -98,7 +106,6 @@ class RecipeIndex(Index):
class RecipeDomain(Domain):
-
name = 'recipe'
label = 'Recipe Sample'
roles = {
@@ -122,18 +129,18 @@ class RecipeDomain(Domain):
def get_objects(self):
yield from self.data['recipes']
- def resolve_xref(self, env, fromdocname, builder, typ, target, node,
- contnode):
- match = [(docname, anchor)
- for name, sig, typ, docname, anchor, prio
- in self.get_objects() if sig == target]
+ def resolve_xref(self, env, fromdocname, builder, typ, target, node, contnode):
+ match = [
+ (docname, anchor)
+ for name, sig, typ, docname, anchor, prio in self.get_objects()
+ if sig == target
+ ]
if len(match) > 0:
todocname = match[0][0]
targ = match[0][1]
- return make_refnode(builder, fromdocname, todocname, targ,
- contnode, targ)
+ return make_refnode(builder, fromdocname, todocname, targ, contnode, targ)
else:
print('Awww, found nothing')
return None
@@ -145,11 +152,10 @@ class RecipeDomain(Domain):
self.data['recipe_ingredients'][name] = ingredients
# name, dispname, type, docname, anchor, priority
- self.data['recipes'].append(
- (name, signature, 'Recipe', self.env.docname, anchor, 0))
+ self.data['recipes'].append((name, signature, 'Recipe', self.env.docname, anchor, 0))
-def setup(app):
+def setup(app: Sphinx) -> ExtensionMetadata:
app.add_domain(RecipeDomain)
return {