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

   <!--
    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/
   -->
   
   ## Why?
   Since the move of operators / hooks to standard provider, we should ideally 
also be moving the decorators to the standard provider or where they truly 
belong. This will permit those being out of core and allow for a more flexible 
release and bug fix cadence.
   
   What have been moved so far
   
   1. bash
   2. branch_external_python
   3. branch_python
   4. branch_virtualenv
   5. external_python
   6. python
   7. python_virtualenv
   
   
   What i am not so sure if it needs moving to standard:
   
   1. condition
   2. sensor
   3. setup_teardown
   4. short_circuit
   5. task_group
   
   
   ## Points to note
   
   1. I have still imported the `python_task` inside 
`airflow-core/src/airflow/decorators/__init__.py` to be able to continue 
allowing it to be the said default, do comment if you know of a better way :)
   2. The __init__.pyi file has also been updated
   
   ## Testing:
   Created a massive dag with all these decorators in it
   
   ```
   import sys
   import tempfile
   
   from airflow.decorators import dag, task
   from airflow.providers.standard.operators.empty import EmptyOperator
   
   
   @dag()
   def all_decorators():
       # python
       @task
       def python():
           return "Hello!"
   
       python()
   
       # bash
       @task.bash
       def bash() -> str:
           return "echo https://airflow.apache.org/";
   
       bash()
   
       # external-python
       @task.external_python(python=sys.executable)
       def external_python():
           print("doing something in external Python")
   
       external_python()
   
       empty_task_1 = EmptyOperator(task_id="empty_task_1")
       empty_task_2 = EmptyOperator(task_id="empty_task_2")
   
       # branch
       @task.branch()
       def branch_task(**kwargs) -> str:
           """
           Determine which empty_task should be run based on if the logical 
date minute is even or odd.
   
           :param dict kwargs: Context
           :return: Id of the task to run
           """
           return "empty_task_2"
       cond = branch_task()
       cond >> [empty_task_1, empty_task_2]
   
       venv_a = EmptyOperator(task_id="venv_a")
       venv_b = EmptyOperator(task_id="venv_b")
       venv_c = EmptyOperator(task_id="venv_c")
       venv_d = EmptyOperator(task_id="venv_d")
   
       # branch virtual env
       @task.branch_virtualenv(requirements=["numpy~=1.26.0"], 
venv_cache_path=tempfile.gettempdir())
       def branching_virtualenv(choices) -> str:
           import random
   
           import numpy as np
   
           print(f"Some numpy stuff: {np.arange(6)}")
           return f"venv_{random.choice(choices)}"
   
       options = ["a", "b", "c", "d"]
       branching_virtualenv(choices=options)
   
       # external_python
       @task.external_python(python=sys.executable)
       def external_python():
           print("doing something in external Python")
   
       external_python()
   
       @task.virtualenv(
           requirements=["numpy~=1.26.0"], venv_cache_path=tempfile.gettempdir()
       )
       def virtualenv():
           import numpy as np
   
           print(f"Some numpy stuff: {np.arange(6)}")
   
       virtualenv()
   
   all_decorators()
   
   ```
   
   Works as expected:
   <img width="798" alt="image" 
src="https://github.com/user-attachments/assets/ed6e5eda-4a9e-461c-a031-3d74eaa0133b";
 />
   
   
   <!-- 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 
[airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to