You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "Lee-W (via GitHub)" <gi...@apache.org> on 2024/09/04 01:04:42 UTC

[PR] ci: auto fix default_deferrable value with LibCST [airflow]

Lee-W opened a new pull request, #41984:
URL: https://github.com/apache/airflow/pull/41984

   <!--
    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at
   
      http://www.apache.org/licenses/LICENSE-2.0
   
    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.
    -->
   
   <!--
   Thank you for contributing! Please make sure that your code changes
   are covered with tests. And in case of new features or big changes
   remember to adjust the documentation.
   
   Feel free to ping committers for the review!
   
   In case of an existing issue, reference it using one of the following:
   
   closes: #ISSUE
   related: #ISSUE
   
   How to write a good git commit message:
   http://chris.beams.io/posts/git-commit/
   -->
   
   
   
   <!-- Please keep an empty line above the dashes. -->
   ---
   **^ Add meaningful description above**
   Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)** for more information.
   In case of fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed.
   In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   In case of backwards incompatible changes please leave a note in a newsfragment file, named `{pr_number}.significant.rst` or `{issue_number}.significant.rst`, in [newsfragments](https://github.com/apache/airflow/tree/main/newsfragments).
   


-- 
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] ci: auto fix default_deferrable value with LibCST [airflow]

Posted by "bugraoz93 (via GitHub)" <gi...@apache.org>.
bugraoz93 commented on PR #41984:
URL: https://github.com/apache/airflow/pull/41984#issuecomment-2335482708

   Hello @Lee-W, I have got an error about the hook introduced in this PR not being able to be installed via `Python 3.8`. I think it's due to `"libcst>=1.4.0"`. 
   I know `Python 3.8` is nearly EOL, so in Airflow 3, the decision was to delete EOL Python versions. Until the Airflow 3 release date, `Python 3.8` will lose support.
   Does this mean we should start developing at least in `Python 3.9`? 
   
   >Which Python version should we support in Airflow 3?
       The consensus was to keep things as-is i.e following the current [Python-support policy](https://github.com/apache/airflow?tab=readme-ov-file#support-for-python-and-kubernetes-versions) where we would remove the support for a Python version when it is EOL.


-- 
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] ci: auto fix default_deferrable value with LibCST [airflow]

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

   it's something I missed. just created a pr for the fix https://github.com/apache/airflow/pull/42083


-- 
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] ci: auto fix default_deferrable value with LibCST [airflow]

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


-- 
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] ci: auto fix default_deferrable value with LibCST [airflow]

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


##########
scripts/ci/pre_commit/check_deferrable_default.py:
##########
@@ -33,62 +37,71 @@
 )
 
 
+class DefaultDeferrableVisitor(ast.NodeVisitor):
+    def __init__(self, *args, **kwargs) -> None:
+        super().__init__(*args, *kwargs)
+        self.error_linenos: list[int] = []
+
+    def visit_FunctionDef(self, node: ast.FunctionDef) -> ast.FunctionDef:
+        if node.name == "__init__":
+            args = node.args
+            arguments = reversed([*args.args, *args.posonlyargs, *args.kwonlyargs])
+            defaults = reversed([*args.defaults, *args.kw_defaults])
+            for argument, default in itertools.zip_longest(arguments, defaults):
+                # argument is not deferrable
+                if argument is None or argument.arg != "deferrable":
+                    continue
+
+                # argument is deferrable, but comes with no default value
+                if default is None:
+                    self.error_linenos.append(argument.lineno)
+                    continue
+
+                # argument is deferrable, but the default value is not valid
+                if not _is_valid_deferrable_default(default):
+                    self.error_linenos.append(default.lineno)
+        return node
+
+
+class DefaultDeferrableTransformer(cst.CSTTransformer):
+    def leave_Param(self, original_node: cst.Param, updated_node: cst.Param) -> cst.Param:
+        if original_node.name.value == "deferrable":
+            expected_default_cst = cst.parse_expression(
+                'conf.getboolean("operators", "default_deferrable", fallback=False)'
+            )
+
+            if updated_node.default and updated_node.default.deep_equals(expected_default_cst):
+                return updated_node
+            return updated_node.with_changes(default=expected_default_cst)
+        return updated_node
+
+
 def _is_valid_deferrable_default(default: ast.AST) -> bool:
     """Check whether default is 'conf.getboolean("operators", "default_deferrable", fallback=False)'"""
-    if not isinstance(default, ast.Call):
-        return False  # Not a function call.
-
-    # Check the function callee is exactly 'conf.getboolean'.
-    call_to_conf_getboolean = (
-        isinstance(default.func, ast.Attribute)
-        and isinstance(default.func.value, ast.Name)
-        and default.func.value.id == "conf"
-        and default.func.attr == "getboolean"
-    )
-    if not call_to_conf_getboolean:
-        return False
-
-    # Check arguments.
-    return (
-        len(default.args) == 2
-        and isinstance(default.args[0], ast.Constant)
-        and default.args[0].value == "operators"
-        and isinstance(default.args[1], ast.Constant)
-        and default.args[1].value == "default_deferrable"
-        and len(default.keywords) == 1
-        and default.keywords[0].arg == "fallback"
-        and isinstance(default.keywords[0].value, ast.Constant)
-        and default.keywords[0].value.value is False
-    )
+    return ast.unparse(default) == "conf.getboolean('operators', 'default_deferrable', fallback=False)"

Review Comment:
   This also needs Python 3.9 to work, it didn't exist before there



-- 
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] ci: auto fix default_deferrable value with LibCST [airflow]

Posted by "bugraoz93 (via GitHub)" <gi...@apache.org>.
bugraoz93 commented on PR #41984:
URL: https://github.com/apache/airflow/pull/41984#issuecomment-2335630388

   Thanks, @Lee-W! 


-- 
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