Defer loading PyYAML

Yet another library that's slow to import and is totally optional. Defer
loading this one also and speed up initial start time.

Change-Id: Ic694b4d36dbf7ce87bc8fe9a2f8b0597719418a1
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
This commit is contained in:
Stephen Finucane 2022-05-18 12:42:10 +01:00
parent 6811218817
commit 3e0eed49c5
1 changed files with 6 additions and 2 deletions

View File

@ -13,8 +13,6 @@
"""Output formatters using PyYAML.
"""
import yaml
from . import base
from cliff import columns
@ -25,6 +23,9 @@ class YAMLFormatter(base.ListFormatter, base.SingleFormatter):
pass
def emit_list(self, column_names, data, stdout, parsed_args):
# the yaml import is slow, so defer loading until we know we want it
import yaml
items = []
for item in data:
items.append(
@ -36,6 +37,9 @@ class YAMLFormatter(base.ListFormatter, base.SingleFormatter):
yaml.safe_dump(items, stream=stdout, default_flow_style=False)
def emit_one(self, column_names, data, stdout, parsed_args):
# the yaml import is slow, so defer loading until we know we want it
import yaml
for key, value in zip(column_names, data):
dict_data = {
key: (value.machine_readable()