ashb commented on a change in pull request #15330:
URL: https://github.com/apache/airflow/pull/15330#discussion_r690246906
##########
File path: docs/apache-airflow/docker_decorator.py
##########
@@ -0,0 +1,460 @@
+# Licensed to the Apache Software Foundation (ASF) under one
Review comment:
I don't think you meant to have this file here.
##########
File path: airflow/providers_manager.py
##########
@@ -278,6 +309,51 @@ def _get_attr(obj: Any, attr_name: str):
return None
return getattr(obj, attr_name)
+ def _add_taskflow_decorator(
+ self, decorator_name, decorator_class_name: str, provider_package: str
+ ) -> None:
+ if provider_package.startswith("apache-airflow"):
+ provider_path = provider_package[len("apache-") :].replace("-",
".")
+ if not decorator_class_name.startswith(provider_path):
+ log.warning(
+ "Sanity check failed when importing '%s' from '%s'
package. It should start with '%s'",
+ decorator_class_name,
+ provider_package,
+ provider_path,
+ )
+ return
+ if decorator_name in self._taskflow_decorator_dict:
+ log.warning(
+ "The hook_class '%s' has been already registered.",
+ decorator_class_name,
+ )
+ return
+ try:
+ module, class_name = decorator_class_name.rsplit('.', maxsplit=1)
+ decorator_class = getattr(importlib.import_module(module),
class_name)
+ self._taskflow_decorator_dict[decorator_name] = decorator_class
Review comment:
This causes _all_ decorators to be imported up front, which was
something I wanted us to avoid -- i.e. I'd like
`airflow.providers.docker.decorators.docker.docker_decorator` to only be
imported on the first access (per process) of `@task.docker`.
##########
File path: docs/apache-airflow/tutorial_taskflow_api.rst
##########
@@ -180,16 +180,155 @@ and even a different python version to run your function.
This option should allow for far greater flexibility for users who wish to
keep their workflows more simple
and pythonic.
+Using the Taskflow API with Docker or Virtual Environments
+----------------------------------------------------------
+
+As of Airflow <Airflow version>, you will have the ability to use the Taskflow
API with either a
Review comment:
```suggestion
As of Airflow 2.2, you will have the ability to use the Taskflow API with
either a
```
##########
File path: docs/apache-airflow/tutorial_taskflow_api.rst
##########
@@ -180,16 +180,155 @@ and even a different python version to run your function.
This option should allow for far greater flexibility for users who wish to
keep their workflows more simple
and pythonic.
+Using the Taskflow API with Docker or Virtual Environments
Review comment:
```suggestion
Using the Taskflow API with Docker or Virtual Environments
```
##########
File path: docs/apache-airflow/tutorial_taskflow_api.rst
##########
@@ -180,16 +180,155 @@ and even a different python version to run your function.
This option should allow for far greater flexibility for users who wish to
keep their workflows more simple
and pythonic.
+Using the Taskflow API with Docker or Virtual Environments
+----------------------------------------------------------
+
+As of Airflow <Airflow version>, you will have the ability to use the Taskflow
API with either a
+docker container or python virtual environment. This added functionality will
allow a much more
+comprehensive range of use-cases for the Taskflow API, as you will not be
limited to the
+packages and system libraries of the Airflow worker.
+
+To use a docker image with the Taskflow API, change the decorator to
``@task.docker``
+and add any needed arguments to correctly run the task. Please note that the
docker
+image must have a python library and take in a bash command as the ``command``
argument.
+
+Below is an example of using the ``@task.docker`` decorator to run a python
task.
+
+.. exampleinclude::
/../../airflow/example_dags/tutorial_taskflow_api_etl_docker_virtualenv.py
+ :language: python
+ :dedent: 4
+ :start-after: [START transform_docker]
+ :end-before: [END transform_docker]
+
+If you don't want to run your image on a docker environment, and instead want
to create a separate virtual
Review comment:
```suggestion
If you don't want to run your image on a Docker environment, and instead
want to create a separate virtual
```
##########
File path: docs/apache-airflow/tutorial_taskflow_api.rst
##########
@@ -180,16 +180,155 @@ and even a different python version to run your function.
This option should allow for far greater flexibility for users who wish to
keep their workflows more simple
and pythonic.
+Using the Taskflow API with Docker or Virtual Environments
+----------------------------------------------------------
+
+As of Airflow <Airflow version>, you will have the ability to use the Taskflow
API with either a
+docker container or python virtual environment. This added functionality will
allow a much more
Review comment:
```suggestion
Docker container or Python virtual environment. This added functionality
will allow a much more
```
##########
File path: docs/apache-airflow/tutorial_taskflow_api.rst
##########
@@ -180,16 +180,155 @@ and even a different python version to run your function.
This option should allow for far greater flexibility for users who wish to
keep their workflows more simple
and pythonic.
+Using the Taskflow API with Docker or Virtual Environments
+----------------------------------------------------------
+
+As of Airflow <Airflow version>, you will have the ability to use the Taskflow
API with either a
+docker container or python virtual environment. This added functionality will
allow a much more
+comprehensive range of use-cases for the Taskflow API, as you will not be
limited to the
+packages and system libraries of the Airflow worker.
+
+To use a docker image with the Taskflow API, change the decorator to
``@task.docker``
+and add any needed arguments to correctly run the task. Please note that the
docker
+image must have a python library and take in a bash command as the ``command``
argument.
+
+Below is an example of using the ``@task.docker`` decorator to run a python
task.
+
+.. exampleinclude::
/../../airflow/example_dags/tutorial_taskflow_api_etl_docker_virtualenv.py
+ :language: python
+ :dedent: 4
+ :start-after: [START transform_docker]
+ :end-before: [END transform_docker]
+
+If you don't want to run your image on a docker environment, and instead want
to create a separate virtual
+environment on the same machine, you can use the ``@task.virtualenv``
decorator instead. The ``@task.virtualenv``
+decorator will allow you to create a new virtualenv with custom libraries and
even a different
+python version to run your function.
+
+.. exampleinclude::
/../../airflow/example_dags/tutorial_taskflow_api_etl_docker_virtualenv.py
+ :language: python
+ :dedent: 4
+ :start-after: [START extract_virtualenv]
+ :end-before: [END extract_virtualenv]
+
+These two options should allow for far greater flexibility for users who wish
to keep their workflows more simple
+and pythonic.
Review comment:
Please add some info here about limitations you might need to place on
input or output? (Size limits or output types?)
##########
File path: docs/apache-airflow/tutorial_taskflow_api.rst
##########
@@ -180,16 +180,155 @@ and even a different python version to run your function.
This option should allow for far greater flexibility for users who wish to
keep their workflows more simple
and pythonic.
+Using the Taskflow API with Docker or Virtual Environments
+----------------------------------------------------------
+
+As of Airflow <Airflow version>, you will have the ability to use the Taskflow
API with either a
+docker container or python virtual environment. This added functionality will
allow a much more
+comprehensive range of use-cases for the Taskflow API, as you will not be
limited to the
+packages and system libraries of the Airflow worker.
+
+To use a docker image with the Taskflow API, change the decorator to
``@task.docker``
+and add any needed arguments to correctly run the task. Please note that the
docker
+image must have a python library and take in a bash command as the ``command``
argument.
Review comment:
```suggestion
image must have a working Python installed and take in a bash command as the
``command`` argument.
```
##########
File path: docs/apache-airflow/tutorial_taskflow_api.rst
##########
@@ -180,16 +180,155 @@ and even a different python version to run your function.
This option should allow for far greater flexibility for users who wish to
keep their workflows more simple
and pythonic.
+Using the Taskflow API with Docker or Virtual Environments
+----------------------------------------------------------
+
+As of Airflow <Airflow version>, you will have the ability to use the Taskflow
API with either a
+docker container or python virtual environment. This added functionality will
allow a much more
+comprehensive range of use-cases for the Taskflow API, as you will not be
limited to the
+packages and system libraries of the Airflow worker.
+
+To use a docker image with the Taskflow API, change the decorator to
``@task.docker``
+and add any needed arguments to correctly run the task. Please note that the
docker
+image must have a python library and take in a bash command as the ``command``
argument.
+
+Below is an example of using the ``@task.docker`` decorator to run a python
task.
+
+.. exampleinclude::
/../../airflow/example_dags/tutorial_taskflow_api_etl_docker_virtualenv.py
+ :language: python
+ :dedent: 4
+ :start-after: [START transform_docker]
+ :end-before: [END transform_docker]
+
+If you don't want to run your image on a docker environment, and instead want
to create a separate virtual
+environment on the same machine, you can use the ``@task.virtualenv``
decorator instead. The ``@task.virtualenv``
+decorator will allow you to create a new virtualenv with custom libraries and
even a different
+python version to run your function.
Review comment:
```suggestion
Python version to run your function.
```
##########
File path: docs/apache-airflow/tutorial_taskflow_api.rst
##########
@@ -180,16 +180,155 @@ and even a different python version to run your function.
This option should allow for far greater flexibility for users who wish to
keep their workflows more simple
and pythonic.
+Using the Taskflow API with Docker or Virtual Environments
+----------------------------------------------------------
+
+As of Airflow <Airflow version>, you will have the ability to use the Taskflow
API with either a
+docker container or python virtual environment. This added functionality will
allow a much more
+comprehensive range of use-cases for the Taskflow API, as you will not be
limited to the
+packages and system libraries of the Airflow worker.
+
+To use a docker image with the Taskflow API, change the decorator to
``@task.docker``
+and add any needed arguments to correctly run the task. Please note that the
docker
+image must have a python library and take in a bash command as the ``command``
argument.
+
+Below is an example of using the ``@task.docker`` decorator to run a python
task.
+
+.. exampleinclude::
/../../airflow/example_dags/tutorial_taskflow_api_etl_docker_virtualenv.py
+ :language: python
+ :dedent: 4
+ :start-after: [START transform_docker]
+ :end-before: [END transform_docker]
+
+If you don't want to run your image on a docker environment, and instead want
to create a separate virtual
+environment on the same machine, you can use the ``@task.virtualenv``
decorator instead. The ``@task.virtualenv``
+decorator will allow you to create a new virtualenv with custom libraries and
even a different
+python version to run your function.
+
+.. exampleinclude::
/../../airflow/example_dags/tutorial_taskflow_api_etl_docker_virtualenv.py
+ :language: python
+ :dedent: 4
+ :start-after: [START extract_virtualenv]
+ :end-before: [END extract_virtualenv]
+
+These two options should allow for far greater flexibility for users who wish
to keep their workflows more simple
+and pythonic.
+
+Creating Custom TaskFlow Decorators
Review comment:
This section should be in a separate doc in howto I hink
--
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]