diff options
author | Stephen Finucane <sfinucan@redhat.com> | 2022-05-18 12:42:10 +0100 |
---|---|---|
committer | Stephen Finucane <sfinucan@redhat.com> | 2022-05-25 17:09:04 +0100 |
commit | 3e0eed49c5c7e38c906e6c31b948d273e3fa91be (patch) | |
tree | 198a4317718908441ee64a29cc1c9c76bbdbcee3 | |
parent | 6811218817ccc034161dfe1b14d51eb9edc05579 (diff) | |
download | cliff-3e0eed49c5c7e38c906e6c31b948d273e3fa91be.tar.gz |
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>
-rw-r--r-- | cliff/formatters/yaml_format.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/cliff/formatters/yaml_format.py b/cliff/formatters/yaml_format.py index 8b1e64d..71d4906 100644 --- a/cliff/formatters/yaml_format.py +++ b/cliff/formatters/yaml_format.py @@ -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() |