@@ -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
0 commit comments