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

Auto formatting for Python files #302

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft

Conversation

jfredrickson
Copy link
Contributor

Improve pre-commit Python formatting per #213.

This does a few things so far:

  • If you're using VS Code or a VS Code based editor, it should recommend the Black Formatter extension upon startup
  • Enables format-on-save for Python files using Black
  • Updates the pre-commit hook to run Black (which, if you're using VS Code, shouldn't have any changes left to make)

To get this to work:

  1. Ensure you have Black Formatter installed (hopefully if you're using VS Code, it'll prompt you to do so if you don't already have it; let me know if it doesn't prompt you)
  2. cp pre-commit .husky/pre-commit to make sure Husky has the latest pre-commit configuration

@jfredrickson
Copy link
Contributor Author

Now with auto stashing. The script now does this:

  1. Stashes all unstaged changes
  2. Runs the formatters as usual
  3. Runs git add . to add any changes from the formatters to the current commit
  4. Pops the unstaged changes from the stash

@jfredrickson
Copy link
Contributor Author

Okay, taking a different angle to this due to conflicts caused by stashing. Copied the simplified hook over from PR #310 and this will only format the code if there are no unstaged changes.

@jfredrickson jfredrickson marked this pull request as draft March 5, 2025 18:35
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.

1 participant