Skip to content

Commit b0fa37f

Browse files
authored
chore: add ruff checks to ci (#79)
- Ran ruff linter and formatter on the codebase - Adds linter and formatter checks to ci
1 parent 5dd5ef4 commit b0fa37f

33 files changed

+1047
-494
lines changed

.github/workflows/ruff.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Run linter and formatter
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [ main ]
7+
tags: [ 'v*.*.*' ]
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
test:
14+
name: Lint and Format
15+
strategy:
16+
matrix:
17+
os: [ubuntu-latest]
18+
python: ["3.9"]
19+
runs-on: ${{ matrix.os }}
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@v4
23+
with:
24+
submodules: recursive
25+
- name: Install uv with python
26+
uses: astral-sh/setup-uv@v6
27+
with:
28+
python-version: ${{ matrix.python }}
29+
- name: Run ruff linter
30+
run: |
31+
32+
- name: Run ruff formatter
33+
run: |
34+
uvx [email protected] format

examples/adbc_example.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,15 @@
2525
names=["ints", "strs"],
2626
)
2727

28+
2829
def read_adbc_named_table(name: str, conn):
2930
pa_schema = conn.adbc_get_table_schema(name)
30-
substrait_schema = pa_substrait.serialize_schema(pa_schema).to_pysubstrait().base_schema
31+
substrait_schema = (
32+
pa_substrait.serialize_schema(pa_schema).to_pysubstrait().base_schema
33+
)
3134
return read_named_table(name, substrait_schema)
3235

36+
3337
with adbc_driver_duckdb.dbapi.connect(":memory:") as conn:
3438
with conn.cursor() as cur:
3539
cur.adbc_ingest("AnswerToEverything", data)
@@ -38,7 +42,14 @@ def read_adbc_named_table(name: str, conn):
3842
cur.executescript("LOAD substrait;")
3943

4044
table = read_adbc_named_table("AnswerToEverything", conn)
41-
table = filter(table, expression=scalar_function('functions_comparison.yaml', 'gte', column('ints'), literal(3, i64())))
45+
table = filter(
46+
table,
47+
expression=scalar_function(
48+
"functions_comparison.yaml",
49+
"gte",
50+
expressions=[column("ints"), literal(3, i64())],
51+
),
52+
)
4253

4354
cur.execute(table(registry).SerializeToString())
44-
print(cur.fetch_arrow_table())
55+
print(cur.fetch_arrow_table())

examples/builder_example.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,20 @@
66
registry = ExtensionRegistry(load_default_extensions=True)
77

88
ns = named_struct(
9-
names=["id", "is_applicable"],
10-
struct=struct(
11-
types=[
12-
i64(nullable=False),
13-
boolean()
14-
]
15-
)
9+
names=["id", "is_applicable"], struct=struct(types=[i64(nullable=False), boolean()])
1610
)
1711

18-
table = read_named_table('example_table', ns)
19-
table = filter(table, expression=column('is_applicable'))
20-
table = filter(table, expression=scalar_function('functions_comparison.yaml', 'lt', column('id'), literal(100, i64())))
21-
table = project(table, expressions=[column('id')])
12+
table = read_named_table("example_table", ns)
13+
table = filter(table, expression=column("is_applicable"))
14+
table = filter(
15+
table,
16+
expression=scalar_function(
17+
"functions_comparison.yaml",
18+
"lt",
19+
expressions=[column("id"), literal(100, i64())],
20+
),
21+
)
22+
table = project(table, expressions=[column("id")])
2223

2324
print(table(registry))
2425

examples/duckdb_example.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
try:
2020
duckdb.install_extension("substrait")
21-
except:
21+
except duckdb.duckdb.HTTPException:
2222
duckdb.install_extension("substrait", repository="community")
2323
duckdb.load_extension("substrait")
2424

@@ -29,14 +29,27 @@
2929

3030
registry = ExtensionRegistry(load_default_extensions=True)
3131

32+
3233
def read_duckdb_named_table(name: str, conn):
3334
pa_schema = conn.sql(f"SELECT * FROM {name} LIMIT 0").arrow().schema
34-
substrait_schema = pa_substrait.serialize_schema(pa_schema).to_pysubstrait().base_schema
35+
substrait_schema = (
36+
pa_substrait.serialize_schema(pa_schema).to_pysubstrait().base_schema
37+
)
3538
return read_named_table(name, substrait_schema)
3639

40+
3741
table = read_duckdb_named_table("customer", duckdb)
38-
table = filter(table, expression=scalar_function('functions_comparison.yaml', 'equal', column('c_nationkey'), literal(3, i32())))
39-
table = project(table, expressions=[column('c_name'), column('c_address'), column('c_nationkey')])
42+
table = filter(
43+
table,
44+
expression=scalar_function(
45+
"functions_comparison.yaml",
46+
"equal",
47+
expressions=[column("c_nationkey"), literal(3, i32())],
48+
),
49+
)
50+
table = project(
51+
table, expressions=[column("c_name"), column("c_address"), column("c_nationkey")]
52+
)
4053

4154
sql = f"CALL from_substrait_json('{dump_json(table(registry))}')"
4255
print(duckdb.sql(sql))

examples/pyarrow_example.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,18 @@
1111
import substrait
1212
from substrait.builders.plan import project, read_named_table
1313

14-
arrow_schema = pa.schema([
15-
pa.field("x", pa.int32()),
16-
pa.field("y", pa.int32())
17-
])
14+
arrow_schema = pa.schema([pa.field("x", pa.int32()), pa.field("y", pa.int32())])
1815

19-
substrait_schema = pa_substrait.serialize_schema(arrow_schema).to_pysubstrait().base_schema
16+
substrait_schema = (
17+
pa_substrait.serialize_schema(arrow_schema).to_pysubstrait().base_schema
18+
)
2019

2120
substrait_expr = pa_substrait.serialize_expressions(
22-
exprs=[pc.field("x") + pc.field("y")],
23-
names=["total"],
24-
schema=arrow_schema
21+
exprs=[pc.field("x") + pc.field("y")], names=["total"], schema=arrow_schema
2522
)
2623

2724
pysubstrait_expr = substrait.proto.ExtendedExpression.FromString(bytes(substrait_expr))
2825

2926
table = read_named_table("example", substrait_schema)
3027
table = project(table, expressions=[pysubstrait_expr])(None)
31-
print(table)
28+
print(table)

pyproject.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,3 @@ respect-gitignore = true
3030
target-version = "py39"
3131
# never autoformat upstream or generated code
3232
exclude = ["third_party/", "src/substrait/gen"]
33-
# do not autofix the following (will still get flagged in lint)
34-
lint.unfixable = [
35-
"F401", # unused imports
36-
"T201", # print statements
37-
]

0 commit comments

Comments
 (0)