phi-friday opened a new pull request, #41832:
URL: https://github.com/apache/airflow/pull/41832
<!--
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/
-->
Like `setup` and `teardown`, `skip_if` and `run_if` should also be removed.
### sample dag code
```python
from __future__ import annotations
from pendulum import datetime
from airflow.decorators import dag, task
@dag(start_date=datetime(2024, 1, 1), schedule=None, catchup=False)
def venv_skip_if() -> None:
@task.skip_if(lambda context: False)
@task.virtualenv()
def echo() -> None:
print("hello world")
echo()
venv_skip_if()
```
#### before in venv
```log
1b4bbddb0c17
*** Found local files:
*** *
/root/airflow/logs/dag_id=venv_skip_if/run_id=manual__2024-08-28T12:29:04.469903+00:00/task_id=echo/attempt=1.log
[2024-08-28, 12:29:05 UTC] {local_task_job_runner.py:123} ▶ Pre task
execution logs
[2024-08-28, 12:29:05 UTC] {process_utils.py:186} INFO - Executing cmd:
/usr/local/bin/python -m virtualenv /tmp/venv5qst192w --system-site-packages
--python=python
[2024-08-28, 12:29:05 UTC] {process_utils.py:190} INFO - Output:
[2024-08-28, 12:29:06 UTC] {process_utils.py:194} INFO - created virtual
environment CPython3.8.19.final.0-64 in 276ms
[2024-08-28, 12:29:06 UTC] {process_utils.py:194} INFO - creator
CPython3Posix(dest=/tmp/venv5qst192w, clear=False, no_vcs_ignore=False,
global=True)
[2024-08-28, 12:29:06 UTC] {process_utils.py:194} INFO - seeder
FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle,
via=copy, app_data_dir=/root/.local/share/virtualenv)
[2024-08-28, 12:29:06 UTC] {process_utils.py:194} INFO - added seed
packages: pip==24.1, setuptools==70.1.0, wheel==0.43.0
[2024-08-28, 12:29:06 UTC] {process_utils.py:194} INFO - activators
BashActivator,CShellActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator
[2024-08-28, 12:29:06 UTC] {process_utils.py:186} INFO - Executing cmd:
/tmp/venv5qst192w/bin/pip install -r /tmp/venv5qst192w/requirements.txt
[2024-08-28, 12:29:06 UTC] {process_utils.py:190} INFO - Output:
[2024-08-28, 12:29:10 UTC] {process_utils.py:194} INFO -
[2024-08-28, 12:29:10 UTC] {process_utils.py:194} INFO - [notice] A new
release of pip is available: 24.1 -> 24.2
[2024-08-28, 12:29:10 UTC] {process_utils.py:194} INFO - [notice] To update,
run: python -m pip install --upgrade pip
[2024-08-28, 12:29:10 UTC] {process_utils.py:186} INFO - Executing cmd:
/tmp/venv5qst192w/bin/python /tmp/venv-callwp2r9u9t/script.py
/tmp/venv-callwp2r9u9t/script.in /tmp/venv-callwp2r9u9t/script.out
/tmp/venv-callwp2r9u9t/string_args.txt /tmp/venv-callwp2r9u9t/termination.log
/tmp/venv-callwp2r9u9t/***_context.json
[2024-08-28, 12:29:10 UTC] {process_utils.py:190} INFO - Output:
[2024-08-28, 12:29:13 UTC] {process_utils.py:194} INFO - Traceback (most
recent call last):
[2024-08-28, 12:29:13 UTC] {process_utils.py:194} INFO - File
"/tmp/venv-callwp2r9u9t/script.py", line 18, in <module>
[2024-08-28, 12:29:13 UTC] {process_utils.py:194} INFO -
@task.skip_if(lambda context: False)
[2024-08-28, 12:29:13 UTC] {process_utils.py:194} INFO - NameError: name
'task' is not defined
[2024-08-28, 12:29:13 UTC] {taskinstance.py:3167} ERROR - Task failed with
exception
Traceback (most recent call last):
File "/opt/airflow/airflow/models/taskinstance.py", line 753, in
_execute_task
result = _execute_callable(context=context, **execute_callable_kwargs)
File "/opt/airflow/airflow/models/taskinstance.py", line 719, in
_execute_callable
return ExecutionCallableRunner(
File "/opt/airflow/airflow/utils/operator_helpers.py", line 252, in run
return self.func(*args, **kwargs)
File "/opt/airflow/airflow/models/baseoperator.py", line 402, in wrapper
return func(self, *args, **kwargs)
File "/opt/airflow/airflow/decorators/base.py", line 266, in execute
return_value = super().execute(context)
File "/opt/airflow/airflow/models/baseoperator.py", line 402, in wrapper
return func(self, *args, **kwargs)
File "/opt/airflow/airflow/operators/python.py", line 509, in execute
return super().execute(context=serializable_context)
File "/opt/airflow/airflow/models/baseoperator.py", line 402, in wrapper
return func(self, *args, **kwargs)
File "/opt/airflow/airflow/operators/python.py", line 240, in execute
return_value = self.execute_callable()
File "/opt/airflow/airflow/operators/python.py", line 900, in
execute_callable
result = self._execute_python_callable_in_subprocess(python_path)
File "/opt/airflow/airflow/operators/python.py", line 593, in
_execute_python_callable_in_subprocess
execute_in_subprocess(
File "/opt/airflow/airflow/utils/process_utils.py", line 175, in
execute_in_subprocess
execute_in_subprocess_with_kwargs(cmd, cwd=cwd, env=env)
File "/opt/airflow/airflow/utils/process_utils.py", line 198, in
execute_in_subprocess_with_kwargs
raise subprocess.CalledProcessError(exit_code, cmd)
subprocess.CalledProcessError: Command '['/tmp/venv5qst192w/bin/python',
'/tmp/venv-callwp2r9u9t/script.py', '/tmp/venv-callwp2r9u9t/script.in',
'/tmp/venv-callwp2r9u9t/script.out', '/tmp/venv-callwp2r9u9t/string_args.txt',
'/tmp/venv-callwp2r9u9t/termination.log',
'/tmp/venv-callwp2r9u9t/airflow_context.json']' returned non-zero exit status 1.
[2024-08-28, 12:29:13 UTC] {taskinstance.py:1211} INFO - Marking task as
FAILED. dag_id=venv_skip_if, task_id=echo,
run_id=manual__2024-08-28T12:29:04.469903+00:00,
execution_date=20240828T122904, start_date=20240828T122905,
end_date=20240828T122913
[2024-08-28, 12:29:13 UTC] {taskinstance.py:337} ▶ Post task execution logs
```
#### after in venv
```log
5dae42dc6e21
*** Found local files:
*** *
/root/airflow/logs/dag_id=venv_skip_if/run_id=manual__2024-08-28T12:39:47.502535+00:00/task_id=echo/attempt=1.log
[2024-08-28, 12:39:48 UTC] {local_task_job_runner.py:123} ▶ Pre task
execution logs
[2024-08-28, 12:39:48 UTC] {process_utils.py:186} INFO - Executing cmd:
/usr/local/bin/python -m virtualenv /tmp/venvt7te04zf --system-site-packages
--python=python
[2024-08-28, 12:39:48 UTC] {process_utils.py:190} INFO - Output:
[2024-08-28, 12:39:48 UTC] {process_utils.py:194} INFO - created virtual
environment CPython3.8.19.final.0-64 in 266ms
[2024-08-28, 12:39:48 UTC] {process_utils.py:194} INFO - creator
CPython3Posix(dest=/tmp/venvt7te04zf, clear=False, no_vcs_ignore=False,
global=True)
[2024-08-28, 12:39:48 UTC] {process_utils.py:194} INFO - seeder
FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle,
via=copy, app_data_dir=/root/.local/share/virtualenv)
[2024-08-28, 12:39:48 UTC] {process_utils.py:194} INFO - added seed
packages: pip==24.1, setuptools==70.1.0, wheel==0.43.0
[2024-08-28, 12:39:48 UTC] {process_utils.py:194} INFO - activators
BashActivator,CShellActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator
[2024-08-28, 12:39:48 UTC] {process_utils.py:186} INFO - Executing cmd:
/tmp/venvt7te04zf/bin/pip install -r /tmp/venvt7te04zf/requirements.txt
[2024-08-28, 12:39:48 UTC] {process_utils.py:190} INFO - Output:
[2024-08-28, 12:39:52 UTC] {process_utils.py:194} INFO -
[2024-08-28, 12:39:52 UTC] {process_utils.py:194} INFO - [notice] A new
release of pip is available: 24.1 -> 24.2
[2024-08-28, 12:39:52 UTC] {process_utils.py:194} INFO - [notice] To update,
run: python -m pip install --upgrade pip
[2024-08-28, 12:39:52 UTC] {process_utils.py:186} INFO - Executing cmd:
/tmp/venvt7te04zf/bin/python /tmp/venv-call55vo1yul/script.py
/tmp/venv-call55vo1yul/script.in /tmp/venv-call55vo1yul/script.out
/tmp/venv-call55vo1yul/string_args.txt /tmp/venv-call55vo1yul/termination.log
/tmp/venv-call55vo1yul/***_context.json
[2024-08-28, 12:39:52 UTC] {process_utils.py:190} INFO - Output:
[2024-08-28, 12:39:56 UTC] {process_utils.py:194} INFO - hello world
[2024-08-28, 12:39:56 UTC] {python.py:242} INFO - Done. Returned value was:
None
[2024-08-28, 12:39:56 UTC] {taskinstance.py:337} ▶ Post task execution logs
```
<!-- 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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]