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 git hooks to automatically run autoformat script #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ZakyHermawan
Copy link
Member

Description

Automatically run autopep8 in place, recursively each time you commit based on rules from autoformat_python.sh,
if there are some errors, your commit will get rejected (no commit) and your code will be modified in place,
just run git add and git commit again.
This pre-commit hook will only modify the .py files that you have changed.

Note: To skip commit hooks during a commit, you can use the --no-verify option with git commit.
image

How to use:

  1. Install pre-commit package manager with pip install pre-commit
  2. run pre-commit install to set up the git hook scripts
  3. Make changes
  4. git add
  5. git commit
  6. If your commit fails, simply run steps 4 and 5 again

Note: If you don't follow either step 1 or step 2, then the workflow will be same as usual (no git hooks will be run).
image

Why do we need this ?

One of the problems with GNU Radio codebase is that there is autoformat
script that is needed to run manually to pass format test in git action,
so I think it will be a good idea to add pre-commit git hook to handle the
formatting before commit.

Related Issue

Which blocks/areas does this affect?

Every .py files

Testing Done

Make a commit that violating our code convention in .py files, also make commit to modify non .py file

Change non .py file
image

Change .py file while violating code convention:
Screenshot from 2024-07-14 09-40-14

Checklist

Signed-off-by: ZakyHermawan <[email protected]>
@willcode
Copy link
Member

I'm not going to be excited about anything that automatically changes code on my machine, even if it is useful.

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.

2 participants