|
67 | 67 | TOMLDecodeError,
|
68 | 68 | )
|
69 | 69 | from typing import (
|
70 |
| - TYPE_CHECKING, Any, Callable, Dict, Iterator, List, Union) |
| 70 | + TYPE_CHECKING, Any, Callable, Dict, Iterator, List, Optional, Union) |
71 | 71 |
|
72 | 72 | from cylc.flow import LOG
|
73 | 73 | from cylc.flow.exceptions import CylcError
|
|
106 | 106 | }
|
107 | 107 |
|
108 | 108 |
|
| 109 | +DEPRECATED_STRING_TEMPLATES = { |
| 110 | + 'suite': 'workflow', |
| 111 | + 'suite_uuid': 'uuid', |
| 112 | + 'batch_sys_name': 'job_runner_name', |
| 113 | + 'batch_sys_job_id': 'job_id', |
| 114 | + 'user@host': 'platform_name', |
| 115 | + 'task_url': '``URL`` (if set in :cylc:conf:`[meta]URL`)', |
| 116 | + 'workflow_url': ( |
| 117 | + '``workflow_URL`` (if set in ' |
| 118 | + ':cylc:conf:`[runtime][<namespace>][meta]URL`)'), |
| 119 | +} |
| 120 | + |
| 121 | + |
| 122 | +LIST_ITEM = ' * ' |
| 123 | + |
| 124 | + |
| 125 | +deprecated_string_templates = { |
| 126 | + key: ( |
| 127 | + re.compile(r'%\(' + key + r'\)s'), |
| 128 | + value |
| 129 | + ) |
| 130 | + for key, value in DEPRECATED_STRING_TEMPLATES.items() |
| 131 | +} |
| 132 | + |
| 133 | + |
109 | 134 | def check_jinja2_no_shebang(
|
110 | 135 | line: str,
|
111 | 136 | file: Path,
|
@@ -233,6 +258,36 @@ def check_for_obsolete_environment_variables(line: str) -> List[str]:
|
233 | 258 | return [i for i in OBSOLETE_ENV_VARS if i in line]
|
234 | 259 |
|
235 | 260 |
|
| 261 | +def check_for_deprecated_task_event_template_vars( |
| 262 | + line: str |
| 263 | +) -> Optional[Dict[str, str]]: |
| 264 | + """Look for string variables which are no longer supported |
| 265 | +
|
| 266 | + Examples: |
| 267 | + >>> this = check_for_deprecated_task_event_template_vars |
| 268 | +
|
| 269 | + >>> this('hello = "My name is %(suite)s"') |
| 270 | + {'list': ' * %(suite)s ⇒ %(workflow)s'} |
| 271 | +
|
| 272 | + >>> expect = {'list': ( |
| 273 | + ... ' * %(suite)s ⇒ %(workflow)s * %(task_url)s' |
| 274 | + ... ' - get ``URL`` (if set in :cylc:conf:`[meta]URL`)')} |
| 275 | + >>> this('hello = "My name is %(suite)s, %(task_url)s"') == expect |
| 276 | + True |
| 277 | + """ |
| 278 | + result = [] |
| 279 | + for key, (regex, replacement) in deprecated_string_templates.items(): |
| 280 | + search_outcome = regex.findall(line) |
| 281 | + if search_outcome and ' ' in replacement: |
| 282 | + result.append(f'%({key})s - get {replacement}') |
| 283 | + elif search_outcome: |
| 284 | + result.append(f'%({key})s ⇒ %({replacement})s') |
| 285 | + |
| 286 | + if result: |
| 287 | + return {'list': LIST_ITEM + LIST_ITEM.join(result)} |
| 288 | + return None |
| 289 | + |
| 290 | + |
236 | 291 | INDENTATION = re.compile(r'^(\s*)(.*)')
|
237 | 292 |
|
238 | 293 |
|
@@ -584,6 +639,23 @@ def check_indentation(line: str) -> bool:
|
584 | 639 | ),
|
585 | 640 | FUNCTION: re.compile(r'rose +date').findall,
|
586 | 641 | },
|
| 642 | + 'U015': { |
| 643 | + 'short': ( |
| 644 | + 'Deprecated template variables.'), |
| 645 | + 'rst': ( |
| 646 | + 'The following template variables, mostly used in event handlers,' |
| 647 | + 'are deprecated, and should be replaced:' |
| 648 | + + ''.join([ |
| 649 | + f'\n * ``{old}`` ⇒ {new}' |
| 650 | + for old, new in DEPRECATED_STRING_TEMPLATES.items() |
| 651 | + ]) |
| 652 | + ), |
| 653 | + 'url': ( |
| 654 | + 'https://cylc.github.io/cylc-doc/stable/html/user-guide/' |
| 655 | + 'writing-workflows/runtime.html#task-event-template-variables' |
| 656 | + ), |
| 657 | + FUNCTION: check_for_deprecated_task_event_template_vars, |
| 658 | + } |
587 | 659 | }
|
588 | 660 | RULESETS = ['728', 'style', 'all']
|
589 | 661 | EXTRA_TOML_VALIDATION = {
|
@@ -1077,7 +1149,7 @@ def get_cylc_files(
|
1077 | 1149 | 'section heading': '\n{title}\n{underline}\n',
|
1078 | 1150 | 'issue heading': {
|
1079 | 1151 | 'text': '\n{check}:\n {summary}\n {url}\n\n',
|
1080 |
| - 'rst': '\n`{check} <{url}>`_\n{underline}\n{summary}\n\n', |
| 1152 | + 'rst': '\n{url}_\n{underline}\n{summary}\n\n', |
1081 | 1153 | },
|
1082 | 1154 | 'auto gen message': (
|
1083 | 1155 | 'U998 and U999 represent automatically generated'
|
@@ -1122,16 +1194,17 @@ def get_reference(linter, output_type):
|
1122 | 1194 | output += '\n'
|
1123 | 1195 | output += '\n* ' + summary
|
1124 | 1196 | else:
|
| 1197 | + check = get_index_str(meta, index) |
1125 | 1198 | template = issue_heading_template
|
1126 | 1199 | url = get_url(meta)
|
| 1200 | + if output_type == 'rst': |
| 1201 | + url = f'`{check} <{url}>`' if url else f'{check}' |
1127 | 1202 | msg = template.format(
|
1128 | 1203 | title=index,
|
1129 |
| - check=get_index_str(meta, index), |
| 1204 | + check=check, |
1130 | 1205 | summary=summary,
|
1131 | 1206 | url=url,
|
1132 |
| - underline=( |
1133 |
| - len(get_index_str(meta, index)) + len(url) + 6 |
1134 |
| - ) * '^' |
| 1207 | + underline=(len(url) + 1) * '^' |
1135 | 1208 | )
|
1136 | 1209 | output += msg
|
1137 | 1210 | output += '\n'
|
|
0 commit comments