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

Add pre-commit hooks for flake8 #465

Merged
merged 3 commits into from
Mar 2, 2021

Conversation

jonasdn
Copy link
Contributor

@jonasdn jonasdn commented Jan 15, 2021

Using the pre-commit framework we can have automatic flake8 checks upon commit. The prerequisite is that the developer has run:

  $ pre-commit install

To install the hooks found in .pre-commit-config.yaml. This could be automated through setup.py later if wanted. This commit adds a pre-commit hook that runs flake8 on the proposed change.

An example session:

$ git diff src/
diff --git a/src/cfclient/ui/dialogs/about.py
b/src/cfclient/ui/dialogs/about.py
index 904b590..ffa5e75 100644
--- a/src/cfclient/ui/dialogs/about.py
+++ b/src/cfclient/ui/dialogs/about.py
@@ -172,8 +172,7 @@ class AboutDialog(QtWidgets.QWidget, about_widget_class):
         self._input_readers_text = ""
         # readers = self._helper.inputDeviceReader.getAvailableDevices()
         for reader in cfclient.utils.input.inputreaders.initialized_readers:
-            self._input_readers_text += INPUT_READER_FORMAT.format(
-                reader.name, len(reader.devices()))
+            self._input_readers_text += INPUT_READER_FORMAT.format(reader.name, len(reader.devices()))
         if len(self._input_readers_text) == 0:
             self._input_readers_text = "None<br>"
 
$ git add src/cfclient/ui/dialogs/about.py
$ git commit
[WARNING] Unstaged files detected.
[INFO] Stashing unstaged files to
/home/jonas/.cache/pre-commit/patch1610697747.
flake8...................................................................Failed
- hook id: flake8
- exit code: 1

src/cfclient/ui/dialogs/about.py:175:80: E501 line too long (102 > 79
characters)

[INFO] Restored changes from
/home/jonas/.cache/pre-commit/patch1610697747.

@jonasdn jonasdn force-pushed the jonasdn/pre-commit-flake8 branch from 0b53e93 to 7a73bc5 Compare January 15, 2021 11:49
Using the pre-commit framework we can have automatic flake8 checks upon
commit. The pre-requsite is that the developer has run:

  $ pre-commit install

To install the hooks found in .pre-commit-config.yaml. This could be
automated through setup.py later if wanted.

This commit adds a pre-commit hook that runs flake8 on the proposed
change.

An example session:

$ git diff src/
diff --git a/src/cfclient/ui/dialogs/about.py
b/src/cfclient/ui/dialogs/about.py
index 904b590..ffa5e75 100644
--- a/src/cfclient/ui/dialogs/about.py
+++ b/src/cfclient/ui/dialogs/about.py
@@ -172,8 +172,7 @@ class AboutDialog(QtWidgets.QWidget,
about_widget_class):
         self._input_readers_text = ""
         # readers =
self._helper.inputDeviceReader.getAvailableDevices()
         for reader in
cfclient.utils.input.inputreaders.initialized_readers:
-            self._input_readers_text += INPUT_READER_FORMAT.format(
-                reader.name, len(reader.devices()))
+            self._input_readers_text +=
	     INPUT_READER_FORMAT.format(reader.name,
len(reader.devices()))
         if len(self._input_readers_text) == 0:
             self._input_readers_text = "None<br>"

$ git add src/cfclient/ui/dialogs/about.py
$ git commit
[WARNING] Unstaged files detected.
[INFO] Stashing unstaged files to
/home/jonas/.cache/pre-commit/patch1610697747.
flake8...................................................................Failed
- hook id: flake8
- exit code: 1

src/cfclient/ui/dialogs/about.py:175:80: E501 line too long (102 > 79
characters)

[INFO] Restored changes from
/home/jonas/.cache/pre-commit/patch1610697747.
@jonasdn jonasdn force-pushed the jonasdn/pre-commit-flake8 branch from 7a73bc5 to baf7f0e Compare March 2, 2021 09:40
jonasdn added 2 commits March 2, 2021 10:43
The library uses pre-commit hooks and a verify script to do the flak8
linting. Let's to the same here.
@jonasdn jonasdn force-pushed the jonasdn/pre-commit-flake8 branch from baf7f0e to ac4ca47 Compare March 2, 2021 09:44
@whoenig
Copy link
Contributor

whoenig commented Mar 2, 2021

Looks good to me and is a very handy feature to have!

@krichardsson krichardsson merged commit 7672b1e into bitcraze:master Mar 2, 2021
@krichardsson krichardsson added this to the next-release milestone Mar 2, 2021
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.

3 participants