amoghrajesh commented on code in PR #66519:
URL: https://github.com/apache/airflow/pull/66519#discussion_r3200013330
##########
scripts/ci/prek/check_sdk_imports.py:
##########
@@ -41,18 +43,31 @@ def check_file_for_sdk_imports(file_path: Path) ->
list[tuple[int, str]]:
except (OSError, UnicodeDecodeError, SyntaxError):
return []
+ source_lines = source.splitlines()
mismatches = []
for node in ast.walk(tree):
if isinstance(node, ast.ImportFrom):
if node.module and ("airflow.sdk" in node.module):
+ if _has_nocheck_marker(source_lines, node):
+ continue
import_names = ", ".join(alias.name for alias in node.names)
statement = f"from {node.module} import {import_names}"
mismatches.append((node.lineno, statement))
return mismatches
+def _has_nocheck_marker(source_lines: list[str], node: ast.Import |
ast.ImportFrom) -> bool:
Review Comment:
nit: `ast.Import` in the union is dead here, in this hook only walks
`ast.ImportFrom` nodes
##########
scripts/ci/prek/check_sdk_imports.py:
##########
@@ -41,18 +43,31 @@ def check_file_for_sdk_imports(file_path: Path) ->
list[tuple[int, str]]:
except (OSError, UnicodeDecodeError, SyntaxError):
return []
+ source_lines = source.splitlines()
mismatches = []
for node in ast.walk(tree):
if isinstance(node, ast.ImportFrom):
if node.module and ("airflow.sdk" in node.module):
+ if _has_nocheck_marker(source_lines, node):
+ continue
import_names = ", ".join(alias.name for alias in node.names)
statement = f"from {node.module} import {import_names}"
mismatches.append((node.lineno, statement))
return mismatches
+def _has_nocheck_marker(source_lines: list[str], node: ast.Import |
ast.ImportFrom) -> bool:
Review Comment:
We use a similar util in`check_core_imports_in_sdk.py`, maybe extract it
into `common_prek_utils`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]