-
Notifications
You must be signed in to change notification settings - Fork 2
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
Replace optparse with argparse in suite_report.py #34
base: main
Are you sure you want to change the base?
Conversation
Remove the deprecated optparse module and replace it with an similar implementation using argparse.
Find and fix various problems reported by pylint.
Fixes everything but a single case where the options are either an E129 warning about having the same indentation as the next line or an E127 warning about over-indentation - and there doesn't seem to be a format that satisfies the checker!
Enable command line argument completion for the two directory options if/when argcomplete is available.
To keep the linter happy, most of the format() calls with f-strings. This supposedly offers better performance and is more in keeping with python 3.
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.
A couple of comments/queries in-line.
@@ -1712,13 +1724,15 @@ def gen_table_element(text_list, link, bold=False): | |||
if "working copy changes" in proj_dict: | |||
if proj_dict["working copy changes"]: | |||
wc_text = "YES" | |||
# pylint: disable=consider-using-f-string |
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.
Having made so many the conversion to f-string format statements, there just 3 older style .format()
s left. Why these?
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.
Good point. It feels like there should be a more elegant way to format these string, but it's not immediately clear to me what it is. Perhaps they should be a property of the instance?
I'll take a look at the other pylint fstring exclusions and see if I can improve those too.
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.
Happy to accept most of my comments will be addressed in the refactor ticket.
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.
Would this be a good one to us os.path.join on instead of creating a string manually ?
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 would always prefer to see os.path.join()
rather than a string with /
s in. It's then platform safe should someone try to run on Windows.
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.
A better python 3 method is to use pathlib.Path because this allows the use of a slash to join paths while retaining platform independence.
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.
Hmmm, this looks like an also ticket....
Lets reconfigure it to use "argparse" and also do quite a lot of linting improvements...
Should it be 2 PRs 😃
Just looking at that - there were some "things were going to get back to later..." like the verbosity level which I'm amused to see are still untouched. Any chance they could be considered in the "major refactor" you mention ?
trac_log.append( | ||
" || Cylc-Review: || {0:s}/{1:s}/{2:s}/?suite={3:s} || ".format( | ||
" || Cylc-Review: || {0:s}/{1:s}/{2:s}/?suite={3:s} || " |
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.
Another where it might be useful to split out into multiple 'steps'
use os.path.join() to join all the parts together into a string which you assign to "sodding_path", and then use an f-string with {sodding_path} in it.
# on a JULES rose-stem suite as JULES has no 'need' of the two | ||
# compare variables and to prevent the warning their absence | ||
# would produce from occuring unnecessarily in JULES they have | ||
# been added to rose-suite.conf for now |
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.
In general - are these not dead yet ? does the UM trac.log still report on compare wallclock and compare output tests ?
@@ -2053,15 +2075,15 @@ def print_report(self): | |||
print(err) | |||
try: | |||
suite_dir = self.suite_path | |||
except: | |||
except Exception: |
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.
Perhaps be more specific what exception is expected here or spit the error message inside the except block?
Reviewer has pointed out that the comment about the UM respository is no longer correct. The text has been amended to reference the SimSys_Scripts github repo instead.
Following suggestion from reviewer to remove one of the small number of remaining formats in the code.
Apply fix suggested by reviewer
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 only script using
optparse
wassuite_report.py
. This has been updated to useargparse
and the script has been linted and its compliance with flake8 improved.A before and after comparison of the output from
suite_report.py
shows no change in behaviour:See also: UM ticket 7722