Skip to content

Commit ecb8516

Browse files
authored
Add pre-commit with ruff (#140)
1 parent a08b871 commit ecb8516

File tree

22 files changed

+78
-67
lines changed

22 files changed

+78
-67
lines changed

.flake8

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[flake8]
2+
max-line-length = 88
3+
extend-ignore = E203,E501

.github/workflows/base-test.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ jobs:
4242
python-version: ${{ matrix.python-version }}
4343
- name: Install dependencies
4444
run: pip install tox 'coveralls<3'
45-
- name: Lint code
46-
run: tox -e lint
4745
# - name: Login to Docker Hub
4846
# uses: docker/login-action@v3
4947
# with:

.github/workflows/test-before-pr.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,20 @@ on:
55
branches: ["main"]
66

77
jobs:
8+
lint:
9+
runs-on: ubuntu-22.04
10+
name: Linting on Python
11+
steps:
12+
- name: Checkout Code
13+
uses: actions/checkout@v5
14+
- name: Set up Python3
15+
uses: actions/setup-python@v5
16+
with:
17+
python-version: '3.10'
18+
- name: Lint with pre-commit
19+
uses: pre-commit/[email protected]
820
test:
21+
needs: lint
922
uses: ./.github/workflows/base-test.yml
1023
# https://docs.github.com/en/actions/using-workflows/reusing-workflows#passing-inputs-and-secrets-to-a-reusable-workflow
1124
secrets: inherit

.pre-commit-config.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
repos:
2+
3+
- repo: https://github.com/astral-sh/ruff-pre-commit
4+
rev: v0.14.1
5+
hooks:
6+
- id: ruff-check
7+
args: [--fix, --exit-non-zero-on-fix]
8+
- id: ruff-format
9+
10+
- repo: https://github.com/PyCQA/flake8
11+
rev: 7.3.0
12+
hooks:
13+
- id: flake8

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
### 1.5.0
2+
- feat: #140: Adding pre-commit with ruff as linter and code formatter.
23
- fix: #139: Fix to replicas query when using default as cluster name
34
- feat: #133: Fix simultaneous queries error when iteration is interrupted
45
- feat: #130: Add `distributed_migrations` database setting to support distributed migration queries.

CONTRIBUTING.md

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,40 +21,33 @@ How to Contribute Source Code
2121

2222
1. Clone the forked repository and cd into it.
2323

24-
2. Install [tox](https://tox.wiki/).
24+
2. Install [tox](https://tox.wiki/):
2525
```shell
2626
pip install tox
2727
```
2828

29-
3. Start ClickHouse cluster.
29+
3. Install [pre-commit](https://pre-commit.com/):
30+
```shell
31+
pip install pre-commit
32+
pre-commit install --install-hooks
33+
```
34+
35+
4. Start ClickHouse cluster.
3036
Docker and docker compose are required.
3137
```shell
3238
docker compose up -d
3339
```
3440

35-
4. Install dependencies.
41+
5. Install dependencies.
3642
```shell
3743
pip install -e .
3844
```
3945

4046
### Code Style
4147

42-
This project use:
43-
44-
- [isort](https://github.com/PyCQA/isort#readme) to automate import sorting.
45-
- [black](https://black.readthedocs.io/en/stable/) to format code.
46-
- [flake8](https://pypi.org/project/flake8/) to lint code.
47-
48-
If tox is installed, code formatting can be run as:
49-
50-
```shell
51-
tox -e format
52-
```
53-
54-
code linting can be run as:
55-
48+
This project uses Ruff with pre-commit, and to run it manually:
5649
```shell
57-
tox -e lint
50+
pre-commit run -a
5851
```
5952

6053
### Code Conventions

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Django ClickHouse Database Backend
77
[![GitHub licence](https://img.shields.io/github/license/jayvynl/django-clickhouse-backend)](https://github.com/jayvynl/django-clickhouse-backend/blob/main/LICENSE)
88
[![GitHub Action: Test](https://github.com/jayvynl/django-clickhouse-backend/actions/workflows/test-main.yml/badge.svg)](https://github.com/jayvynl/django-clickhouse-backend/actions/workflows/test-main.yml)
99
[![Coverage Status](https://coveralls.io/repos/github/jayvynl/django-clickhouse-backend/badge.svg?branch=main)](https://coveralls.io/github/jayvynl/django-clickhouse-backend?branch=main)
10-
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
10+
[![Code style](https://camo.githubusercontent.com/051a04ae958f4a1a5d6444df4cdc520305eef93d5028e6d4c7cd16efa3136cd4/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f75726c3d68747470733a2f2f7261772e67697468756275736572636f6e74656e742e636f6d2f61737472616c2d73682f727566662f6d61696e2f6173736574732f62616467652f76322e6a736f6e)](https://github.com/astral-sh/ruff-pre-commit)
1111

1212
Django clickhouse backend is a [django database backend](https://docs.djangoproject.com/en/5.1/ref/databases/) for
1313
[clickhouse](https://clickhouse.com/docs/en/home/) database. This project allows using django ORM to interact with

clickhouse_backend/models/engines.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ def __init__(
130130
primary_key=None,
131131
**settings,
132132
):
133-
assert (
134-
order_by is not None or primary_key is not None
135-
), "At least one of order_by or primary_key must be provided"
133+
assert order_by is not None or primary_key is not None, (
134+
"At least one of order_by or primary_key must be provided"
135+
)
136136
self.order_by = order_by
137137
self.primary_key = primary_key
138138
self.partition_by = partition_by

clickhouse_backend/models/fields/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ def _check_choices(self):
279279

280280
invalid_errors = [
281281
checks.Error(
282-
"'choices' must be an iterable containing " "(int, str) tuples.",
282+
"'choices' must be an iterable containing (int, str) tuples.",
283283
obj=self,
284284
id="fields.E005",
285285
)

clickhouse_backend/models/indexes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def __init__(
3535
raise ValueError("Index.fields must be a list or tuple.")
3636
if not expressions and not fields:
3737
raise ValueError(
38-
"At least one field or expression is required to define an " "index."
38+
"At least one field or expression is required to define an index."
3939
)
4040
if expressions and fields:
4141
raise ValueError(

0 commit comments

Comments
 (0)