To maintain uniform pycode style and easier linting for CI, this PR aims at cleaning up the existing codebase with support from local and remote pycode linting (using GitHub Actions).
The newly modified workflow is similar to previous Action however it provides an option to ignore few PEP8 warnings like line-length and whitespaces.
The idea is that warnings like mentioned above should be taken care off locally before committing code using pre-commit git hooks configured to run flake8 and black based on the project's config.
GitHub Action for lint should be mainly to catch more serious warnings or errors like Syntax & Name errors:
E901,E999,F821,F822,F823 are the "showstopper" flake8 issues that can halt the runtime with a SyntaxError, NameError, etc. These 5 are different from most other flake8 issues which are merely "style violations" -- useful for readability but they do not effect runtime safety.
Instructions
The following instructions should help in setting up pre-commit hooks locally and mentions few steps to ensure if the code being committed has style or runtime warnings.
To Install Commit hooks: Follow the instructions mentioned in this link. The pre-commit config file is already configured in the ai-engine repo, so it will just use everything from it.
Once installed, everytime a git commit op is performed, the code being committed is checked against black and flake8 formatter. If the warnings need to be ignored for some reason, then use git commit -n
Install this package: https://github.com/nektos/act. It allows us to run the github action locally to replicate and verify what warnings would be thrown upon performing push or pull_request.
Next action
Owners of various subprojects/services can follow the step 3 from above instructions as an immediate step and check what warnings persist for their services or subprojects.
Make changes to address them and use this **branch** to commit and push the changes.
This way we can use this PR to address all the refactoring and CI changes for the existing codebase and merge it to develop. Later by following the steps for local setup, we can ensure that we will all uniformly follow the same guide before even pushing changes.
Comment and modify/remove the procedures as needed.
Changes
pre-commit
git hooks configured to run flake8 and black based on the project's config.Instructions
The following instructions should help in setting up
pre-commit
hooks locally and mentions few steps to ensure if the code being committed has style or runtime warnings.git commit
op is performed, the code being committed is checked against black and flake8 formatter. If the warnings need to be ignored for some reason, then usegit commit -n
push
orpull_request
.Next action
**branch**
to commit and push the changes.This way we can use this PR to address all the refactoring and CI changes for the existing codebase and merge it to develop. Later by following the steps for local setup, we can ensure that we will all uniformly follow the same guide before even pushing changes.
Comment and modify/remove the procedures as needed.