Skip to content

Commit 04c2b54

Browse files
committed
Add pre-commit with ruff
1 parent 03b9adb commit 04c2b54

File tree

23 files changed

+109
-83
lines changed

23 files changed

+109
-83
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/pre-commit.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Pre-commit
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
8+
jobs:
9+
run-pre-commit:
10+
runs-on: ubuntu-22.04
11+
name: Linting on Python
12+
steps:
13+
- name: Checkout Code
14+
uses: actions/checkout@v5
15+
- name: Set up Python3
16+
uses: actions/setup-python@v5
17+
with:
18+
python-version: '3.10'
19+
- name: Lint with pre-commit
20+
uses: pre-commit/[email protected]

.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/charliermarsh/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

CONTRIBUTING.md

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,40 +21,32 @@ 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+
```
33+
34+
4. Start ClickHouse cluster.
3035
Docker and docker compose are required.
3136
```shell
3237
docker compose up -d
3338
```
3439

35-
4. Install dependencies.
40+
5. Install dependencies.
3641
```shell
3742
pip install -e .
3843
```
3944

4045
### Code Style
4146

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-
47+
This project uses Ruff with pre-commit, and to run it manually:
5648
```shell
57-
tox -e lint
49+
pre-commit run -a
5850
```
5951

6052
### 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/fields/tuple.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,18 +166,22 @@ def description(self):
166166

167167
def db_type(self, connection):
168168
base_type = ", ".join(
169-
"%s %s" % (field[0], field[1].db_type(connection))
170-
if self.is_named_tuple
171-
else field.db_type(connection)
169+
(
170+
"%s %s" % (field[0], field[1].db_type(connection))
171+
if self.is_named_tuple
172+
else field.db_type(connection)
173+
)
172174
for field in self.base_fields
173175
)
174176
return "Tuple(%s)" % base_type
175177

176178
def cast_db_type(self, connection):
177179
base_type = ", ".join(
178-
"%s %s" % (field[0], field[1].cast_db_type(connection))
179-
if self.is_named_tuple
180-
else field.cast_db_type(connection)
180+
(
181+
"%s %s" % (field[0], field[1].cast_db_type(connection))
182+
if self.is_named_tuple
183+
else field.cast_db_type(connection)
184+
)
181185
for field in self.base_fields
182186
)
183187
return "Tuple(%s)" % base_type

clickhouse_backend/models/functions/tuples.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,20 @@ def __init__(self, *expressions, output_field=None, **extra):
2929
if len(expressions) == 2:
3030
expressions = (
3131
expressions[0],
32-
Value(expressions[1] + 1)
33-
if isinstance(expressions[1], int)
34-
else expressions[1],
32+
(
33+
Value(expressions[1] + 1)
34+
if isinstance(expressions[1], int)
35+
else expressions[1]
36+
),
3537
)
3638
elif len(expressions) == 3:
3739
expressions = (
3840
expressions[0],
39-
Value(expressions[1] + 1)
40-
if isinstance(expressions[1], int)
41-
else expressions[1],
41+
(
42+
Value(expressions[1] + 1)
43+
if isinstance(expressions[1], int)
44+
else expressions[1]
45+
),
4246
expressions[2],
4347
)
4448
else:

0 commit comments

Comments
 (0)