Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
wxtim committed Aug 21, 2024
1 parent 5a37277 commit 3ae39c8
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 12 deletions.
8 changes: 8 additions & 0 deletions cylc/sphinx_ext/cylc_lang/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,11 @@
.. rst-example::
.. auto-cylc-global:: {workflow_path}
:show:
foo,
install target,
bar,
qax
.. rst:directive:: .. auto-cylc-workflow:: source
Expand All @@ -227,6 +232,9 @@
.. rst-example::
.. auto-cylc-workflow:: {workflow_path}/workflow
:show:
foo,
platform
"""


Expand Down
60 changes: 48 additions & 12 deletions cylc/sphinx_ext/cylc_lang/autodocumenters.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
)
from typing import Any, Dict, List, Optional

from docutils.parsers.rst import Directive
from docutils.parsers.rst import Directive, directives
from docutils.statemachine import StringList, ViewList

from sphinx import addnodes, project
Expand Down Expand Up @@ -397,10 +397,17 @@ class CylcGlobalDirective(SphinxDirective):
"""Represent a Cylc Global Config.
"""
optional_arguments = 1
option_spec = {
'show': directives.split_escaped_whitespace
}

def run(self):
display_these = None
if 'show' in self.options:
display_these = [
i.strip() for i in self.options['show'][0].split(',')]
src = self.arguments[0] if self.arguments else None
ret = self.config_to_node(load_cfg(src), src)
ret = self.config_to_node(load_cfg(src), src, display_these)
node = addnodes.desc_content()
self.state.nested_parse(
StringList(ret),
Expand All @@ -410,7 +417,11 @@ def run(self):
return [node]

@staticmethod
def config_to_node(config: [Dict, Any], src: str) -> List[str]:
def config_to_node(
config: [Dict, Any],
src: str,
display_these=None,
) -> List[str]:
"""Take a global config and create a node for display.
* Displays `platform groups` and then `platforms`.
Expand Down Expand Up @@ -482,13 +493,13 @@ def config_to_node(config: [Dict, Any], src: str) -> List[str]:
# Custom keys:
section_content += custom_items(meta)

# Key list needs a closing space:
section_content.append('')
if display_these:
section_content += custom_items(conf, these=display_these)

# Add description tag.
description = meta.get('description', '')
if description:
section_content.append(description)
section_content += ['', description, '']

content += directive(
CYLC_CONF, [title], content=section_content)
Expand All @@ -510,11 +521,19 @@ class CylcWorkflowDirective(SphinxDirective):
"""Represent a Cylc Workflow Config.
"""
required_arguments = 1
option_spec = {
'show': directives.split_escaped_whitespace
}

def run(self):
display_these = None
if 'show' in self.options:
display_these = [
i.strip() for i in self.options['show'][0].split(',')]
ret = self.config_to_node(
load_cfg(self.arguments[0]),
self.arguments[0]
self.arguments[0],
display_these
)
node = addnodes.desc_content()
self.state.nested_parse(
Expand All @@ -525,7 +544,7 @@ def run(self):
return [node]

@staticmethod
def config_to_node(config, src):
def config_to_node(config, src, display_these=None):
"""Document Workflow
Additional processing:
Expand Down Expand Up @@ -573,6 +592,10 @@ def config_to_node(config, src):
# Custom keys:
task_content += custom_items(task_meta)

# Config keys given
if display_these:
task_content += custom_items(taskdef, display_these)

desc = task_meta.get('description', '')
if desc:
task_content += ['', desc, '']
Expand Down Expand Up @@ -651,16 +674,29 @@ def custom_items(
data: The input dictionary.
not_these: Keys to ignore.
these: Keys to include.
Examples:
>>> data = {'foo': 'I cannot believe it!', 'title': 'Hi'}
>>> custom_items(data)
:foo:
I cannot believe it!
>>> custom(data, these=['title'])
:title:
Hi
"""
ret = []
if these:
for key in these:
value = data.get('key', '')
value = value.replace("\n", "\n ")
ret.append(f':{key}:\n {value}')
value = data.get(key, '')
if value and isinstance(value, str):
value = value.replace("\n", "\n ")
ret.append(f':{key}:\n {value}')
else:
for key, val in data.items():
if key not in (not_these or ['title', 'description', 'URL']):
if (
key not in (not_these or ['title', 'description', 'URL'])
and isinstance(val, str)
):
value = val.replace("\n", "\n ")
ret.append(f':{key}:\n {value}')
return ret
1 change: 1 addition & 0 deletions etc/flow/global.cylc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
[[camden_town]]
hosts = northern, buslink
job runner = pbs
install target = northern
[platform groups]
[[northern line]]
platforms = camden_town, mornington_crescent

0 comments on commit 3ae39c8

Please sign in to comment.