Skip to content

Commit 3f5fbec

Browse files
committed
re
1 parent b123fce commit 3f5fbec

File tree

4 files changed

+103
-27
lines changed

4 files changed

+103
-27
lines changed

cylc/sphinx_ext/cylc_lang/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,21 @@
222222
If you have a user config this will still override the site
223223
config!
224224
225+
----
226+
227+
Workflow Config
228+
^^^^^^^^^^^^^^^
229+
225230
.. rst-example::
226231
227232
.. cylc-metadata::
228233
:source: {workflow_path}
229234
235+
----
236+
237+
Global Config
238+
^^^^^^^^^^^^^
239+
230240
.. rst-example::
231241
232242
.. cylc-metadata::

cylc/sphinx_ext/cylc_lang/autodocumenters.py

Lines changed: 82 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,8 @@ def get_global_metadata(config):
466466

467467
@staticmethod
468468
def global_to_node(meta, src):
469-
"""Convert the global metadata into rst format."""
469+
"""Convert the global metadata into rst format.
470+
"""
470471
ret = [
471472
f'.. cylc:conf:: Global Config: {src}', '',
472473
f'{INDENT}.. note::', '',
@@ -490,26 +491,47 @@ def global_to_node(meta, src):
490491
f'{INDENT * 3}.. cylc:conf:: {title}', '',
491492
f'{INDENT * 4}.. csv-table:: Key Details', '']
492493

494+
# Add the definition regex if an explicit title
495+
# has been given to the platform.
493496
if title != regex:
494497
ret.append(f'{INDENT * 5}Regex, ``{regex}``.')
495498

496499
if info.get('job_runner'):
497500
ret.append(
498501
f'{INDENT * 5}job runner,'
499502
f' ``{info.get("job_runner")}``')
500-
503+
504+
# Lists platforms in group or hosts in platform.
501505
selectables = '- ' + '\n- '.join(
502506
f'``{i}``' for i in info["select_from"])
503-
ret.append(f'{INDENT * 5}{selects},"{selectables}"')
507+
ret += [f'{INDENT * 5}{selects},"{selectables}"', '']
508+
504509
ret.append('')
505-
desc = platform_meta.get("description", "No description")
510+
url = platform_meta.get('url', '')
511+
if url:
512+
ret += [
513+
f'{INDENT * 4}.. seealso::',
514+
'',
515+
f'{INDENT * 5}{url}',
516+
''
517+
]
518+
519+
# Add description.
520+
desc = platform_meta.get("description", "")
506521
ret += [
507522
f'{INDENT * 4}'
508523
f'{desc}',
509524
'']
510525

511-
[print(i) for i in ret]
512-
526+
# Add any other metadata as a definition list:
527+
ret += CylcMetadataDirective.meta_to_def_list(
528+
metadata=platform_meta.items(),
529+
lowest_indent=4
530+
)
531+
532+
# Handy for debugging:
533+
# [print(f'{i + 1:03}|{j}') for i, j in enumerate(ret)]
534+
513535
return ret
514536

515537
@staticmethod
@@ -577,30 +599,47 @@ def get_workflow_metadata(config, conf_path):
577599

578600
@staticmethod
579601
def workflow_to_node(meta, src):
580-
"""Convert workflow metadata to RST.
602+
"""Convert workflow metadata to list of strings for use as a node.
581603
582604
"""
583-
584-
# ret = [
585-
# f'.. {directive}::{" " if arguments else ""}{" ".join(arguments)}'
586-
# ]
587-
# rst = Doc()
588-
589-
# # Handle the workflow config metadata:
590-
# CylcMetadataDirective.write_section(rst, meta.get('workflow', {}), '#')
591-
592-
# # Handle the runtime config metadata:
593-
# rst.append('Runtime', '=')
594-
# for taskmeta in meta['runtime'].values():
595-
# CylcMetadataDirective.write_section(rst, taskmeta)
596605
ret = []
597606

607+
# Handle the workflow config metadata:
598608
workflow_title = meta.get('workflow', {}).get('title', src)
599-
ret.append(f'.. cylc:conf:: {workflow_title}')
600-
ret.append('')
601609
workflow_desc = meta.get('workflow', {}).get(
602-
'description', 'No Description').split('\n')
603-
ret += [f' {t.strip()}' for t in workflow_desc]
610+
'description', '').split('\n')
611+
612+
ret += [f'.. cylc:conf:: {workflow_title}', '']
613+
ret += [f' {t.strip()}' for t in workflow_desc] + ['']
614+
615+
# Handle the runtime config metadata:
616+
ret += [f'{INDENT}Runtime', f'{INDENT}=======', '']
617+
618+
for taskmeta in meta['runtime'].values():
619+
indent = INDENT
620+
title = taskmeta["title"]
621+
ret += [f'{indent}.. cylc:conf:: {title}', '']
622+
indent += INDENT
623+
624+
url = taskmeta.get('url', '')
625+
if url:
626+
ret += [
627+
f'{indent}.. seealso::',
628+
'',
629+
f'{indent + INDENT}{url}',
630+
''
631+
]
632+
633+
desc = taskmeta.get('description', '').replace('\n', ' ')
634+
ret += [f'{indent}{desc}', '']
635+
636+
ret += CylcMetadataDirective.meta_to_def_list(
637+
metadata=taskmeta.items(),
638+
lowest_indent=1
639+
)
640+
641+
# Handy for debugging:
642+
# [print(f'{i + 1:03}|{j}') for i, j in enumerate(ret)]
604643

605644
return ret
606645

@@ -622,3 +661,22 @@ def check_subproc_output(sub):
622661
msg += '\n'.join(
623662
i.strip("\n") for i in sub.stderr.decode().split('\n'))
624663
raise Exception(msg)
664+
665+
@staticmethod
666+
def meta_to_def_list(metadata, lowest_indent):
667+
result = []
668+
other_meta_items = False
669+
for key, value in metadata:
670+
if key in ['title', 'description', 'url']:
671+
continue
672+
if other_meta_items is False:
673+
result += [
674+
f'{INDENT * lowest_indent}Other metadata',
675+
f'{INDENT * lowest_indent}^^^^^^^^^^^^^^', '']
676+
other_meta_items = True
677+
value = value.replace('\n', ' ')
678+
result += [
679+
f'{INDENT * (lowest_indent + 1)}{key}:',
680+
f'{INDENT * (lowest_indent + 2)}{value}', '']
681+
682+
return result

etc/flow.cylc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929
[[bar]]
3030
[[[meta]]]
3131
description = """
32-
What should happen if I forget the title?
33-
Should I process RST?
32+
Lorem Ipsum blah blah blah
3433
"""
3534
url = 'https://www.myproject.com/tasks/bar'
36-
see also = Bar task docs.
35+
and another thing = Morse

etc/flow/global.cylc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,20 @@
66
If platform name is a regex you might want
77
an explicit title
88
"""
9+
url = https://www.mysupercomputer.ac.uk
910
[[mornington_crescent]]
1011
[[[meta]]]
1112
description = """
1213
I win!
1314
"""
15+
location = Otago
16+
contractor = Takahē Industries
17+
other info = """
18+
This is a longer
19+
chunk of metadata designed
20+
to see if the extra section
21+
handling can manage.
22+
"""
1423
[[camden_town]]
1524
hosts = northern, buslink
1625
job runner = pbs

0 commit comments

Comments
 (0)