Add :zuul:path support

This is to support documenting zookeeper paths in the Zuul developer
docs.

Change-Id: Id29eee89b38b34a3dac09750d6cabb442551e211
This commit is contained in:
James E. Blair 2021-11-11 14:22:53 -08:00
parent ca54cdca93
commit a8465c7cc1
3 changed files with 101 additions and 2 deletions

View File

@ -0,0 +1,32 @@
ZooKeeper Paths
---------------
.. path:: zuul
This is an example Zookeeper path
.. path:: zuul/tenant
A sub path. Since paths can get quite long, you may choose to
indent or to specify the full path. The signature will appear the
same either way.
.. path:: <bar>
:ephemeral:
Another sub path.
.. path:: lock
:type: RLock
:ephemeral:
Another sub path.
.. path:: zuul-system
Another top level path.
References
==========
This is a path role: :path:`zuul/tenant/<bar>/lock`

View File

@ -44,6 +44,7 @@ Examples
example-roles example-roles
example-autodoc example-autodoc
example-statistics example-statistics
example-paths
Indices and tables Indices and tables
------------------ ------------------

View File

@ -234,7 +234,9 @@ class ZuulObjectDescription(ZuulDirective, ObjectDescription):
'var': 'variable', 'var': 'variable',
'jobvar': 'job variable', 'jobvar': 'job variable',
'rolevar': 'role variable', 'rolevar': 'role variable',
'path': 'path',
} }
separator = '.'
def get_path(self): def get_path(self):
return self.env.ref_context.get('zuul:attr_path', []) return self.env.ref_context.get('zuul:attr_path', [])
@ -244,12 +246,12 @@ class ZuulObjectDescription(ZuulDirective, ObjectDescription):
@property @property
def parent_pathname(self): def parent_pathname(self):
return '.'.join(self.get_display_path()) return self.separator.join(self.get_display_path())
@property @property
def full_pathname(self): def full_pathname(self):
name = self.names[-1].lower() name = self.names[-1].lower()
return '.'.join(self.get_path() + [name]) return self.separator.join(self.get_path() + [name])
def add_target_and_index(self, name, sig, signode): def add_target_and_index(self, name, sig, signode):
targetname = self.objtype + '-' + self.full_pathname targetname = self.objtype + '-' + self.full_pathname
@ -510,6 +512,67 @@ class ZuulStatDirective(ZuulObjectDescription):
return sig return sig
class ZuulPathDirective(ZuulObjectDescription):
has_content = True
option_spec = {
'ephemeral': lambda x: x,
'noindex': lambda x: x,
'example': lambda x: x,
'type': lambda x: x,
}
separator = '/'
def before_content(self):
path = self.env.ref_context.setdefault('zuul:attr_path', [])
path.append(self.names[-1])
path = self.env.ref_context.setdefault('zuul:display_attr_path', [])
path.append(self.names[-1])
def after_content(self):
path = self.env.ref_context.get('zuul:attr_path')
if path:
path.pop()
path = self.env.ref_context.get('zuul:display_attr_path')
if path:
path.pop()
def handle_signature(self, sig, signode):
path = self.get_display_path()
signode['is_multiline'] = True
line = addnodes.desc_signature_line()
line['add_permalink'] = True
line += addnodes.desc_addname('/', '/')
for x in path:
line += addnodes.desc_addname(x + '/', x + '/')
for x in sig.split('/')[:-1]:
line += addnodes.desc_addname(x + '/', x + '/')
last = sig.split('/')[-1]
line += addnodes.desc_name(last, last)
signode += line
if 'type' in self.options:
line = addnodes.desc_signature_line()
line += addnodes.desc_type('Type: ', 'Type: ')
line += nodes.emphasis(self.options['type'],
self.options['type'])
signode += line
elif 'ephemeral' in self.options:
line = addnodes.desc_signature_line()
signode += line
if 'ephemeral' in self.options:
# This is appended to the type line, or a new blank line
# if no type.
line += addnodes.desc_annotation(' (ephemeral)', ' (ephemeral)')
if 'example' in self.options:
line = addnodes.desc_signature_line()
line += addnodes.desc_type('Example: ', 'Example: ')
line += nodes.literal(self.options['example'],
self.options['example'])
signode += line
return sig
###################################################################### ######################################################################
# #
# Autodoc directives # Autodoc directives
@ -611,6 +674,7 @@ class ZuulDomain(Domain):
'stat': ZuulStatDirective, 'stat': ZuulStatDirective,
'jobvar': ZuulJobVarDirective, 'jobvar': ZuulJobVarDirective,
'rolevar': ZuulRoleVarDirective, 'rolevar': ZuulRoleVarDirective,
'path': ZuulPathDirective,
# Autodoc directives # Autodoc directives
'autojob': ZuulAutoJobDirective, 'autojob': ZuulAutoJobDirective,
'autojobs': ZuulAutoJobsDirective, 'autojobs': ZuulAutoJobsDirective,
@ -643,6 +707,8 @@ class ZuulDomain(Domain):
warn_dangling=True), warn_dangling=True),
'rolevar': XRefRole(innernodeclass=nodes.inline, # type: ignore 'rolevar': XRefRole(innernodeclass=nodes.inline, # type: ignore
warn_dangling=True), warn_dangling=True),
'path': XRefRole(innernodeclass=nodes.inline, # type: ignore
warn_dangling=True),
} }
initial_data = { initial_data = {