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

Commit 33ca675

Browse files
authored
style: fix ruff issues (#2172)
1 parent e5f5e82 commit 33ca675

File tree

8 files changed

+64
-32
lines changed

8 files changed

+64
-32
lines changed

python-sdk/src/astro/databases/base.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def get_merge_initialization_query(parameters: tuple) -> str:
205205
it agnostic to database.
206206
"""
207207
constraints = ",".join(parameters)
208-
sql = "ALTER TABLE {{table}} ADD CONSTRAINT airflow UNIQUE (%s)" % constraints
208+
sql = f"ALTER TABLE {{{{table}}}} ADD CONSTRAINT airflow UNIQUE ({constraints})"
209209
return sql
210210

211211
@staticmethod
@@ -319,7 +319,8 @@ def create_table_using_schema_autodetection(
319319
)
320320

321321
def is_native_autodetect_schema_available( # skipcq: PYL-R0201
322-
self, file: File # skipcq: PYL-W0613
322+
self,
323+
file: File, # skipcq: PYL-W0613
323324
) -> bool:
324325
"""
325326
Check if native auto detection of schema is available.
@@ -801,7 +802,9 @@ def schema_exists(self, schema: str) -> bool:
801802
# ---------------------------------------------------------
802803

803804
def get_sqlalchemy_template_table_identifier_and_parameter(
804-
self, table: BaseTable, jinja_table_identifier: str # skipcq PYL-W0613
805+
self,
806+
table: BaseTable,
807+
jinja_table_identifier: str, # skipcq PYL-W0613
805808
) -> tuple[str, str]:
806809
"""
807810
During the conversion from a Jinja-templated SQL query to a SQLAlchemy query, there is the need to
@@ -853,7 +856,9 @@ def parameterize_variable(self, variable: str):
853856
return ":" + variable
854857

855858
def is_native_load_file_available( # skipcq: PYL-R0201
856-
self, source_file: File, target_table: BaseTable # skipcq: PYL-W0613
859+
self,
860+
source_file: File,
861+
target_table: BaseTable, # skipcq: PYL-W0613
857862
) -> bool:
858863
"""
859864
Check if there is an optimised path for source to destination.

python-sdk/src/astro/databases/duckdb.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ def get_merge_initialization_query(parameters: tuple) -> str:
8181
"""
8282
Handles database-specific logic to handle index for DuckDB.
8383
"""
84-
return "CREATE UNIQUE INDEX merge_index ON {{table}}(%s)" % ",".join(parameters) # skipcq PYL-C0209
84+
joined_parameters = ",".join(parameters)
85+
return f"CREATE UNIQUE INDEX merge_index ON {{{{table}}}}({joined_parameters})"
8586

8687
def merge_table(
8788
self,

python-sdk/src/astro/databases/snowflake.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,8 @@ def drop_stage(self, stage: SnowflakeStage) -> None:
455455
# ---------------------------------------------------------
456456

457457
def is_native_autodetect_schema_available( # skipcq: PYL-R0201
458-
self, file: File # skipcq: PYL-W0613
458+
self,
459+
file: File, # skipcq: PYL-W0613
459460
) -> bool:
460461
"""
461462
Check if native auto detection of schema is available.
@@ -585,7 +586,9 @@ def create_table_using_schema_autodetection(
585586
self.truncate_table(table)
586587

587588
def is_native_load_file_available(
588-
self, source_file: File, target_table: BaseTable # skipcq PYL-W0613, PYL-R0201
589+
self,
590+
source_file: File,
591+
target_table: BaseTable, # skipcq PYL-W0613, PYL-R0201
589592
) -> bool:
590593
"""
591594
Check if there is an optimised path for source to destination.
@@ -654,7 +657,9 @@ def _get_table_columns_count(self, table_name: str) -> int:
654657
try:
655658
table_columns_count = int(
656659
self.hook.run(
657-
sql_statement, parameters={"table_name": table_name}, handler=lambda cur: cur.fetchone()
660+
sql_statement,
661+
parameters={"table_name": table_name},
662+
handler=lambda cur: cur.fetchone(),
658663
)[0]
659664
)
660665
except AttributeError: # pragma: no cover
@@ -1059,7 +1064,7 @@ def get_merge_initialization_query(cls, parameters: tuple) -> str:
10591064
identifier_enclosure = '"'
10601065

10611066
constraints = ",".join([f"{identifier_enclosure}{p}{identifier_enclosure}" for p in parameters])
1062-
sql = "ALTER TABLE {{table}} ADD CONSTRAINT airflow UNIQUE (%s)" % constraints # skipcq PYL-C0209
1067+
sql = f"ALTER TABLE {{{{table}}}} ADD CONSTRAINT airflow UNIQUE ({constraints})"
10631068
return sql
10641069

10651070
def openlineage_dataset_name(self, table: BaseTable) -> str:

python-sdk/src/astro/databases/sqlite.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ def get_merge_initialization_query(parameters: tuple) -> str:
9090
"""
9191
Handles database-specific logic to handle index for Sqlite.
9292
"""
93-
return "CREATE UNIQUE INDEX merge_index ON {{table}}(%s)" % ",".join(parameters) # skipcq PYL-C0209
93+
joined_parameters = ",".join(parameters)
94+
return f"CREATE UNIQUE INDEX merge_index ON {{{{table}}}}({joined_parameters})"
9495

9596
def merge_table(
9697
self,
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from astro.databases.duckdb import DuckdbDatabase
2+
3+
4+
def test_get_merge_initialization_query():
5+
parameters = ("col_1", "col_2")
6+
7+
sql = DuckdbDatabase.get_merge_initialization_query(parameters)
8+
assert sql == "CREATE UNIQUE INDEX merge_index ON {{table}}(col_1,col_2)"

python-sdk/tests/databases/test_snowflake.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,3 +287,9 @@ def test_get_copy_into_with_metadata_sql_statement_no_metadata_columns():
287287
)
288288
with pytest.raises(ValueError, match="Error: Requires metadata columns to be set in load options"):
289289
database._get_copy_into_with_metadata_sql_statement(file_path, table, stage)
290+
291+
292+
def test_get_merge_initialization_query():
293+
parameters = ("col_1", "col_2")
294+
sql = SnowflakeDatabase.get_merge_initialization_query(parameters)
295+
assert sql == "ALTER TABLE {{table}} ADD CONSTRAINT airflow UNIQUE (col_1,col_2)"

python-sdk/tests/databases/test_sqlite.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import pytest
66

77
from astro.constants import Database
8+
from astro.databases.sqlite import SqliteDatabase
89
from astro.files import File
910

1011
DEFAULT_CONN_ID = "sqlite_default"
@@ -31,3 +32,10 @@ def test_export_table_to_file_file_already_exists_raises_exception(
3132
database.export_table_to_file(source_table, File(str(filepath)))
3233
err_msg = exception_info.value.args[0]
3334
assert err_msg.endswith(f"The file {filepath} already exists.")
35+
36+
37+
def test_get_merge_initialization_query():
38+
parameters = ("col_1 text(4)", "col_2 text(15)")
39+
40+
sql = SqliteDatabase.get_merge_initialization_query(parameters)
41+
assert sql == "CREATE UNIQUE INDEX merge_index ON {{table}}(col_1 text(4),col_2 text(15))"

ruff.toml

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,36 @@
11
line-length = 120
22

3+
target-version = "py37"
4+
fix = true
5+
# Exclude a variety of commonly ignored directories.
6+
extend-exclude = ["__pycache__", "docs/source/conf.py"]
7+
8+
[lint]
9+
extend-ignore = ["A002"]
310
# Enable Pyflakes `E` and `F` codes by default.
411
extend-select = [
5-
"W", # pycodestyle warnings
6-
"I", # isort
7-
"C90", # Complexity
8-
# "B", # flake8-bugbear
9-
"C", # flake8-comprehensions
10-
# "ANN", # flake8-comprehensions
11-
"ISC", # flake8-implicit-str-concat
12-
"T10", # flake8-debugger
13-
"A", # flake8-builtins
14-
"UP", # pyupgrade
12+
"W", # pycodestyle warnings
13+
"I", # isort
14+
"C90", # Complexity
15+
# "B", # flake8-bugbear
16+
"C", # flake8-comprehensions
17+
# "ANN", # flake8-comprehensions
18+
"ISC", # flake8-implicit-str-concat
19+
"T10", # flake8-debugger
20+
"A", # flake8-builtins
21+
"UP", # pyupgrade
1522
]
16-
extend-ignore = ["A002"]
1723

18-
# Exclude a variety of commonly ignored directories.
19-
extend-exclude = [
20-
"__pycache__",
21-
"docs/source/conf.py",
22-
]
23-
24-
target-version = "py37"
25-
fix = true
2624

27-
[per-file-ignores]
25+
[lint.per-file-ignores]
2826
"python-sdk/src/astro/sql/__init__.py" = ["F401"]
2927
"python-sdk/src/astro/lineage/__init__.py" = ["F401"]
3028
"python-sdk/src/astro/sql/table.py" = ["F401"]
3129

3230

33-
[mccabe]
31+
[lint.mccabe]
3432
max-complexity = 6
3533

36-
[isort]
34+
[lint.isort]
3735
combine-as-imports = true
3836
known-first-party = ["astro", "tests"]

0 commit comments

Comments
 (0)