-
Notifications
You must be signed in to change notification settings - Fork 92
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
Allow CLI selection of a single rule to check. #6120
Conversation
a0ad10e
to
23cc46f
Compare
PR title and description don't appear to match? Does this do both? If so maybe a bugfix changelog entry? |
Fix a bug where empty flow.cylc files caused traceback.
23cc46f
to
d235ca8
Compare
Yes. Sorry - original text not super clear. Have added the changelog entry as suggested. |
cylc/flow/loggingutil.py
Outdated
def log_iterable( | ||
items: Iterable, | ||
header: str, | ||
singular_header: str, | ||
) -> str: | ||
"""Log a list. | ||
|
||
Args: | ||
items: The iterable | ||
singular_header: To use if list has length 1 | ||
header: To use otherwise | ||
""" | ||
if len(items) == 0: | ||
raise ValueError('This function does not take len==0 iterables') | ||
elif len(items) == 1: | ||
return singular_header.format(items[0]) | ||
else: | ||
msg = header + '\n * ' | ||
msg += '\n * '.join(items) | ||
return msg |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function feels a bit over-complicated for a single use.
I think it should fail type checking as generators are iterables but are not supported by len()
?
Not sure if mypy is smart enough to spot that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is over complicated for a single use. I think that this is code we've replicated in a number of places, and may want again in future . The idea is that this function is available for refactoring elsewhere and for future use cases. Probably also needs list truncation logic too.
- config.py, 570, 2584
- platforms.py 700
- rundb 938
You're right about the type hinting though: My local copy of MyPy has certainly picked that up.
4f6d30e
to
dd0d00b
Compare
dd0d00b
to
a172396
Compare
@@ -1417,6 +1434,14 @@ def main(parser: COP, options: 'Values', target=None) -> None: | |||
max_line_len=mergedopts[MAX_LINE_LENGTH] | |||
) | |||
|
|||
if options.rule: | |||
checks = {k: v for k, v in checks.items() if k in options.rule} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can be simplified to:
checks = {rule: checks[rule] for rule in options.rule}
Which has the advantage of raising an error if a rule does not exist.
checks = {k: v for k, v in checks.items() if k in options.rule} | |
try: | |
checks = {rule: checks[rule] for rule in options.rule} | |
except KeyError as exc: | |
LOG.error(f'No such rule {exc.args[0]}') | |
sys.exit(1) |
However, it looks like --rule
can only accept one rule at present? If so we don't need the dict comprehension.
I feel we should implement this more like --select
(ruff/flake8), to allow the selection of rules OR rule sets?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rule can apply multiple rules:
cylc lint /var/tmp/cylc-src/mean.marble -R S001 -R S002
I feel we should implement this more like --select (ruff/flake8), to allow the selection of rules OR rule sets?
A legit point - I'll have a poke and see if I can do that without having two CLI args.
Should cut down the amount of code
parser.add_option( | ||
'--rule', '-R', | ||
help='Carry out only specific checks.', | ||
choices=list(parse_checks(['style', '728']).keys()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So --rule
can be one of style
or 728
.
AND --ruleset
can be one of style
, 728
or all
.
What's the point of --rule
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The --select
/ --ignore
interface of ruff
is a good gauge of how to go about implementing rule selection.
--select=R # select all Rxxx rules
--select=R001 # select only R001
--select=R --ignore=R001 # select all R other than R001
--select=R001,R002 # select both R001 and R002
--select=ALL # magic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AND --ruleset can be one of style, 728 or all.
No - rulest can be any of the items in the parsed checks for both rulesets currently available because
>>> parse_checks(['style', '728'].keys()
DictKeys('S001', 'S002' ... ... 'R999')
Side effect of this is that the safety mechanism (try/except) is completely redundant.
Redrafting - not a priority |
Roll this into the full refactor of Cylc Lint - probably a good training day activity for Tim |
Closes #5544
Additionally...
Fix a bug where empty flow.cylc files caused traceback.
To replicate
Check List
CONTRIBUTING.md
and added my name as a Code Contributor.setup.cfg
(andconda-environment.yml
if present).CHANGES.md
entry included if this is a change that can affect users?.?.x
branch.