-
Notifications
You must be signed in to change notification settings - Fork 633
Enhance can.logger
to consider the append
option
#1327
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
Enhance can.logger
to consider the append
option
#1327
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #1327 +/- ##
========================================
Coverage 65.96% 65.97%
========================================
Files 86 86
Lines 8953 8955 +2
========================================
+ Hits 5906 5908 +2
Misses 3047 3047 |
Interestingly it looks like Python's argparser.py isn't well suited for a The following line is where the issue occurs:
The reason for the issue can be explained below:
The command line arguments are passed in as strings, and when evaluating |
This solution is only required until Python>=3.9.
can/logger.py
Outdated
# argparser.py in Python 3.7.11 does not properly consider boolean arguments passed | ||
# in from the command line. If a boolean is passed in, the variable must be converted | ||
# to an integer 0 (False) or 1 (True). Once the project goes to a minimum of | ||
# Python 3.9, the BooleanOptionalAction, this will no longer be required (Please do | ||
# not use this as a reason to advocate a minimum Python version of 3.9). | ||
boolean_args = ['-a', '--append'] | ||
args = sys.argv[1:] | ||
for i, bool_arg in enumerate(boolean_args): | ||
for j, arg in enumerate(args): | ||
if bool_arg == arg: | ||
# Make sure the length of args is long enough to check the action | ||
if len(args) >= j+1: | ||
action = args[j+1] | ||
else: | ||
break | ||
# Consider the action, and update the results to accurately embody request | ||
if action == '0' or action == 'False': | ||
results.append_mode = False | ||
elif action == '1' or action == 'True': | ||
results.append_mode = True | ||
else: | ||
pass |
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 added a manual argparse
to search for boolean_args
and correct the value of results.append_mode
.
NOTE: Only required until Python>=3.9
NOTE: Please do not use this as a reason to advocate Python>=3.9.
@hardbyte @zariiii9003 This accomplishes what was described in #1326 and is ready for review. |
Could you fix the linters? |
@zariiii9003 The
|
I guess you are using a different black version. Run |
@zariiii9003 Done. I'm passing 24/25 checks. |
@zariiii9003 Do you want for me to add in tests to try to resolve the https://github.com/hardbyte/python-can/pull/1327/checks?check_run_id=6775694757 failure? |
can/logger.py
Outdated
@@ -201,12 +219,42 @@ def main() -> None: | |||
print(f"Connected to {bus.__class__.__name__}: {bus.channel_info}") | |||
print(f"Can Logger (Started on {datetime.now()})") | |||
|
|||
# argparser.py in Python 3.7.11 does not properly consider boolean |
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.
You don't need any of this. Look at how the --fd
argument is handled. It is also a boolean.
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 agree. I have modified my changes. This simplifies things. Thank you.
@zariiii9003 I committed your recommendations. Next time you do that I'll make sure to accept them from this UI rather than manually change them. |
The goal here appears to be to give access to the boolean
append
option ofPrinter
.python-can/can/io/printer.py
Lines 16 to 40 in 0d7f65f
closes #1326