Conversation
woutdenolf
left a comment
There was a problem hiding this comment.
Nice! It seems that getopt is used everywhere. Perhaps in another PR we could use it everywhere? Or this PR, as you want.
| opts = [] | ||
| if args.logging: | ||
| opts.append(('--logging', args.logging)) | ||
| if args.debug.lower() not in ['0', 'false']: | ||
| opts.append(('--debug', args.debug)) | ||
|
|
||
| from PyMca5.PyMcaCore.LoggingLevel import getLoggingLevel | ||
| logging.basicConfig(level=getLoggingLevel(opts)) |
There was a problem hiding this comment.
Do we need getLoggingLevel here?
There was a problem hiding this comment.
Essentially we have one log level
log_level = "debug" if args.debug else args.loggingSomething like
import argparse
import logging
parser = argparse.ArgumentParser(description="Example script with logging.")
parser.add_argument(
"--logging",
default="warning",
choices=["debug", "info", "warning", "error", "critical"],
help="Set logging level (default: warning)"
)
parser.add_argument(
"--debug",
action="store_true",
help="Force logging level to DEBUG"
)
args = parser.parse_args()
if args.debug:
log_level = logging.DEBUG
else:
log_level = getattr(logging, args.logging.upper(), logging.WARNING)
logging.basicConfig(level=log_level)There was a problem hiding this comment.
Maybe this logic can be implemented in a re-usable way.
There was a problem hiding this comment.
Do we need backward compatibility? if yes then to forbid numerical values will be an issue.
If not this is a good looking approach.
Sry i am a bit confused with "use it". You mean substitute Yea I can search and change it everywhere if it is better, should not be a big problem. |
Yes |
|
May I also suggest to use from argparse import ArgumentDefaultsHelpFormatter
parser = ArgumentParser(
..., formatter_class=ArgumentDefaultsHelpFormatter
)This shows the default values in --help. Again you may want to implement common logic in |
Closes #1141
By switching to
argparse.