Purpose: To enforce consistent code style across the team despite different local code formatters being used by team members.
Benefit: Ensures code consistency, especially useful when working with a large team.
Removed .editorconfig:
Reason: The .editorconfig file was not effective and was difficult to set up.
Configured Black as the Code Formatter:
Used Black as the code formatter within the pre-commit hooks to ensure uniform code formatting. Black is a PEP 8 compliant opinionated formatter. https://peps.python.org/pep-0008/
Reformatted All Files:
Reformatted the entire codebase using Black to align with the enforced code style.
Issue: #61
Here's a step-by-step guide on how to set up and use pre-commit, starting from installing the dependencies listed in requirements.txt and including instructions for team members.
Setting Up Pre-commit Hooks
Follow these steps to set up and use pre-commit hooks for your project once you merge this PR
1. Install Dependencies
First, ensure all the dependencies, including pre-commit, are installed. Run the following command in your terminal:
pip install -r requirements.txt
4. Install Pre-commit Hooks
To install the pre-commit hooks defined in the configuration file, run the following.
This step is a must. While doing pip install -r requirements.txt, we are just downloading the package. The following step register the rule for the project
pre-commit install
This will set up the hooks to run automatically on git commit.
5. Stage Your Changes
Before committing, you need to stage the files you want to include in the commit. You can do this using the git add command. For example, to stage all modified files, run:
git add .
2. Commit Your Changes
Once the files are staged, commit your changes using the git commit command. Pre-commit hooks will automatically run at this stage.
git commit -m "Your descriptive commit message"
3. Handle Pre-commit Hook Failures
Since, local formatting might be different than that enforced by PEP8, you might see error message like the one below. The best part is, the files are already reformatted. You don't have to save them again or format them manually. It's already done for you.
The formatting is done. so, you will have to add the changes again by running following. Make sure you run the following again, otherwise, you will see the following error
git add .
4. Retry Committing
After adding the files to staging by running git add . , commit again by running following.
git commit -m "Your descriptive commit message"
5. Push Your Changes
Once the commit is successful, you can push your changes to the remote repository:
git push origin your-branch-name
Change Form
[x] The pull request title includes issue number and description.
[x] The work done is summarised above.
[x] The code is commented and well formatted.
[x] Testing has been performed and documented above.
Other Information
[E.g.: Unresolved bugs / follow-up actions / notes to the reviewer]
Change Summary
Installed Pre-commit Package:
Removed
.editorconfig
:.editorconfig
file was not effective and was difficult to set up.Configured Black as the Code Formatter:
Reformatted All Files:
Issue: #61
Here's a step-by-step guide on how to set up and use pre-commit, starting from installing the dependencies listed in
requirements.txt
and including instructions for team members.Setting Up Pre-commit Hooks
Follow these steps to set up and use pre-commit hooks for your project once you merge this PR
1. Install Dependencies
First, ensure all the dependencies, including
pre-commit
, are installed. Run the following command in your terminal:4. Install Pre-commit Hooks
To install the pre-commit hooks defined in the configuration file, run the following. This step is a
must
. While doingpip install -r requirements.txt
, we are just downloading the package. The following step register the rule for the projectThis will set up the hooks to run automatically on
git commit
.5. Stage Your Changes
Before committing, you need to stage the files you want to include in the commit. You can do this using the
git add
command. For example, to stage all modified files, run:2. Commit Your Changes
Once the files are staged, commit your changes using the
git commit
command. Pre-commit hooks will automatically run at this stage.3. Handle Pre-commit Hook Failures
Since, local formatting might be different than that enforced by PEP8, you might see error message like the one below. The best part is, the files are already reformatted. You don't have to save them again or format them manually. It's already done for you.
The formatting is done. so, you will have to add the changes again by running following. Make sure you run the following again, otherwise, you will see the following error
4. Retry Committing
After adding the files to staging by running
git add .
, commit again by running following.5. Push Your Changes
Once the commit is successful, you can push your changes to the remote repository:
Change Form
Other Information