Skip to content

Commit 0d204cc

Browse files
authored
Lint S014: Only warn about -W when used for LSF (#6551)
1 parent ab87e15 commit 0d204cc

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

changes.d/6551.fix.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix bug in `cylc lint` S014 where it warned about use of legitimate `-W` directive for PBS.

cylc/flow/scripts/lint.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,15 +189,20 @@ def get_wallclock_directives():
189189
'TIME_LIMIT_DIRECTIVE',
190190
None
191191
)
192-
if directive:
193-
directives[module.name] = directive
192+
if directive and directive == '-W':
193+
# LSF directive -W needs to have a particular form to
194+
# avoid matching PBS directive -W:
195+
directives[module.name] = re.compile(
196+
r'^-W\s*=?\s*(\d+:)?\d+[^/]*$')
197+
elif directive:
198+
directives[module.name] = re.compile(rf'^{directive}.*')
194199
return directives
195200

196201

197202
WALLCLOCK_DIRECTIVES = get_wallclock_directives()
198203

199204

200-
def check_wallclock_directives(line: str) -> Union[Dict[str, str], bool]:
205+
def check_wallclock_directives(line: str) -> Dict[str, str]:
201206
"""Check for job runner specific directives
202207
equivalent to exection time limit.
203208
@@ -209,11 +214,21 @@ def check_wallclock_directives(line: str) -> Union[Dict[str, str], bool]:
209214
>>> this = check_wallclock_directives
210215
>>> this(' -W 42:22')
211216
{'directive': '-W 42:22'}
217+
>>> this(' -W 42:22/hostname') # Legit LSF use case
218+
{}
219+
>>> this(' -W 422')
220+
{'directive': '-W 422'}
221+
>>> this(' -W foo=42') # Legit PBS use case.
222+
{}
223+
>>> this(' -W foo="Hello World"') # Legit PBS use case.
224+
{}
225+
>>> this(' -l walltime whatever')
226+
{'directive': '-l walltime whatever'}
212227
"""
213228
for directive in set(WALLCLOCK_DIRECTIVES.values()):
214-
if line.strip().startswith(directive):
229+
if directive.findall(line.strip()):
215230
return {'directive': line.strip()}
216-
return False
231+
return {}
217232

218233

219234
def check_jinja2_no_shebang(

0 commit comments

Comments
 (0)