You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "jason810496 (via GitHub)" <gi...@apache.org> on 2026/05/07 08:14:53 UTC

[PR] Support inline ignore marker for check-sdk-imports hook [airflow]

jason810496 opened a new pull request, #66519:
URL: https://github.com/apache/airflow/pull/66519

   
   - related: #65358
   
   ## Why
   
   There are cases where importing `airflow.sdk` modules in airflow-core is intentionally needed, but the `check-sdk-imports` prek hook has no way to suppress individual violations. Mirrors the `# nocheck: core-imports` support added for `check_core_imports_in_sdk` in #65358.
   
   ## What
   
   - Add `# nocheck: sdk-imports` inline comment marker support to `check_sdk_imports.py`, allowing specific import lines to be excluded from the check.
   - The marker works on both single-line and multi-line `from airflow.sdk import (...)` statements (on the first line, any middle line, or the closing paren line).
   - Add tests for the `check_sdk_imports` hook covering both the existing detection behavior and the new nocheck marker.
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [x] Yes, with help of Claude Opus 4.7 following [the guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
   


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Support inline ignore marker for check-sdk-imports hook [airflow]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #66519:
URL: https://github.com/apache/airflow/pull/66519#issuecomment-4397777339

   ### Backport successfully created: v3-2-test
   
   Note: As of [Merging PRs targeted for Airflow 3.X](https://github.com/apache/airflow/blob/main/dev/README_AIRFLOW3_DEV.md#merging-prs-targeted-for-airflow-3x)
   the committer who merges the PR is responsible for backporting the PRs that are bug fixes (generally speaking) to the maintenance branches.
   
   In matter of doubt please ask in [#release-management](https://apache-airflow.slack.com/archives/C03G9H97MM2) Slack channel.
   
   <table>
           <tr>
           <th>Status</th>
           <th>Branch</th>
           <th>Result</th>
       </tr>
       <tr>
           <td>✅</td>
           <td>v3-2-test</td>
           <td><a href="https://github.com/apache/airflow/pull/66550"><img src="https://img.shields.io/badge/PR-66550-blue" alt="PR Link"></a></td>
       </tr>
   </table>


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Support inline ignore marker for check-sdk-imports hook [airflow]

Posted by "jason810496 (via GitHub)" <gi...@apache.org>.
jason810496 merged PR #66519:
URL: https://github.com/apache/airflow/pull/66519


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Support inline ignore marker for check-sdk-imports hook [airflow]

Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W commented on code in PR #66519:
URL: https://github.com/apache/airflow/pull/66519#discussion_r3200041684


##########
scripts/ci/prek/check_sdk_imports.py:
##########
@@ -31,6 +31,8 @@
 
 from common_prek_utils import console
 
+NOCHECK_MARKER = "# nocheck: sdk-imports"

Review Comment:
   should we unify the style by using `# noqa` like `# noqa: MIG003`



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Support inline ignore marker for check-sdk-imports hook [airflow]

Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Support inline ignore marker for check-sdk-imports hook [airflow]

Posted by "jason810496 (via GitHub)" <gi...@apache.org>.
jason810496 commented on code in PR #66519:
URL: https://github.com/apache/airflow/pull/66519#discussion_r3200047898


##########
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:
   Good idea!



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org