-
Notifications
You must be signed in to change notification settings - Fork 4
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
103 we should be using the logging module #224
Conversation
…o be refactored to take advantage of this. #103
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #224 +/- ##
==========================================
+ Coverage 59.61% 60.76% +1.15%
==========================================
Files 30 30
Lines 2199 2238 +39
==========================================
+ Hits 1311 1360 +49
+ Misses 888 878 -10 ☔ View full report in Codecov by Sentry. |
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.
Just a small change on how the log_level
is set. I would do it directly within the argument parser instead of during parse_and_dispatch
.
benchcab/main.py
Outdated
# Intercept the verbosity flag to engage the logger | ||
log_level = 'debug' if args.get('verbose', False) == True else 'info' |
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 could be handled in the parser definition directly:
args_subcommand.add_argument(
"-v",
"--verbose",
help="Enable more detailed output in the command line.",
action="store_const",
default="info",
const="debug",
dest="log_level",
)
or something like that because I haven't tried it out... I believe action
isn't necessary but it doesn't hurt either.
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.
See, this was my first thought, but then I saw that the verbose argument is passed around 150+ times throughout the code so there is a bit of a refactoring exercise involved to ensure things still work. This suggestion is probably related to, but a bit outside the scope of this ticket.
Should we raise this as a different Issue and PR to address this?
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.
Yes, we can put it in a different issue.
benchcab/main.py
Outdated
# We just need to instantiate this with the desired level | ||
logger = get_logger(level=log_level) |
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.
Considering the suggestion above this would then need to change to:
# We just need to instantiate this with the desired level | |
logger = get_logger(level=log_level) | |
# We just need to instantiate this with the desired level | |
logger = get_logger(level=args.log_level) |
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.
See comment above :)
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.
Looks good. Just a few suggestions:
- Can you run
black
on your changes? - Can you run
ruff
on your changes and fix any small errors like unused imports etc? - Now that we have a logger, can you remove all occurrences of the
verbose
argument?
Also, I realise the integration test will fail due to #223. I will fix this today so that we have working integration tests. |
benchcab/benchcab.py
Outdated
# Copyright 2022 ACCESS-NRI and contributors. See the top-level COPYRIGHT file for details. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
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.
We shouldn't remove the copyright notice from this file. Can we reinstate please?
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.
Sure thing, I think it was when I was trying to get ruff to work, for some reason it didn't like the double "#" comments. Typically a triple quote is used at the top of Python files but I will see how it goes.
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.
Actually, I think this is ready. We will have to open an issue about the way log_level
is set.
I've added a comment yesterday about a deleted copyright statement in a file that needs to be added. Please make sure to add that statement back first and then this can be merged.
@SeanBryan51, OK. Massive update with merges and reversion to the native logger class. We had to do this because there is some python magic behind the scenes that will enable the native logger to pickle, whereas subclassing the native logger loses this ability. Many hours chasing that down. This means that we lose the ability for multi-line logging in a single call (which also means we retain the code location information in the log), and we have to call an explicit log call for each line, which is technically the proper practice and will enable us to later use a log-scanning framework to extract events from log lines. I've updated from main, merged, applied a bunch of changes suggested from ruff and black and ran the integration and pytest suites through to success. I think we're good to go on this. We should look at adding black and ruff to the GitHub actions in another PR, if we haven't already. Let me know if you have any questions. |
@bschroeter There is a minor conflict now with main since the merge of #232. Since Sean is away, I'll try and review. |
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've spotted a few errors while resolving merge conflicts. But otherwise only minor typos.
If you don't mind resubmitting for review once this is solved, I want to make sure I'm not missing anything else.
benchcab/benchcab.py
Outdated
pbs_config=config["fluxsite"]["pbs"], | ||
verbose=verbose, |
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.
We want to keep the pbs_config
argument here! That comes from #238
benchcab/benchcab.py
Outdated
# TODO(Sean) we should archive revision numbers for CABLE-AUX | ||
cable_aux_repo = SVNRepo( | ||
svn_root=internal.CABLE_SVN_ROOT, | ||
branch_path=internal.CABLE_AUX_RELATIVE_SVN_PATH, | ||
path=internal.SRC_DIR / "CABLE-AUX", | ||
) | ||
cable_aux_repo.checkout(verbose=verbose) |
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.
We removed this in #230
benchcab/benchcab.py
Outdated
print("Running fluxsite tasks...") | ||
if config["fluxsite"]["multiprocess"]: | ||
ncpus = config["fluxsite"]["pbs"]["ncpus"] | ||
try: | ||
multiprocess = config["fluxsite"]["multiprocess"] | ||
except KeyError: | ||
multiprocess = internal.FLUXSITE_DEFAULT_MULTIPROCESS | ||
if multiprocess: | ||
ncpus = config.get("pbs", {}).get( | ||
"ncpus", internal.FLUXSITE_DEFAULT_PBS["ncpus"] | ||
) | ||
run_tasks_in_parallel(tasks, n_processes=ncpus, verbose=verbose) | ||
else: | ||
run_tasks(tasks, verbose=verbose) | ||
print("Successfully ran fluxsite tasks") | ||
print("") | ||
run_tasks(tasks) | ||
self.logger.info("Successfully ran fluxsite tasks") |
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.
We want the version in main
here but I believe the print
at the top should call the logger.
benchcab/benchcab.py
Outdated
print("Running comparison tasks...") | ||
if config["fluxsite"]["multiprocess"]: | ||
ncpus = config["fluxsite"]["pbs"]["ncpus"] | ||
try: | ||
multiprocess = config["fluxsite"]["multiprocess"] | ||
except KeyError: | ||
multiprocess = internal.FLUXSITE_DEFAULT_MULTIPROCESS | ||
if multiprocess: | ||
try: | ||
ncpus = config["fluxsite"]["pbs"]["ncpus"] | ||
except KeyError: | ||
ncpus = internal.FLUXSITE_DEFAULT_PBS["ncpus"] |
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.
We want the version in main
. And we want to call self.logger.info
instead of print
on the first line.
benchcab/fluxsite.py
Outdated
model : Model | ||
Model. | ||
met_forcing_file : str | ||
Met forcinf file. |
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.
Met forcinf file. | |
Met forcing file. |
benchcab/model.py
Outdated
Parameters | ||
---------- | ||
repo : Repo | ||
Respository. |
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.
Respository. | |
Repository. |
benchcab/utils/singleton.py
Outdated
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.
Not used, remove?
benchcab/utils/__init__.py
Outdated
from importlib import resources | ||
from pathlib import Path | ||
|
||
import yaml | ||
|
||
# from benchcab.utils.singleton_logger import SingletonLogger |
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.
Remove instead of commented?
Thanks Claire - looks like the merge from main didn't pick up some of the recent changes. I'm working through these and getting an update PR ready for you. |
OK @ccarouge, I've gone back through everything and manually applied all of the changes that got clobbered over the last week. I think it should all be ok now... I've run all tests and integration and it seems to pass. Coverage drops, but otherwise I think this is ready? |
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.
@bschroeter There is one more clobbered conflict resolution. I think I have put the right code in the suggestion. Can you try it out before I give approval?
benchcab/benchcab.py
Outdated
self.logger.debug("Running comparison tasks...") | ||
try: | ||
multiprocess = config["fluxsite"]["multiprocess"] | ||
except KeyError: | ||
multiprocess = internal.FLUXSITE_DEFAULT_MULTIPROCESS | ||
if multiprocess: | ||
try: | ||
ncpus = config["fluxsite"]["pbs"]["ncpus"] | ||
except KeyError: | ||
ncpus = internal.FLUXSITE_DEFAULT_PBS["ncpus"] |
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.
Old version. We want:
self.logger.debug("Running comparison tasks...") | |
try: | |
multiprocess = config["fluxsite"]["multiprocess"] | |
except KeyError: | |
multiprocess = internal.FLUXSITE_DEFAULT_MULTIPROCESS | |
if multiprocess: | |
try: | |
ncpus = config["fluxsite"]["pbs"]["ncpus"] | |
except KeyError: | |
ncpus = internal.FLUXSITE_DEFAULT_PBS["ncpus"] | |
self.logger.debug("Running comparison tasks...") | |
if config["fluxsite"]["multiprocess"]: | |
ncpus = config["fluxsite"]["pbs"]["ncpus"] |
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.
Hi @ccarouge, I've committed the fix after running all tests again. Passing.
One thing to note, many of these remaining changes did not trigger failures in the tests. We may need to take a look at how robust our testing is to catch these in future.
…m:CABLE-LSM/benchcab into 103-we-should-be-using-the-logging-module
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.
Finally! Last small changes done:
- clobbered merge conflicts
- removed unused singleton.py
Added changes from yesterday's discussion. Also updated the CLI interface to engage the log level from the verbosity flag.