Skip to content

Commit 9729cf9

Browse files
authored
Merge pull request #170 from Dev-iL/2605/prek
Replace `pre-commit` with `prek`
2 parents 3a23ff3 + 6c8638c commit 9729cf9

16 files changed

Lines changed: 100 additions & 93 deletions

.github/workflows/prek.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: Prek checks
2+
on: [push, pull_request]
3+
4+
jobs:
5+
prek:
6+
runs-on: ubuntu-latest
7+
steps:
8+
- uses: actions/checkout@v6
9+
- uses: j178/prek-action@v2

.pre-commit-config.yaml

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,25 @@ ci:
33

44
repos:
55
- repo: https://github.com/pre-commit/pre-commit-hooks
6-
rev: v5.0.0
6+
rev: v6.0.0
77
hooks:
88
- id: trailing-whitespace
99
- repo: https://github.com/pre-commit/mirrors-mypy
10-
rev: v1.5.1
10+
rev: v2.1.0
1111
hooks:
1212
- id: mypy
1313
name: python mypy
1414
always_run: true
1515
pass_filenames: false
1616
args: ["python"]
1717
- repo: https://github.com/astral-sh/ruff-pre-commit
18-
rev: v0.8.1
18+
rev: v0.15.13
1919
hooks:
20-
- id: ruff
21-
name: ruff
22-
pass_filenames: false
23-
always_run: true
24-
args: ["python", "--fix"]
20+
# Run the linter.
21+
- id: ruff-check
22+
args: [ --fix ]
23+
# Run the formatter.
2524
- id: ruff-format
26-
name: ruff
27-
pass_filenames: false
28-
always_run: true
29-
args: ["python"]
3025
- repo: local
3126
hooks:
3227
- id: fmt

docs/contribute.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ One of the best ways is follow [maturin offical documentation](https://www.matur
2222
```bash
2323
> python3 -m venv .venv
2424
> source .venv/bin/activate
25-
> pip install -U pip maturin pre-commit pytest pytest-anyio pydantic pgpq
25+
> pip install -U pip maturin prek pytest pytest-anyio pydantic pgpq
2626
```
2727

2828
Then you need to build `PSQLPy` project.
@@ -33,12 +33,12 @@ maturin develop
3333
After this step project is built and installed in your python environment you created in previous step.
3434

3535
## Linting and type checking
36-
We have pre-commit configured with all our settings. We highly recommend you to install it as a git hook using pre-commit install command.
36+
We have prek configured with all our settings. We highly recommend you to install it as a git hook using prek install command.
3737

3838
But even without installation, you can run all lints manually:
3939

4040
```bash
41-
pre-commit run -a
41+
prek run -a
4242
```
4343

4444
## Testing
Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,34 @@
11
# See https://pre-commit.com for more information
22
# See https://pre-commit.com/hooks.html for more hooks
3+
orphan: true
34
repos:
45
- repo: https://github.com/pre-commit/pre-commit-hooks
5-
rev: v2.4.0
6+
rev: v6.0.0
67
hooks:
78
- id: check-ast
89
- id: trailing-whitespace
910
- id: check-toml
1011
- id: end-of-file-fixer
1112

1213
- repo: https://github.com/asottile/add-trailing-comma
13-
rev: v2.1.0
14+
rev: v4.0.0
1415
hooks:
1516
- id: add-trailing-comma
1617

17-
- repo: local
18+
- repo: https://github.com/pre-commit/mirrors-mypy
19+
rev: v2.1.0
1820
hooks:
19-
- id: ruff
20-
name: Check with ruff
21-
entry: poetry run ruff check --force-exclude
22-
language: system
23-
types: [python]
24-
2521
- id: mypy
26-
name: Validate types with MyPy
27-
entry: poetry run mypy
28-
language: system
29-
types: [python]
22+
name: python mypy
23+
always_run: true
24+
pass_filenames: false
25+
args: ["psqlpy_stress"]
26+
27+
- repo: https://github.com/astral-sh/ruff-pre-commit
28+
rev: v0.15.13
29+
hooks:
30+
# Run the linter.
31+
- id: ruff-check
32+
args: [ --fix ]
33+
# Run the formatter.
34+
- id: ruff-format

psqlpy-stress/psqlpy_stress/migrations/env.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11
# noqa: INP001
2+
"""Alembic migration environment.
3+
4+
To enable autogenerate support, point ``target_metadata`` at your models::
5+
6+
from myapp import mymodel
7+
target_metadata = mymodel.Base.metadata
8+
9+
Additional values from alembic.ini can be read via ``config.get_main_option``::
10+
11+
my_important_option = config.get_main_option("my_important_option")
12+
"""
13+
214
from logging.config import fileConfig
315

416
from alembic import context
@@ -17,20 +29,11 @@
1729
if config.config_file_name is not None:
1830
fileConfig(config.config_file_name)
1931

20-
# add your model's MetaData object here
21-
# for 'autogenerate' support
22-
# from myapp import mymodel
23-
# target_metadata = mymodel.Base.metadata
2432
target_metadata = Base.metadata
2533

2634
database_url = settings.database_url
2735
config.set_main_option("sqlalchemy.url", database_url)
2836

29-
# other values from the config, defined by the needs of env.py,
30-
# can be acquired:
31-
# my_important_option = config.get_main_option("my_important_option")
32-
# ... etc.
33-
3437

3538
def run_migrations_offline() -> None:
3639
"""Run migrations in 'offline' mode.

psqlpy-stress/psqlpy_stress/migrations/versions/06d989926550_basic_user_table.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# ruff: noqa: INP001
12
"""basic user table
23
34
Revision ID: 06d989926550
@@ -7,17 +8,16 @@
78
"""
89

910
from collections.abc import Sequence
10-
from typing import Union
1111

1212
import sqlalchemy as sa
1313
from alembic import op
1414

1515

1616
# revision identifiers, used by Alembic.
1717
revision: str = "06d989926550"
18-
down_revision: Union[str, None] = None
19-
branch_labels: Union[str, Sequence[str], None] = None
20-
depends_on: Union[str, Sequence[str], None] = None
18+
down_revision: str | None = None
19+
branch_labels: str | Sequence[str] | None = None
20+
depends_on: str | Sequence[str] | None = None
2121

2222

2323
def upgrade() -> None:

psqlpy-stress/psqlpy_stress/migrations/versions/d162c084f522_big_af_table.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# ruff: noqa: INP001
12
"""big af table
23
34
Revision ID: d162c084f522
@@ -7,7 +8,6 @@
78
"""
89

910
from collections.abc import Sequence
10-
from typing import Union
1111

1212
import sqlalchemy as sa
1313
from alembic import op
@@ -16,9 +16,9 @@
1616

1717
# revision identifiers, used by Alembic.
1818
revision: str = "d162c084f522"
19-
down_revision: Union[str, None] = "06d989926550"
20-
branch_labels: Union[str, Sequence[str], None] = None
21-
depends_on: Union[str, Sequence[str], None] = None
19+
down_revision: str | None = "06d989926550"
20+
branch_labels: str | Sequence[str] | None = None
21+
depends_on: str | Sequence[str] | None = None
2222

2323

2424
def upgrade() -> None:

psqlpy-stress/psqlpy_stress/mocker.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ async def fill_users() -> None:
2525
)
2626

2727

28-
def generate_random_array() -> list[str]:
29-
return [random.randint(50, 500) for _ in range(random.randint(50, 500))]
28+
def generate_random_array() -> list[int]:
29+
return [random.randint(50, 500) for _ in range(random.randint(50, 500))] # noqa: S311
3030

3131

3232
def generate_random_dict() -> dict[str, str]:
33-
return {str(uuid.uuid4()): str(uuid.uuid4()) for _ in range(random.randint(50, 500))}
33+
return {str(uuid.uuid4()): str(uuid.uuid4()) for _ in range(random.randint(50, 500))} # noqa: S311
3434

3535

3636
async def fill_big_table() -> None:
@@ -39,10 +39,12 @@ async def fill_big_table() -> None:
3939
connection = await pool.connection()
4040
for _ in range(big_table_amount):
4141
await connection.execute(
42-
"INSERT INTO big_table (string_field, integer_field, json_field, array_field) VALUES($1, $2, $3, $4)",
42+
"INSERT INTO big_table"
43+
" (string_field, integer_field, json_field, array_field)"
44+
" VALUES($1, $2, $3, $4)",
4345
parameters=[
4446
str(uuid.uuid4()),
45-
random.randint(1, 99999999),
47+
random.randint(1, 99999999), # noqa: S311
4648
generate_random_dict(),
4749
generate_random_array(),
4850
],

psqlpy-stress/psqlpy_stress/models/piccolo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
from piccolo.table import Table
33

44

5-
class User(Table, tablename="users"):
5+
class User(Table, tablename="users"): # type: ignore[call-arg]
66
user_id = Serial(primary_key=True)
77
username = Varchar(null=False)
88

99

10-
class SomeBigTable(Table, tablename="big_table"):
10+
class SomeBigTable(Table, tablename="big_table"): # type: ignore[call-arg]
1111
big_table_id = Integer(primary_key=True)
1212
string_field = Varchar(null=False)
1313
integer_field = Integer(null=False)

psqlpy-stress/psqlpy_stress/models/sqlalchemy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
Base = declarative_base()
77

88

9-
class User(Base):
9+
class User(Base): # type: ignore[misc, valid-type]
1010
__tablename__ = "users"
1111

1212
user_id = Column(Integer, primary_key=True, autoincrement=True)
1313
username = Column(String, unique=True, nullable=False)
1414

1515

16-
class SomeBigTable(Base):
16+
class SomeBigTable(Base): # type: ignore[misc, valid-type]
1717
__tablename__ = "big_table"
1818
big_table_id = Column(Integer, primary_key=True, autoincrement=True)
1919
string_field = Column(String, unique=False, nullable=False)

0 commit comments

Comments
 (0)