Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint S014: Only warn about -W when used for LSF #6551

Merged
merged 6 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes.d/6551.fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix bug in `cylc lint` S014 where it warned about use of legitimate `-W` directive for PBS.
25 changes: 20 additions & 5 deletions cylc/flow/scripts/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,20 @@ def get_wallclock_directives():
'TIME_LIMIT_DIRECTIVE',
None
)
if directive:
directives[module.name] = directive
if directive and directive == '-W':
# LSF directive -W needs to have a particular form to
# avoid matching PBS directive -W:
directives[module.name] = re.compile(
r'^-W\s*=?\s*(\d+:)?\d+[^/]*$')
elif directive:
directives[module.name] = re.compile(rf'^{directive}.*')
return directives


WALLCLOCK_DIRECTIVES = get_wallclock_directives()


def check_wallclock_directives(line: str) -> Union[Dict[str, str], bool]:
def check_wallclock_directives(line: str) -> Dict[str, str]:
"""Check for job runner specific directives
equivalent to exection time limit.

Expand All @@ -209,11 +214,21 @@ def check_wallclock_directives(line: str) -> Union[Dict[str, str], bool]:
>>> this = check_wallclock_directives
>>> this(' -W 42:22')
{'directive': '-W 42:22'}
>>> this(' -W 42:22/hostname') # Legit LSF use case
oliver-sanders marked this conversation as resolved.
Show resolved Hide resolved
{}
>>> this(' -W 422')
{'directive': '-W 422'}
>>> this(' -W foo=42') # Legit PBS use case.
{}
>>> this(' -W foo="Hello World"') # Legit PBS use case.
{}
>>> this(' -l walltime whatever')
{'directive': '-l walltime whatever'}
"""
for directive in set(WALLCLOCK_DIRECTIVES.values()):
if line.strip().startswith(directive):
if directive.findall(line.strip()):
return {'directive': line.strip()}
return False
return {}


def check_jinja2_no_shebang(
Expand Down
Loading