Add :zuul:path support
This is to support documenting zookeeper paths in the Zuul developer docs. Change-Id: Id29eee89b38b34a3dac09750d6cabb442551e211
This commit is contained in:
parent
ca54cdca93
commit
a8465c7cc1
32
doc/source/example-paths.rst
Normal file
32
doc/source/example-paths.rst
Normal 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`
|
@ -44,6 +44,7 @@ Examples
|
||||
example-roles
|
||||
example-autodoc
|
||||
example-statistics
|
||||
example-paths
|
||||
|
||||
Indices and tables
|
||||
------------------
|
||||
|
@ -234,7 +234,9 @@ class ZuulObjectDescription(ZuulDirective, ObjectDescription):
|
||||
'var': 'variable',
|
||||
'jobvar': 'job variable',
|
||||
'rolevar': 'role variable',
|
||||
'path': 'path',
|
||||
}
|
||||
separator = '.'
|
||||
|
||||
def get_path(self):
|
||||
return self.env.ref_context.get('zuul:attr_path', [])
|
||||
@ -244,12 +246,12 @@ class ZuulObjectDescription(ZuulDirective, ObjectDescription):
|
||||
|
||||
@property
|
||||
def parent_pathname(self):
|
||||
return '.'.join(self.get_display_path())
|
||||
return self.separator.join(self.get_display_path())
|
||||
|
||||
@property
|
||||
def full_pathname(self):
|
||||
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):
|
||||
targetname = self.objtype + '-' + self.full_pathname
|
||||
@ -510,6 +512,67 @@ class ZuulStatDirective(ZuulObjectDescription):
|
||||
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
|
||||
@ -611,6 +674,7 @@ class ZuulDomain(Domain):
|
||||
'stat': ZuulStatDirective,
|
||||
'jobvar': ZuulJobVarDirective,
|
||||
'rolevar': ZuulRoleVarDirective,
|
||||
'path': ZuulPathDirective,
|
||||
# Autodoc directives
|
||||
'autojob': ZuulAutoJobDirective,
|
||||
'autojobs': ZuulAutoJobsDirective,
|
||||
@ -643,6 +707,8 @@ class ZuulDomain(Domain):
|
||||
warn_dangling=True),
|
||||
'rolevar': XRefRole(innernodeclass=nodes.inline, # type: ignore
|
||||
warn_dangling=True),
|
||||
'path': XRefRole(innernodeclass=nodes.inline, # type: ignore
|
||||
warn_dangling=True),
|
||||
}
|
||||
|
||||
initial_data = {
|
||||
|
Loading…
Reference in New Issue
Block a user