13
13
from urllib .parse import quote as _urllib_quote
14
14
15
15
from docutils import nodes
16
- from docutils .nodes import Element
17
- from sphinx import addnodes , domains
18
- from sphinx .builders import Builder
16
+ from sphinx import addnodes
19
17
from sphinx .domains .std import StandardDomain
20
- from sphinx .environment import BuildEnvironment
21
- from sphinx .locale import _
22
18
from sphinx .util import logging
23
19
from sphinx .util .docutils import SphinxDirective
24
20
from sphinx .util .nodes import make_id
25
21
26
- from antsibull_docs .utils .rst import massage_rst_label
22
+ from antsibull_docs .rst_labels import (
23
+ get_attribute_ref ,
24
+ get_option_ref ,
25
+ get_requirements_ref ,
26
+ get_return_value_ref ,
27
+ )
27
28
28
29
from .directive_helper import YAMLDirective
30
+ from .domains import AnsibleDomain
29
31
from .nodes import ansible_attribute , ansible_option , ansible_return_value , link_button
30
32
from .schemas .ansible_links import AnsibleLinks
31
33
from .schemas .ansible_plugin import (
@@ -93,51 +95,6 @@ def _run(self, content_str: str, content: AnsibleLinks) -> list[nodes.Node]:
93
95
return [node ]
94
96
95
97
96
- class AnsibleDomain (domains .Domain ):
97
- name = "ansible"
98
-
99
- object_types : dict [str , domains .ObjType ] = {
100
- "plugin" : domains .ObjType (_ ("plugin" ), "plugin" , searchprio = - 1 ),
101
- "role_entrypoint" : domains .ObjType (
102
- _ ("role entrypoint" ), "role_entrypoint" , searchprio = - 1
103
- ),
104
- }
105
-
106
- @property
107
- def objects (self ) -> dict [tuple [str , str ], tuple [str , str ]]:
108
- return self .data .setdefault (
109
- "objects" , {}
110
- ) # (objtype, name) -> docname, labelid
111
-
112
- def note_object (
113
- self , objtype : str , name : str , labelid : str , location : t .Any = None
114
- ) -> None :
115
- if (objtype , name ) in self .objects :
116
- docname = self .objects [objtype , name ][0 ]
117
- logger .warning (
118
- f"Duplicate { objtype } description of { name } , other instance in { docname } " ,
119
- location = location ,
120
- )
121
- self .objects [objtype , name ] = (self .env .docname , labelid )
122
-
123
- def merge_domaindata (self , docnames : list [str ], otherdata : dict ) -> None :
124
- """Merge in data regarding *docnames* from a different domaindata
125
- inventory (coming from a subprocess in parallel builds).
126
- """
127
-
128
- def resolve_any_xref (
129
- self ,
130
- env : BuildEnvironment ,
131
- fromdocname : str ,
132
- builder : Builder ,
133
- target : str ,
134
- node : addnodes .pending_xref ,
135
- contnode : Element ,
136
- ) -> list [tuple [str , Element ]]:
137
- """Resolve the pending_xref *node* with the given *target*."""
138
- return []
139
-
140
-
141
98
class _Plugin (YAMLDirective [AnsiblePlugin ]):
142
99
schema = AnsiblePlugin
143
100
@@ -241,16 +198,12 @@ def _run(
241
198
title = titles [0 ]
242
199
self .state .document .note_explicit_target (title )
243
200
std = t .cast (StandardDomain , self .env .get_domain ("std" ))
244
- rst_id = (
245
- f"ansible_collections. { content .fqcn } _ { content .plugin_type } _requirements"
201
+ rst_id = get_requirements_ref (
202
+ content .fqcn , content .plugin_type , content . role_entrypoint
246
203
)
247
204
plugin_name = _plugin_name (content .fqcn , content .plugin_type )
248
205
ref_title = f"Requirements of the { plugin_name } "
249
206
if content .role_entrypoint is not None and content .plugin_type == "role" :
250
- rst_id = (
251
- f"ansible_collections.{ content .fqcn } _role"
252
- f"-{ content .role_entrypoint } _requirements"
253
- )
254
207
ref_title = f"{ ref_title } , { content .role_entrypoint } entrypoint"
255
208
std .note_hyperlink_target (
256
209
rst_id ,
@@ -270,9 +223,8 @@ class _Attribute(YAMLDirective[AnsibleAttribute]):
270
223
271
224
def _run (self , content_str : str , content : AnsibleAttribute ) -> list [nodes .Node ]:
272
225
html_id = f"attribute-{ _percent_encode (content .name )} "
273
- rst_id = (
274
- f"ansible_collections.{ content .fqcn } _{ content .plugin_type } "
275
- f"__attribute-{ content .name } "
226
+ rst_id = get_attribute_ref (
227
+ content .fqcn , content .plugin_type , content .role_entrypoint , content .name
276
228
)
277
229
node = ansible_attribute (
278
230
"" , content .name , classes = ["ansible-option-title" ], ids = [html_id ]
@@ -309,17 +261,16 @@ def _compile_ids(
309
261
role_entrypoint : str | None ,
310
262
full_keys : list [list [str ]],
311
263
prefix_type : str ,
264
+ get_ref : t .Callable [[str , str , str | None , list [str ]], str ],
312
265
) -> tuple [dict [str , tuple [str , str , str ]], list [str ]]:
313
- rst_id_prefix = f"ansible_collections.{ fqcn } _{ plugin_type } __{ prefix_type } -"
314
266
html_id_prefix = f"{ prefix_type } -"
315
267
if role_entrypoint is not None :
316
- rst_id_prefix += f"{ role_entrypoint } __"
317
268
html_id_prefix += f"{ role_entrypoint } --"
318
269
rst_ids = {}
319
270
html_ids = []
320
271
for full_key in full_keys :
321
272
html_id = html_id_prefix + "/" .join ([_percent_encode (k ) for k in full_key ])
322
- rst_id = rst_id_prefix + "/" . join ([ massage_rst_label ( k ) for k in full_key ] )
273
+ rst_id = get_ref ( fqcn , plugin_type , role_entrypoint , full_key )
323
274
html_ids .append (html_id )
324
275
rst_ids [rst_id ] = (html_id , "." .join (full_key ), "." .join (full_key [1 :]))
325
276
return rst_ids , _make_unique (html_ids )
@@ -335,6 +286,7 @@ def _run(self, content_str: str, content: AnsibleOption) -> list[nodes.Node]:
335
286
content .role_entrypoint ,
336
287
content .full_keys ,
337
288
"parameter" ,
289
+ get_option_ref ,
338
290
)
339
291
node = ansible_option (
340
292
"" ,
@@ -392,6 +344,7 @@ def _run(self, content_str: str, content: AnsibleReturnValue) -> list[nodes.Node
392
344
content .role_entrypoint ,
393
345
content .full_keys ,
394
346
"return" ,
347
+ get_return_value_ref ,
395
348
)
396
349
node = ansible_return_value (
397
350
"" ,
@@ -446,6 +399,5 @@ def setup_directives(app):
446
399
"""
447
400
Setup directives for a Sphinx app object.
448
401
"""
449
- app .add_domain (AnsibleDomain )
450
402
for name , directive in DIRECTIVES .items ():
451
403
app .add_directive (name , directive )
0 commit comments