@@ -81,6 +81,60 @@ def validate_job_schema(job_definition: Dict[str, Any]) -> Optional[str]:
81
81
return None
82
82
83
83
84
+ def get_job_doc_url (job : str , job_definition : Dict [str , Any ], manifest_url : str ) -> str :
85
+ """Returns the Job's documentation URL for a specific Job using the JOb's
86
+ 'doc-url' and manifest URL. The job manifest is expected to
87
+ have been validated, and we expect to have been given one job structure
88
+ from the job's definition, not the whole job definition file.
89
+ """
90
+ assert job
91
+ assert isinstance (job_definition , dict )
92
+ assert manifest_url
93
+
94
+ # The response depends on the value of 'doc-url'.
95
+ # 1. If there is no doc-url the URL is auto-generated
96
+ # from the manifest URL, job collection and job name.
97
+ # 2. If the doc-url begins 'https://' then this is taken as the doc-url
98
+ # 3. If the doc-url does not begin https:// then is
99
+ # assumed to be relative to the manifest directory URL
100
+
101
+ # A typical manifest URl will look like this...
102
+ #
103
+ # https://raw.githubusercontent.com/InformaticsMatters/
104
+ # virtual-screening/main/data-manager/manifest-virtual-screening.yaml
105
+ #
106
+ # The base for an auto-generated doc-url (if we need it)
107
+ # will be: -
108
+ #
109
+ # https://raw.githubusercontent.com/InformaticsMatters/
110
+ # virtual-screening/main/data-manager/docs
111
+
112
+ collection : str = job_definition ["collection" ]
113
+ doc_url : Optional [str ] = job_definition .get ("doc-url" , None )
114
+
115
+ # If doc-url starts 'https://' just return it
116
+ if doc_url and doc_url .startswith ("https://" ):
117
+ return doc_url
118
+
119
+ # If the doc-url is set (it's not https://)
120
+ # so we assume is simply relative to the 'docs' directory
121
+ # where the manifest is found.
122
+ manifest_directory_url , _ = os .path .split (manifest_url )
123
+ if doc_url and not doc_url .startswith ("https://" ):
124
+ # doc-url defined but does not start 'https://'
125
+ doc_url = f"{ manifest_directory_url } /docs/{ doc_url } "
126
+ elif doc_url is None :
127
+ # No doc-url.
128
+ # The
129
+ doc_url = f"{ manifest_directory_url } /docs/{ collection } /{ job } .md"
130
+ else :
131
+ # How did we get here?
132
+ assert False
133
+
134
+ assert doc_url
135
+ return doc_url
136
+
137
+
84
138
def decode (
85
139
template_text : str ,
86
140
variable_map : Optional [Dict [str , str ]],
0 commit comments