You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by tu...@apache.org on 2021/02/28 15:42:49 UTC
[airflow] branch master updated: Make airflow info to work with
pipes (#14528)
This is an automated email from the ASF dual-hosted git repository.
turbaszek pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/master by this push:
new a1097f6 Make airflow info to work with pipes (#14528)
a1097f6 is described below
commit a1097f6f29796bd11f8ed7b3651dfeb3e40eec09
Author: Tomek Urbaszek <tu...@gmail.com>
AuthorDate: Sun Feb 28 16:42:33 2021 +0100
Make airflow info to work with pipes (#14528)
After this change output from AirflowConsole can be piped in bash
without loosing some information thanks to fixed width of output.
Closes: #14518
Co-authored-by: Kamil BreguĊa <mi...@users.noreply.github.com>
---
airflow/cli/commands/cheat_sheet_command.py | 7 ++-----
airflow/cli/commands/info_command.py | 21 ++++++++++-----------
airflow/cli/simple_table.py | 6 ++++++
3 files changed, 18 insertions(+), 16 deletions(-)
diff --git a/airflow/cli/commands/cheat_sheet_command.py b/airflow/cli/commands/cheat_sheet_command.py
index e77ebad..0dcce3c 100644
--- a/airflow/cli/commands/cheat_sheet_command.py
+++ b/airflow/cli/commands/cheat_sheet_command.py
@@ -14,13 +14,10 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
-
from typing import Iterable, List, Optional, Union
-from rich.console import Console
-
from airflow.cli.cli_parser import ActionCommand, GroupCommand, airflow_commands
-from airflow.cli.simple_table import SimpleTable
+from airflow.cli.simple_table import AirflowConsole, SimpleTable
from airflow.utils.cli import suppress_logs_and_warning
from airflow.utils.helpers import partition
@@ -44,7 +41,7 @@ def display_commands_index():
actions_iter, groups_iter = partition(lambda x: isinstance(x, GroupCommand), commands)
actions, groups = list(actions_iter), list(groups_iter)
- console = Console()
+ console = AirflowConsole()
if actions:
table = SimpleTable(title=help_msg or "Miscellaneous commands")
table.add_column(width=40)
diff --git a/airflow/cli/commands/info_command.py b/airflow/cli/commands/info_command.py
index 9a32520..5db357a 100644
--- a/airflow/cli/commands/info_command.py
+++ b/airflow/cli/commands/info_command.py
@@ -27,10 +27,9 @@ from urllib.parse import urlsplit, urlunsplit
import requests
import tenacity
-from rich.console import Console
from airflow import configuration
-from airflow.cli.simple_table import SimpleTable
+from airflow.cli.simple_table import AirflowConsole, SimpleTable
from airflow.providers_manager import ProvidersManager
from airflow.typing_compat import Protocol
from airflow.utils.cli import suppress_logs_and_warning
@@ -181,7 +180,7 @@ _MACHINE_TO_ARCHITECTURE = {
class _BaseInfo:
- def info(self, console: Console) -> None:
+ def info(self, console: AirflowConsole) -> None:
"""
Print required information to provided console.
You should implement this function in custom classes.
@@ -190,12 +189,12 @@ class _BaseInfo:
def show(self) -> None:
"""Shows info"""
- console = Console()
+ console = AirflowConsole()
self.info(console)
def render_text(self) -> str:
"""Exports the info to string"""
- console = Console(record=True)
+ console = AirflowConsole(record=True)
with console.capture():
self.info(console)
return console.export_text()
@@ -212,7 +211,7 @@ class AirflowInfo(_BaseInfo):
self.config = ConfigInfo(anonymizer)
self.provider = ProvidersInfo()
- def info(self, console: Console):
+ def info(self, console: AirflowConsole):
console.print(
f"[bold][green]Apache Airflow[/bold][/green]: {self.airflow_version}\n", highlight=False
)
@@ -234,7 +233,7 @@ class SystemInfo(_BaseInfo):
self.python_location = anonymizer.process_path(sys.executable)
self.python_version = sys.version.replace("\n", " ")
- def info(self, console: Console):
+ def info(self, console: AirflowConsole):
table = SimpleTable(title="System info")
table.add_column()
table.add_column(width=100)
@@ -260,7 +259,7 @@ class PathsInfo(_BaseInfo):
os.path.exists(os.path.join(path_elem, "airflow")) for path_elem in system_path
)
- def info(self, console: Console):
+ def info(self, console: AirflowConsole):
table = SimpleTable(title="Paths info")
table.add_column()
table.add_column(width=150)
@@ -274,7 +273,7 @@ class PathsInfo(_BaseInfo):
class ProvidersInfo(_BaseInfo):
"""providers information"""
- def info(self, console: Console):
+ def info(self, console: AirflowConsole):
table = SimpleTable(title="Providers info")
table.add_column()
table.add_column(width=150)
@@ -321,7 +320,7 @@ class ConfigInfo(_BaseInfo):
except Exception: # noqa pylint: disable=broad-except
return "NOT AVAILABLE"
- def info(self, console: Console):
+ def info(self, console: AirflowConsole):
table = SimpleTable(title="Config info")
table.add_column()
table.add_column(width=150)
@@ -363,7 +362,7 @@ class ToolsInfo(_BaseInfo):
else:
return data[0].decode()
- def info(self, console: Console):
+ def info(self, console: AirflowConsole):
table = SimpleTable(title="Tools info")
table.add_column()
table.add_column(width=150)
diff --git a/airflow/cli/simple_table.py b/airflow/cli/simple_table.py
index 696b9bf..ce58811 100644
--- a/airflow/cli/simple_table.py
+++ b/airflow/cli/simple_table.py
@@ -25,11 +25,17 @@ from rich.syntax import Syntax
from rich.table import Table
from airflow.plugins_manager import PluginsDirectorySource
+from airflow.utils.platform import is_tty
class AirflowConsole(Console):
"""Airflow rich console"""
+ def __init__(self, *args, **kwargs):
+ super().__init__(*args, **kwargs)
+ # Set the width to constant to pipe whole output from console
+ self._width = 200 if not is_tty() else self._width
+
def print_as_json(self, data: Dict):
"""Renders dict as json text representation"""
json_content = json.dumps(data)