This is an automated email from the ASF dual-hosted git repository.
potiuk 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 cc8519d1be Refactor: Simplify code in utils (#33268)
cc8519d1be is described below
commit cc8519d1bedd665d89834343171ecf62e72d8f2a
Author: Miroslav Šedivý <[email protected]>
AuthorDate: Thu Aug 10 22:54:13 2023 +0000
Refactor: Simplify code in utils (#33268)
---
airflow/utils/file.py | 3 +--
airflow/utils/log/file_task_handler.py | 11 +++++------
2 files changed, 6 insertions(+), 8 deletions(-)
diff --git a/airflow/utils/file.py b/airflow/utils/file.py
index fb17ee6a8d..2b230b6129 100644
--- a/airflow/utils/file.py
+++ b/airflow/utils/file.py
@@ -22,7 +22,6 @@ import io
import logging
import os
import zipfile
-from collections import OrderedDict
from pathlib import Path
from typing import Generator, NamedTuple, Pattern, Protocol, overload
@@ -230,7 +229,7 @@ def _find_path_from_directory(
]
# evaluation order of patterns is important with negation
# so that later patterns can override earlier patterns
- patterns = list(OrderedDict.fromkeys(patterns).keys())
+ patterns = list(dict.fromkeys(patterns))
dirs[:] = [subdir for subdir in dirs if not
ignore_rule_type.match(Path(root) / subdir, patterns)]
diff --git a/airflow/utils/log/file_task_handler.py
b/airflow/utils/log/file_task_handler.py
index 6c8073b005..2a7bd688b5 100644
--- a/airflow/utils/log/file_task_handler.py
+++ b/airflow/utils/log/file_task_handler.py
@@ -491,12 +491,11 @@ class FileTaskHandler(logging.Handler):
@staticmethod
def _read_from_local(worker_log_path: Path) -> tuple[list[str], list[str]]:
messages = []
- logs = []
- files = list(worker_log_path.parent.glob(worker_log_path.name + "*"))
- if files:
- messages.extend(["Found local files:", *[f" * {x}" for x in
sorted(files)]])
- for file in sorted(files):
- logs.append(Path(file).read_text())
+ paths = sorted(worker_log_path.parent.glob(worker_log_path.name + "*"))
+ if paths:
+ messages.append("Found local files:")
+ messages.extend(f" * {x}" for x in paths)
+ logs = [file.read_text() for file in paths]
return messages, logs
def _read_from_logs_server(self, ti, worker_log_rel_path) ->
tuple[list[str], list[str]]: