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

Replace optparse with argparse in suite_report.py #34

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

t00sa
Copy link
Contributor

@t00sa t00sa commented Aug 12, 2024

The only script using optparse was suite_report.py. This has been updated to use argparse 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:

vdi> python suite_report.py -S ~/cylc-run/vn13.6_remove_optparse/runN/ -L /var/tmp
svn://fcm1/monc.xm_svn/casim/trunk appears to be the trunk, nothing to do!
svn://fcm1/jules.xm_svn/main/trunk appears to be the trunk, nothing to do!
svn://fcm1/moci.xm_svn/main/trunk appears to be the trunk, nothing to do!
svn://fcm1/um.xm_svn/mule/trunk appears to be the trunk, nothing to do!
svn://fcm1/utils.xm_svn/shumlib/trunk appears to be the trunk, nothing to do!
svn://fcm1/socrates.xm_svn/main/trunk appears to be the trunk, nothing to do!
svn://fcm1/ukca.xm_svn/main/trunk appears to be the trunk, nothing to do!
svn://fcm1/um.xm_svn/aux/trunk appears to be the trunk, nothing to do!
svn://fcm1/um.xm_svn/meta/trunk appears to be the trunk, nothing to do!
vdi> diff /var/tmp/trac.log ~/cylc-run/vn13.6_remove_optparse/runN/trac.log 
7c7
<  || Report Generated: || 2024/08/12 20:34:02 || 
---
>  || Report Generated: || 2024/08/12 13:53:01 ||
vdi> 

See also: UM ticket 7722

t00sa added 3 commits August 12, 2024 17:59
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!
@t00sa t00sa linked an issue Aug 12, 2024 that may be closed by this pull request
t00sa added 2 commits August 13, 2024 10:54
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.
@t00sa t00sa requested review from a team and ericaneininger and removed request for a team August 27, 2024 07:22
Copy link
Contributor

@ericaneininger ericaneininger left a 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.

suite_report.py Show resolved Hide resolved
suite_report.py Show resolved Hide resolved
@@ -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
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor

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 ?

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

@r-sharp r-sharp left a 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 ?

suite_report.py Outdated Show resolved Hide resolved
suite_report.py Show resolved Hide resolved
suite_report.py Show resolved Hide resolved
suite_report.py Show resolved Hide resolved
suite_report.py Show resolved Hide resolved
suite_report.py Outdated Show resolved Hide resolved
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} || "
Copy link
Contributor

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
Copy link
Contributor

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 ?

suite_report.py Outdated Show resolved Hide resolved
suite_report.py Outdated Show resolved Hide resolved
@@ -2053,15 +2075,15 @@ def print_report(self):
print(err)
try:
suite_dir = self.suite_path
except:
except Exception:
Copy link

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?

t00sa added 4 commits January 20, 2025 09:28
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
Copy link

@yaswant yaswant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@t00sa one minor comment: can you blackify the script please? Once #51 is merged, this script will need reformatting again to pass the CI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace optparse with argparse in scripts
4 participants