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

Use black as the python code formatter. #159

Merged
merged 3 commits into from
Sep 4, 2024
Merged

Conversation

shaoyijia
Copy link
Collaborator

@shaoyijia shaoyijia commented Sep 1, 2024

  1. Set up black code formatter for this repo to ensure code quality. Update README.md and CONTRIBUTING.md accordingly.
  2. Reformat knowledge_storm/ using black.

Copy link
Collaborator

@Yucheng-Jiang Yucheng-Jiang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking about following workflow:

  • Require each developer to install pre-commit hook to enforce running the code formatter automatically upon every commit. Documentation: https://pre-commit.com.
  • Add main branch protection by running "check style" script, to enforce all incoming code is properly formatted.

Rationale for using combination of these two method:

  1. Developers do not need to manually run code formatter every time
  2. When developers properly configure pre-commit hook, everything will be automatic; when they haven't configure pre-commit hook, the branch protection will reject merge action.
  3. There is option to setup CI/CD workflow to auto run code formatter, but it will create code formatting commit upon every push, which I think it's not neat? But not a big concern.

@shaoyijia
Copy link
Collaborator Author

but it will create code formatting commit upon every push

Yes, I also think this is not neat. Previously, I also found an unofficial action that can also reformat the code based on the identified format issue. But I think the change will not be transparent enough to developer and they may fail to test the reformatted code (reformatting the code shall be safe, but just in case).

Require each developer to install pre-commit hook

I can see the benefit, but given this repo mainly hosts a python package, will this "overkill"? Also, I am not sure if everyone is familiar with this.

@shaoyijia
Copy link
Collaborator Author

More thoughts on this @Yucheng-Jiang ?

@Yucheng-Jiang
Copy link
Collaborator

For pre-hook, on our end we just need to add .pre-commit-config.yaml. For the developers, they only need to do

pip install pre-commit
pre-commit install

Upon commit, it will run code formatter automatically.

@shaoyijia
Copy link
Collaborator Author

ok, I will look into this. Thanks

@Yucheng-Jiang Yucheng-Jiang merged commit f78a073 into main Sep 4, 2024
1 check passed
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.

Add a code formatter for this project to make contribution easier
2 participants