-
Notifications
You must be signed in to change notification settings - Fork 659
Enable black formatter in CI #602
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
Conversation
Disable the pylint warning for the block, as black will reformat this over multiple lines instead of the previous one-liner.
|
Also, I wrote this quick and dirty bash script to dump all the Python files that are currently touched by open PRs. ACTIVE_PRS=(290 539 554 567)
DIFF_FILE="output.txt"
echo "" >| "${DIFF_FILE}"
for PR in "${ACTIVE_PRS[@]}"; do
git fetch origin pull/"${PR}"/head:pr-"${PR}"
git diff --name-only develop...pr-"${PR}" | grep '.py' | tee -a "${DIFF_FILE}"
done
sort "${DIFF_FILE}" -o "${DIFF_FILE}" -uI looked at those PRs, and the changes don't seem too bad in context of this giant format patch. Otherwise, if we want to, we can simply exclude these files until those PRs are merged. |
Codecov Report
@@ Coverage Diff @@
## develop #602 +/- ##
===========================================
- Coverage 63.79% 63.68% -0.11%
===========================================
Files 63 63
Lines 5532 5541 +9
===========================================
Hits 3529 3529
- Misses 2003 2012 +9 |
Codecov Report
@@ Coverage Diff @@
## develop #602 +/- ##
===========================================
- Coverage 63.79% 63.66% -0.13%
===========================================
Files 63 63
Lines 5532 5543 +11
===========================================
Hits 3529 3529
- Misses 2003 2014 +11 |
| 'slcan': ('can.interfaces.slcan', 'slcanBus'), | ||
| 'canalystii': ('can.interfaces.canalystii', 'CANalystIIBus'), | ||
| 'systec': ('can.interfaces.systec', 'UcanBus') | ||
| "kvaser": ("can.interfaces.kvaser", "KvaserBus"), |
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.
Do we really want this new formatting here? Or is there no option to exclude a block?
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.
black provides a way to exclude sections from formatting, but IMO that kind of goes against the point of having a formatter.
If someone feels strongly about keeping it untouched by the formatter, I can add
# fmt: off
# ...
# fmt: on
can/interfaces/canalystii.py
Outdated
|
|
||
| for channel in self.channels: | ||
| if CANalystII.VCI_InitCAN(VCI_USBCAN2, self.device, channel, byref(self.init_config)) == STATUS_ERR: | ||
| if ( |
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.
Maybe:
| if ( | |
| status = CANalystII.VCI_InitCAN(VCI_USBCAN2, self.device, channel, byref(self.init_config)) | |
| if status == == STATUS_ERR: |
can/interfaces/canalystii.py
Outdated
| timeout = -1 if timeout is None else int(timeout * 1000) | ||
|
|
||
| if CANalystII.VCI_Receive(VCI_USBCAN2, self.device, self.channels[0], byref(raw_message), 1, timeout) <= STATUS_ERR: | ||
| if ( |
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.
split into two statements?
felixdivo
left a comment
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.
Well, I don't really like the style, but that is kind of subjective so I'm fine with it if you want it since it at least is consistent.
Maybe it would be nice to exclude some code "blocks", like in can/interfaces/__init__.py or large parts of can/interfaces/ixxat/constants.py. I don't know whether that's possible or desired.
|
I didn't go through all of the changes, since it was just tom much. |
|
We could also add the badge: https://github.com/python/black#show-your-style |
|
I did really like the previous semantics of quotes: Double quotes for user facing text, single quotes for everything else. But I guess that's a matter of taste as well. |
.travis.yml
Outdated
| - travis_retry pip install -r requirements-lint.txt | ||
| script: | ||
| - black --diff . | ||
| - black --check . |
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 could image black --check --verbose . being enough, since black itself uses it
Clean up formatting of the CANalystII interface after running Black formatter.
Switch to using:
black --check --verbose .
Providing the diff isn't too valuable when the formatting is
automatically handled by the formatter.
Here's the second part that enables black formatter checks on the project.
The black formatter returns
0if nothing would change, and1if files would be reformatted, which allows the CI job to fail.black --check .In order to provide some more verbose error reporting, we also run the following to provide the diff and show the modifications (although this isn't strictly necessary).
black --diff .I've split the commits for easier review so that the final commit is purely the results of running
black .