This is an automated email from the ASF dual-hosted git repository.
eladkal pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new f70c10748b Refactor: Consolidate import textwrap in core (#34113)
f70c10748b is described below
commit f70c10748b23d6f06eeb520b8854a87345cb9765
Author: Miroslav Šedivý <[email protected]>
AuthorDate: Mon Sep 11 07:18:38 2023 +0000
Refactor: Consolidate import textwrap in core (#34113)
---
airflow/decorators/base.py | 4 ++--
airflow/example_dags/example_passing_params_via_test_command.py | 4 ++--
airflow/example_dags/tutorial.py | 6 +++---
airflow/example_dags/tutorial_dag.py | 8 ++++----
airflow/operators/python.py | 4 ++--
scripts/ci/pre_commit/pre_commit_insert_extras.py | 4 ++--
scripts/in_container/run_migration_reference.py | 4 ++--
setup.py | 4 ++--
tests/dag_processing/test_job_runner.py | 4 ++--
tests/dags/test_default_impersonation.py | 4 ++--
tests/dags/test_impersonation.py | 4 ++--
tests/dags/test_no_impersonation.py | 4 ++--
12 files changed, 27 insertions(+), 27 deletions(-)
diff --git a/airflow/decorators/base.py b/airflow/decorators/base.py
index 57362e7331..939b65b876 100644
--- a/airflow/decorators/base.py
+++ b/airflow/decorators/base.py
@@ -18,9 +18,9 @@ from __future__ import annotations
import inspect
import itertools
+import textwrap
import warnings
from functools import cached_property
-from textwrap import dedent
from typing import (
TYPE_CHECKING,
Any,
@@ -293,7 +293,7 @@ class DecoratedOperator(BaseOperator):
def get_python_source(self):
raw_source = inspect.getsource(self.python_callable)
- res = dedent(raw_source)
+ res = textwrap.dedent(raw_source)
res = remove_task_decorator(res, self.custom_operator_name)
return res
diff --git a/airflow/example_dags/example_passing_params_via_test_command.py
b/airflow/example_dags/example_passing_params_via_test_command.py
index 055c8639f9..ba867629cb 100644
--- a/airflow/example_dags/example_passing_params_via_test_command.py
+++ b/airflow/example_dags/example_passing_params_via_test_command.py
@@ -20,7 +20,7 @@ from __future__ import annotations
import datetime
import os
-from textwrap import dedent
+import textwrap
import pendulum
@@ -67,7 +67,7 @@ with DAG(
) as dag:
run_this = my_py_command(params={"miff": "agg"})
- my_command = dedent(
+ my_command = textwrap.dedent(
"""
echo "'foo' was passed in via Airflow CLI Test command with value
'$FOO'"
echo "'miff' was passed in via BashOperator with value '$MIFF'"
diff --git a/airflow/example_dags/tutorial.py b/airflow/example_dags/tutorial.py
index 87e1d104ef..a7fd8f069c 100644
--- a/airflow/example_dags/tutorial.py
+++ b/airflow/example_dags/tutorial.py
@@ -24,8 +24,8 @@ from __future__ import annotations
# [START tutorial]
# [START import_module]
+import textwrap
from datetime import datetime, timedelta
-from textwrap import dedent
# The DAG object; we'll need this to instantiate a DAG
from airflow import DAG
@@ -87,7 +87,7 @@ with DAG(
# [END basic_task]
# [START documentation]
- t1.doc_md = dedent(
+ t1.doc_md = textwrap.dedent(
"""\
#### Task Documentation
You can document your task using the attributes `doc_md` (markdown),
@@ -105,7 +105,7 @@ with DAG(
# [END documentation]
# [START jinja_template]
- templated_command = dedent(
+ templated_command = textwrap.dedent(
"""
{% for i in range(5) %}
echo "{{ ds }}"
diff --git a/airflow/example_dags/tutorial_dag.py
b/airflow/example_dags/tutorial_dag.py
index 07b193865d..6ea9d629df 100644
--- a/airflow/example_dags/tutorial_dag.py
+++ b/airflow/example_dags/tutorial_dag.py
@@ -24,7 +24,7 @@ from __future__ import annotations
# [START tutorial]
# [START import_module]
import json
-from textwrap import dedent
+import textwrap
import pendulum
@@ -94,7 +94,7 @@ with DAG(
task_id="extract",
python_callable=extract,
)
- extract_task.doc_md = dedent(
+ extract_task.doc_md = textwrap.dedent(
"""\
#### Extract task
A simple Extract task to get data ready for the rest of the data pipeline.
@@ -107,7 +107,7 @@ with DAG(
task_id="transform",
python_callable=transform,
)
- transform_task.doc_md = dedent(
+ transform_task.doc_md = textwrap.dedent(
"""\
#### Transform task
A simple Transform task which takes in the collection of order data from
xcom
@@ -120,7 +120,7 @@ with DAG(
task_id="load",
python_callable=load,
)
- load_task.doc_md = dedent(
+ load_task.doc_md = textwrap.dedent(
"""\
#### Load task
A simple Load task which takes in the result of the Transform task, by
reading it
diff --git a/airflow/operators/python.py b/airflow/operators/python.py
index c756454040..4382884178 100644
--- a/airflow/operators/python.py
+++ b/airflow/operators/python.py
@@ -25,13 +25,13 @@ import pickle
import shutil
import subprocess
import sys
+import textwrap
import types
import warnings
from abc import ABCMeta, abstractmethod
from collections.abc import Container
from pathlib import Path
from tempfile import TemporaryDirectory
-from textwrap import dedent
from typing import TYPE_CHECKING, Any, Callable, Collection, Iterable,
Mapping, Sequence, cast
import dill
@@ -398,7 +398,7 @@ class _BasePythonVirtualenvOperator(PythonOperator,
metaclass=ABCMeta):
def get_python_source(self):
"""Return the source of self.python_callable."""
- return dedent(inspect.getsource(self.python_callable))
+ return textwrap.dedent(inspect.getsource(self.python_callable))
def _write_args(self, file: Path):
if self.op_args or self.op_kwargs:
diff --git a/scripts/ci/pre_commit/pre_commit_insert_extras.py
b/scripts/ci/pre_commit/pre_commit_insert_extras.py
index 81669d0493..72dfdba4f3 100755
--- a/scripts/ci/pre_commit/pre_commit_insert_extras.py
+++ b/scripts/ci/pre_commit/pre_commit_insert_extras.py
@@ -19,8 +19,8 @@ from __future__ import annotations
import os
import sys
+import textwrap
from pathlib import Path
-from textwrap import wrap
AIRFLOW_SOURCES_DIR = Path(__file__).parents[3].resolve()
@@ -57,7 +57,7 @@ if __name__ == "__main__":
global_constants_file_path = (
AIRFLOW_SOURCES_DIR / "dev" / "breeze" / "src" / "airflow_breeze" /
"global_constants.py"
)
- extras_list = wrap(", ".join(EXTRAS_DEPENDENCIES.keys()), 100)
+ extras_list = textwrap.wrap(", ".join(EXTRAS_DEPENDENCIES.keys()), 100)
extras_list = [line + "\n" for line in extras_list]
extras_code = [f" {extra}\n" for extra in EXTRAS_DEPENDENCIES.keys()]
insert_documentation(install_file_path, extras_list, INSTALL_HEADER,
INSTALL_FOOTER)
diff --git a/scripts/in_container/run_migration_reference.py
b/scripts/in_container/run_migration_reference.py
index 47b8dbed25..6e79b629ed 100755
--- a/scripts/in_container/run_migration_reference.py
+++ b/scripts/in_container/run_migration_reference.py
@@ -23,8 +23,8 @@ from __future__ import annotations
import os
import re
+import textwrap
from pathlib import Path
-from textwrap import wrap
from typing import TYPE_CHECKING, Iterable
from alembic.script import ScriptDirectory
@@ -125,7 +125,7 @@ def update_docs(revisions: Iterable[Script]):
revision=wrap_backticks(rev.revision) + revision_suffix(rev),
down_revision=wrap_backticks(rev.down_revision),
version=wrap_backticks(rev.module.airflow_version), # type:
ignore
- description="\n".join(wrap(rev.doc, width=60)),
+ description="\n".join(textwrap.wrap(rev.doc, width=60)),
)
)
diff --git a/setup.py b/setup.py
index 3bd81e8391..01b2b51493 100644
--- a/setup.py
+++ b/setup.py
@@ -28,10 +28,10 @@ import logging
import os
import subprocess
import sys
+import textwrap
import unittest
from copy import deepcopy
from pathlib import Path
-from textwrap import wrap
from typing import Iterable
from setuptools import Command, Distribution, find_namespace_packages, setup
@@ -206,7 +206,7 @@ class ListExtras(Command):
def run(self) -> None:
"""List extras."""
- print("\n".join(wrap(", ".join(EXTRAS_DEPENDENCIES.keys()), 100)))
+ print("\n".join(textwrap.wrap(", ".join(EXTRAS_DEPENDENCIES.keys()),
100)))
def git_version() -> str:
diff --git a/tests/dag_processing/test_job_runner.py
b/tests/dag_processing/test_job_runner.py
index ffa953f434..51187d7153 100644
--- a/tests/dag_processing/test_job_runner.py
+++ b/tests/dag_processing/test_job_runner.py
@@ -27,11 +27,11 @@ import pathlib
import random
import socket
import sys
+import textwrap
import threading
import time
from datetime import datetime, timedelta
from logging.config import dictConfig
-from textwrap import dedent
from unittest import mock
from unittest.mock import MagicMock, PropertyMock
@@ -892,7 +892,7 @@ class TestDagProcessorJobRunner:
@mock.patch("airflow.dag_processing.manager.Stats.timing")
def test_send_file_processing_statsd_timing(self, statsd_timing_mock,
tmp_path):
path_to_parse = tmp_path / "temp_dag.py"
- dag_code = dedent(
+ dag_code = textwrap.dedent(
"""
from airflow import DAG
dag = DAG(dag_id='temp_dag', schedule='0 0 * * *')
diff --git a/tests/dags/test_default_impersonation.py
b/tests/dags/test_default_impersonation.py
index 7ae7dadef5..82d4e47a86 100644
--- a/tests/dags/test_default_impersonation.py
+++ b/tests/dags/test_default_impersonation.py
@@ -17,8 +17,8 @@
# under the License.
from __future__ import annotations
+import textwrap
from datetime import datetime
-from textwrap import dedent
from airflow.models import DAG
from airflow.operators.bash import BashOperator
@@ -34,7 +34,7 @@ dag = DAG(dag_id="test_default_impersonation",
default_args=args)
deelevated_user = "airflow_test_user"
-test_command = dedent(
+test_command = textwrap.dedent(
f"""\
if [ '{deelevated_user}' != "$(whoami)" ]; then
echo current user $(whoami) is not {deelevated_user}!
diff --git a/tests/dags/test_impersonation.py b/tests/dags/test_impersonation.py
index 0c54a3cfbe..79bf08f79a 100644
--- a/tests/dags/test_impersonation.py
+++ b/tests/dags/test_impersonation.py
@@ -17,8 +17,8 @@
# under the License.
from __future__ import annotations
+import textwrap
from datetime import datetime
-from textwrap import dedent
from airflow.models import DAG
from airflow.operators.bash import BashOperator
@@ -34,7 +34,7 @@ dag = DAG(dag_id="test_impersonation", default_args=args)
run_as_user = "airflow_test_user"
-test_command = dedent(
+test_command = textwrap.dedent(
f"""\
if [ '{run_as_user}' != "$(whoami)" ]; then
echo current user is not {run_as_user}!
diff --git a/tests/dags/test_no_impersonation.py
b/tests/dags/test_no_impersonation.py
index 57b1ff17db..756e2e35ba 100644
--- a/tests/dags/test_no_impersonation.py
+++ b/tests/dags/test_no_impersonation.py
@@ -17,8 +17,8 @@
# under the License.
from __future__ import annotations
+import textwrap
from datetime import datetime
-from textwrap import dedent
from airflow.models import DAG
from airflow.operators.bash import BashOperator
@@ -32,7 +32,7 @@ args = {
dag = DAG(dag_id="test_no_impersonation", default_args=args)
-test_command = dedent(
+test_command = textwrap.dedent(
"""\
sudo ls
if [ $? -ne 0 ]; then