Skip to content

Commit 8e17fb2

Browse files
authored
Enhance Code Quality with Ruff, Black, and Pre-commit (#456)
* add: linter, formatter for github actions * add: CONTRIBUTING.md * add: pre-commit config and pre-commit rule * fix: auto-fix with ruff * fix: E401 Multiple imports on one line * fix: E999 SyntaxError: Unexpected token 'json' * fix: F821 Undefined name `unicode` by removing python2 compatibility * fix: F811 Redefinition of unused `gtid` from line 3 * fix: E721 Do not compare types, use `isinstance()` * fix: E721 Do not compare types, use `isinstance()` * fix: F811 Redefinition of unused `TestMariadbBinlogStreamReader` from line 1012 by rename into TestMariadbBinlogStreamReader2 * fix: import json * fix: fromtimestamp into utcfromtimestamp * fix: apply black formatter * fix: test that doesn't work * fix: remove actions dependencies * fix: E712 * fix: apply black * fix: apply black * fix: remove duplicated if-statement * fix: indent for if-statement
1 parent a097cf0 commit 8e17fb2

31 files changed

+2022
-1173
lines changed

.github/workflows/lint.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Lint
2+
on: [push, pull_request]
3+
4+
jobs:
5+
lint:
6+
runs-on: ubuntu-latest
7+
steps:
8+
- name: Checkout repository
9+
uses: actions/checkout@v3
10+
11+
- name: Set up Python
12+
uses: actions/setup-python@v4
13+
with:
14+
python-version: '3.x' # This will install the latest version of Python 3
15+
16+
- name: Install dependencies
17+
run: |
18+
python -m pip install --upgrade pip
19+
pip install ruff black
20+
21+
- name: Run lint script
22+
run: bash scripts/lint.sh

.pre-commit-config.yaml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.4.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: end-of-file-fixer
7+
- id: check-yaml
8+
- id: check-added-large-files
9+
10+
- repo: https://github.com/astral-sh/ruff-pre-commit
11+
rev: v0.0.286
12+
hooks:
13+
- id: ruff
14+
args: [ --fix, --exit-non-zero-on-fix ]
15+
16+
- repo: https://github.com/psf/black
17+
rev: 23.7.0
18+
hooks:
19+
- id: black

CONTRIBUTING.md

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Contributing to python-mysql-replication
2+
3+
Firstly, thank you for considering to contribute to `python-mysql-replication`. We appreciate your effort, and to ensure that your contributions align with the project's coding standards, we employ the use of `pre-commit` hooks. This guide will walk you through setting them up.
4+
5+
## Setting up pre-commit
6+
7+
1. **Install pre-commit**
8+
9+
Before you can use `pre-commit`, you need to install it. You can do so using `pip`:
10+
11+
```bash
12+
pip install pre-commit
13+
```
14+
15+
2. **Install the pre-commit hooks**
16+
17+
Navigate to the root directory of your cloned `python-mysql-replication` repository and run:
18+
19+
```bash
20+
pre-commit install
21+
```
22+
23+
This will install the `pre-commit` hooks to your local repository.
24+
25+
3. **Make sure to stage your changes**
26+
27+
`pre-commit` will only check the files that are staged in git. So make sure to `git add` any new changes you made before running `pre-commit`.
28+
29+
4. **Run pre-commit manually (Optional)**
30+
31+
Before committing, you can manually run:
32+
33+
```bash
34+
pre-commit run --all-files
35+
```
36+
37+
This will run the hooks on all the files. If there's any issue, the hooks will let you know.
38+
39+
## If you encounter issues
40+
41+
If you run into any problems with the hooks, you can always skip them using:
42+
43+
```bash
44+
git commit -m "Your commit message" --no-verify
45+
```
46+
47+
However, please note that skipping hooks might lead to CI failures if we use these checks in our CI pipeline. It's always recommended to adhere to the checks to ensure a smooth contribution process.
48+
49+
---
50+
51+
That's it! With these steps, you should be well on your way to contributing to `python-mysql-replication`. We look forward to your contributions!

0 commit comments

Comments
 (0)