diff options
-rw-r--r-- | .zuul.yaml | 14 | ||||
-rw-r--r-- | cliff/app.py | 9 | ||||
-rw-r--r-- | cliff/command.py | 24 | ||||
-rw-r--r-- | cliff/formatters/yaml_format.py | 8 | ||||
-rw-r--r-- | requirements.txt | 7 | ||||
-rw-r--r-- | setup.cfg | 5 | ||||
-rw-r--r-- | test-requirements.txt | 5 |
7 files changed, 30 insertions, 42 deletions
@@ -1,6 +1,6 @@ - job: - name: cliff-tox-py37-neutronclient-tip - parent: openstack-tox-py37 + name: cliff-tox-py38-neutronclient-tip + parent: openstack-tox-py38 description: | Run unit tests for neutronclient with master branch of cliff @@ -23,15 +23,15 @@ templates: - check-requirements - lib-forward-testing-python3 - - openstack-python3-xena-jobs + - openstack-python3-zed-jobs - publish-openstack-docs-pti check: jobs: - - cliff-tox-py37-neutronclient-tip - - osc-tox-py36-tips: + - cliff-tox-py38-neutronclient-tip + - osc-tox-py38-tips: branches: ^master$ gate: jobs: - - cliff-tox-py37-neutronclient-tip - - osc-tox-py36-tips: + - cliff-tox-py38-neutronclient-tip + - osc-tox-py38-tips: branches: ^master$ diff --git a/cliff/app.py b/cliff/app.py index 798b41f..10a4941 100644 --- a/cliff/app.py +++ b/cliff/app.py @@ -20,8 +20,6 @@ import logging.handlers import os import sys -import cmd2 - from cliff import _argparse from . import complete from . import help @@ -403,7 +401,12 @@ class App(object): try: parsed_args = cmd_parser.parse_args(sub_argv) except SystemExit as ex: - raise cmd2.exceptions.Cmd2ArgparseError from ex + if self.interactive_mode: + # Defer importing cmd2 as it is a slow import + import cmd2 + raise cmd2.exceptions.Cmd2ArgparseError from ex + else: + raise ex result = cmd.run(parsed_args) except BrokenPipeError as err1: result = _SIGPIPE_EXIT diff --git a/cliff/command.py b/cliff/command.py index 0a02525..f8e38ad 100644 --- a/cliff/command.py +++ b/cliff/command.py @@ -13,6 +13,7 @@ import abc import inspect +import importlib_metadata from stevedore import extension from cliff import _argparse @@ -27,26 +28,15 @@ def _get_distributions_by_modules(): distribution name (the name used with pip and PyPI) do not always match. We want to report which distribution caused the command to be installed, so we need to look up the values. - """ - import pkg_resources global _dists_by_mods if _dists_by_mods is None: - results = {} - for dist in pkg_resources.working_set: - try: - mod_names = dist.get_metadata('top_level.txt').strip() - except Exception: - # Could not retrieve metadata. Either the file is not - # present or we cannot read it. Ignore the - # distribution. - pass - else: - # Distributions may include multiple top-level - # packages (see setuptools for an example). - for mod_name in mod_names.splitlines(): - results[mod_name] = dist.project_name - _dists_by_mods = results + # There can be multiple distribution in the case of namespace packages + # so we'll just grab the first one + _dists_by_mods = { + k: v[0] for k, v in + importlib_metadata.packages_distributions().items() + } return _dists_by_mods 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() diff --git a/requirements.txt b/requirements.txt index 4450bd7..79ed14f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,10 +1,7 @@ -# The order of packages is significant, because pip processes them in the order -# of appearance. Changing the order has an impact on the overall integration -# process, which may cause wedges in the gate later. -pbr!=2.1.0,>=2.0.0 # Apache-2.0 autopage>=0.4.0 # Apache 2.0 +# TODO: Drop this when Python 3.10 is our minimum supported version +importlib_metadata>=4.4 # Apache-2.0 cmd2>=1.0.0 # MIT PrettyTable>=0.7.2 # BSD -pyparsing>=2.1.0 # MIT stevedore>=2.0.1 # Apache-2.0 PyYAML>=3.12 # MIT @@ -5,15 +5,14 @@ author = OpenStack author_email = openstack-discuss@lists.openstack.org summary = Command Line Interface Formulation Framework home_page = https://docs.openstack.org/cliff/latest/ -python_requires = >=3.6 +python_requires = >=3.8 classifier = Development Status :: 5 - Production/Stable License :: OSI Approved :: Apache Software License Programming Language :: Python Programming Language :: Python :: 3 - Programming Language :: Python :: 3.6 - Programming Language :: Python :: 3.7 Programming Language :: Python :: 3.8 + Programming Language :: Python :: 3.9 Programming Language :: Python :: 3 :: Only Programming Language :: Python :: Implementation :: CPython Intended Audience :: Developers diff --git a/test-requirements.txt b/test-requirements.txt index 686ff61..75f4d52 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,8 +1,3 @@ -# The order of packages is significant, because pip processes them in the order -# of appearance. Changing the order has an impact on the overall integration -# process, which may cause wedges in the gate later. - -python-subunit>=1.0.0 # Apache-2.0/BSD stestr>=1.0.0 # Apache-2.0 testtools>=2.2.0 # MIT testscenarios>=0.4 # Apache-2.0/BSD |