Re: Migrate code style to Black #307
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Migrate code style to Black.
Note: Black is strictly about formatting, nothing else.
The file includes the necessary dependencies for pre-commit. Please install the dependencies under the root directory using
pip install -r requirements-dev.txtAs hooks are a feature of git, pre-commit hooks have to be manually installed to your local repository by executing:
pre-commit installEvery time you make a commitment, the pre-commit hook will examine all relevant files under the current working directory. If any test defined by pre-commit fails, the commit will be unsuccessful (files in the staged area will not be affected).
As we use Black, pre-commit will automatically format all .py files except those in docs/ if it detect your code style violates Black's and refuse your commit (but things in the staged area will remain intact). Afterward, you have to add the auto-formatted files manually and repeat your last commit. This is the expected behavior to avoid any unnoticed changes, and the reason is explained in this issue.
A workaround to the issue is to execute after the commit fails the pre-commit check:
git add -u && !!(not working on my computer. I saw the solution on stackoverflow)!! means repeating the previous command. For example, if the previous command was git commit -m "some message", then git add -u && !! would be equivalent to git add -u && git commit -m "some message".
Or, you can execute a pre-commit test before committing your changes:
pre-commit run -agit config blame.ignoreRevsFile .git-blame-ignore-revs===================
Get familiar with Black Style using the official Black doc
Test CLI & API (
bash tests/autotest.sh)Test APIs used by main.py.
Check API Document
If any new APIs are added, please check if the description of the APIs is added to API document.
Test quickstart & API (
bash tests/docs/test_changed_document.sh)If any APIs in quickstarts or tutorials are modified, please run this test to check if the current examples can run correctly after the modified APIs are released.