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

Commit

Permalink
Merge pull request #771 from datafold/feature/pre-commit-automation
Browse files Browse the repository at this point in the history
Add pre-commit automation for faster, safer development
  • Loading branch information
dlawin authored Nov 13, 2023
2 parents 119ade5 + d871ffd commit c409c81
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 17 deletions.
22 changes: 9 additions & 13 deletions .github/workflows/formatter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,16 @@ on:

jobs:
linter_name:
name: runner / black
name: runner / ruff
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Check files using the black formatter
uses: rickstaa/action-black@v1
id: black_formatter
- uses: actions/checkout@v3
- name: Check files using the ruff formatter
uses: chartboost/ruff-action@v1
id: ruff_formatter
with:
black_args: ". -l 120"
- name: Annotate diff changes using reviewdog
if: steps.black_formatter.outputs.is_formatted == 'true'
uses: reviewdog/action-suggester@v1
args: format
- name: Auto commit ruff formatting
uses: stefanzweifel/git-auto-commit-action@v5
with:
tool_name: blackfmt
- name: Fail if there are formatting suggestions
if: steps.black_formatter.outputs.is_formatted == 'true'
run: exit 1
commit_message: 'style fixes by ruff'
11 changes: 11 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
default_language_version:
python: python3

repos:
# Run the Ruff linter.
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.1.2
hooks:
# Run the Ruff formatter.
- id: ruff-format
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ Once inside, you can install the dependencies.

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

- Run `pre-commit install` to automatically format your code before committing.

At the bare minimum, you need MySQL to run the tests.

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.
Expand Down
4 changes: 1 addition & 3 deletions data_diff/databases/redshift.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,7 @@ def select_view_columns(self, path: DbPath) -> str:

return """select * from pg_get_cols('{}.{}')
cols(view_schema name, view_name name, col_name name, col_type varchar, col_num int)
""".format(
schema, table
)
""".format(schema, table)

def query_pg_get_cols(self, path: DbPath) -> Dict[str, tuple]:
rows = self.query(self.select_view_columns(path), list)
Expand Down
1 change: 1 addition & 0 deletions data_diff/queries/ast_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ def else_(self, then: Expr) -> Self:
@attrs.define(frozen=True, eq=False)
class QB_When:
"Partial case-when, used for query-building"

casewhen: CaseWhen
when: Expr

Expand Down
131 changes: 130 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ clickhouse-driver = "*"
vertica-python = "*"
duckdb = "^0.7.0"
dbt-core = "^1.0.0"
ruff = "^0.1.4"
# google-cloud-bigquery = "*"
# databricks-sql-connector = "*"

Expand All @@ -80,6 +81,9 @@ clickhouse = ["clickhouse-driver"]
vertica = ["vertica-python"]
duckdb = ["duckdb"]

[tool.poetry.group.dev.dependencies]
pre-commit = "^3.5.0"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
Expand Down
2 changes: 2 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Allow lines to be as long as 120.
line-length = 120
1 change: 1 addition & 0 deletions tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ def str_to_checksum(str: str):

class DiffTestCase(unittest.TestCase):
"Sets up two tables for diffing"

db_cls = None
src_schema = None
dst_schema = None
Expand Down

0 comments on commit c409c81

Please sign in to comment.