Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.

Commit c409c81

Browse files
authored
Merge pull request #771 from datafold/feature/pre-commit-automation
Add pre-commit automation for faster, safer development
2 parents 119ade5 + d871ffd commit c409c81

File tree

9 files changed

+161
-17
lines changed

9 files changed

+161
-17
lines changed

.github/workflows/formatter.yml

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,16 @@ on:
77

88
jobs:
99
linter_name:
10-
name: runner / black
10+
name: runner / ruff
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v2
14-
- name: Check files using the black formatter
15-
uses: rickstaa/action-black@v1
16-
id: black_formatter
13+
- uses: actions/checkout@v3
14+
- name: Check files using the ruff formatter
15+
uses: chartboost/ruff-action@v1
16+
id: ruff_formatter
1717
with:
18-
black_args: ". -l 120"
19-
- name: Annotate diff changes using reviewdog
20-
if: steps.black_formatter.outputs.is_formatted == 'true'
21-
uses: reviewdog/action-suggester@v1
18+
args: format
19+
- name: Auto commit ruff formatting
20+
uses: stefanzweifel/git-auto-commit-action@v5
2221
with:
23-
tool_name: blackfmt
24-
- name: Fail if there are formatting suggestions
25-
if: steps.black_formatter.outputs.is_formatted == 'true'
26-
run: exit 1
22+
commit_message: 'style fixes by ruff'

.pre-commit-config.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
default_language_version:
2+
python: python3
3+
4+
repos:
5+
# Run the Ruff linter.
6+
- repo: https://github.com/astral-sh/ruff-pre-commit
7+
# Ruff version.
8+
rev: v0.1.2
9+
hooks:
10+
# Run the Ruff formatter.
11+
- id: ruff-format

CONTRIBUTING.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ Once inside, you can install the dependencies.
5454

5555
- Option 2: Run `pip install -e .` to install them, and data-diff, in the global context.
5656

57+
- Run `pre-commit install` to automatically format your code before committing.
58+
5759
At the bare minimum, you need MySQL to run the tests.
5860

5961
You can create a local MySQL instance using `docker-compose up mysql`. The URI for it will be `mysql://mysql:Password1@localhost/mysql`. If you're using a different server, make sure to update `TEST_MYSQL_CONN_STRING` in `tests/common.py`. For your convenience, we recommend creating `tests/local_settings.py`, and to override the value there.

data_diff/databases/redshift.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,7 @@ def select_view_columns(self, path: DbPath) -> str:
126126

127127
return """select * from pg_get_cols('{}.{}')
128128
cols(view_schema name, view_name name, col_name name, col_type varchar, col_num int)
129-
""".format(
130-
schema, table
131-
)
129+
""".format(schema, table)
132130

133131
def query_pg_get_cols(self, path: DbPath) -> Dict[str, tuple]:
134132
rows = self.query(self.select_view_columns(path), list)

data_diff/queries/ast_classes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ def else_(self, then: Expr) -> Self:
337337
@attrs.define(frozen=True, eq=False)
338338
class QB_When:
339339
"Partial case-when, used for query-building"
340+
340341
casewhen: CaseWhen
341342
when: Expr
342343

poetry.lock

Lines changed: 130 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ clickhouse-driver = "*"
6161
vertica-python = "*"
6262
duckdb = "^0.7.0"
6363
dbt-core = "^1.0.0"
64+
ruff = "^0.1.4"
6465
# google-cloud-bigquery = "*"
6566
# databricks-sql-connector = "*"
6667

@@ -80,6 +81,9 @@ clickhouse = ["clickhouse-driver"]
8081
vertica = ["vertica-python"]
8182
duckdb = ["duckdb"]
8283

84+
[tool.poetry.group.dev.dependencies]
85+
pre-commit = "^3.5.0"
86+
8387
[build-system]
8488
requires = ["poetry-core>=1.0.0"]
8589
build-backend = "poetry.core.masonry.api"

ruff.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Allow lines to be as long as 120.
2+
line-length = 120

tests/common.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ def str_to_checksum(str: str):
135135

136136
class DiffTestCase(unittest.TestCase):
137137
"Sets up two tables for diffing"
138+
138139
db_cls = None
139140
src_schema = None
140141
dst_schema = None

0 commit comments

Comments
 (0)