| Commit message (Collapse) | Author | Age | Files | Lines |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Functions used for deriving terminal width are no longer
necessary, as Python 3.3 introduced[0] built in solution.
Remaining helper function `utils.terminal_width` received docstring
explaining return parameters.
Method `_assign_max_widths` of the `TableFormatter` class was refactored
to no longer use the `stdout` argument. Uses of the method were adjusted accordingly.
Method now also has minimal docstring. Minor adjustment was made to inline comments
to more closely reflect functionality of the code.
[0]https://docs.python.org/3.8/library/os.html?highlight=get_terminal_size#os.get_terminal_size
Signed-off-by: Jiri Podivin <jpodivin@redhat.com>
Change-Id: I2898f099227e8c97aef6492c60f2f99038aa1357
|
|
|
|
|
|
|
| |
This yields slightly prettier output.
Change-Id: Ibec7cd861eacc3630182d6a782ffaf361f449aa6
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
|
|\ |
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
The default implementations for __str__ and __repr__ are rubbish.
>>> from osc_lib.cli import format_columns
>>> str(format_columns.DictColumn({'foo': 'bar'}))
'<osc_lib.cli.format_columns.DictColumn object at 0x7f6e26771e40>'
>>> repr(format_columns.DictColumn({'foo': 'bar'}))
'<osc_lib.cli.format_columns.DictColumn object at 0x7f6e26b57ac0>'
Make it useful.
>>> from osc_lib.cli import format_columns
>>> str(format_columns.DictColumn({'foo': 'bar'}))
"foo='bar'"
>>> repr(format_columns.DictColumn({'foo': 'bar'}))
"DictColumn({'foo': 'bar'})"
This helps when testing as the reason for mismatches will be more
obvious.
Change-Id: I8b8598875f896cb3dbf417515d377e7758b3b98b
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
|
| |\ |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | | |
While permissible syntactically, using brackets to wrap tested conditional is unnecessary
and potentially confusing. As without inserted whitspace the code may look as a function
call, rather than a statement and expression.
The construct is also considered erroneous by linters.
Closes-Bug: 1983593
Signed-off-by: Jiri Podivin <jpodivin@redhat.com>
Change-Id: I0a086a8349e2a72cae024857e148fddc3556c319
|
|/ /
| |
| |
| |
| |
| |
| |
| |
| | |
Replace abc.abstractproperty with property and abc.abstractmethod,
as abc.abstractproperty has been deprecated since python3.3[1]
[1]https://docs.python.org/3.8/whatsnew/3.3.html?highlight=deprecated#abc
Change-Id: I5e86211323c5e08553a5c777c0b6d1d85f95e1a9
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
'pkg_resources' is slow, while 'importlib.metadata' is the new shiny and
is *much* faster. Recent version of 'importlib.metadata' - namely those
found in Python 3.10 or provided by the 4.4 'importlib-metadata'
backport - now provide the last bit of functionality we were missing to
remove 'pkg_resources' entirely, namely the ability to map package names
to modules. This is used for generating epilogs.
The benefits of this are huge, yielding a near 40% decrease in runtime
for the cliffdemo app (100mS after compared to 160mS) before.
Change-Id: I934d8a196d76622671781643f36bdb8a07d2f319
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
|
| |
| |
| |
| |
| |
| |
| |
| | |
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>
|
|/
|
|
|
|
|
|
|
|
|
| |
We were importing cmd2 purely so we could do some exception
transformation. However, this is only needed if we're in interactive
mode. Avoid both the import of cmd2 and the transformation of the
exceptions unless this is the case. This speeds up import time by ~30%
for the demoapp on my machine (~160mS after compared to ~210mS before)
Change-Id: I2356dc9803b4d0eef3528c6d057207509932e6b2
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
|
|\ |
|
| |
| |
| |
| |
| |
| |
| |
| | |
The previous commit already ensures that the interactive help for
individual commands is sent to a pager. This does the same for the
'help' command with no arguments.
Change-Id: If5e38421d21e09f88a572dbb508b1997381bdb87
|
|\ \
| |/ |
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
Using the autopage library we can automatically send the help output to
a pager (less, by default), git-style. The pager is configured to not
reset the terminal on exit, avoiding the problem when piping to less
manually that the help text you want to refer to disappears off the
screen when you go to use it. The pager is only invoked when the output
is to the terminal.
Since we invoke the pager, we can ensure that it is correctly set up to
interpret ANSI escape codes, so it is safe to use colour to make the
output easier to read. The autopage library provides light styling of
the default argparse help output, and some additional colour
highlighting is added here for the command list (which is generated by
cliff, not using argparse's formatting code).
Change-Id: If9e1aa5166da32c58cc0fa617f4f81eaa9b2c470
Depends-On: https://review.opendev.org/c/openstack/requirements/+/799343
|
|\ \ |
|
| |/
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
Fedora is already testing Python 3.10 [1] and an issue
has been raised [2].
All the details are in the BZ ticket but TLDR is that
"optional arguments" was replaced with "options [3].
So, I used assertRegexp to accept both of them (i.e
"optional arguments" and "options").
[1] https://fedoraproject.org/wiki/Changes/Python3.10
[2] https://bugzilla.redhat.com/show_bug.cgi?id=1914138
[3] https://github.com/python/cpython/commit/fb35fa49d192368e94ffec09c092260ed0fea2e1
Change-Id: I18d9f1bea7bb5a7afb273550314c36da7b466a69
|
|\ \
| |/
|/| |
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
Adding conflict_handler as attribut in the Command class in order to be
able to take control of this parameter and change to different behavior
that argparse is handling: error / resolve / ignore.
Callers will be able to override it and get a proper Parser object.
Change-Id: I327ece99a04bc8b2ebfa554dea643b1f2a456336
|
|/
|
|
|
|
|
|
|
| |
If we are piping output to a command that exits before the entire
output is written (e.g. "head") then we will receive a BrokenPipeError.
This is expected and we should react by exiting gracefully, setting an
appropriate return code (128 + SIGPIPE).
Change-Id: I0d60e44450da1f48dbd8f459549da80fda69aad5
|
|
|
|
|
|
|
|
| |
inspect.getargspec() is deprecated since py3
[1] https://docs.python.org/3/library/inspect.html#inspect.getargspec
Change-Id: I7a1692d9979e9ffaf781de1f39f5bfa59a01cf3c
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
PrettyTable was capped at a < 0.8, which meant we were getting the
veritably ancient 0.7.2 release first release in April 2013 (!) [1].
The project is now being maintained as a Jazzband project [2], meaning
we should switch to this new version.
The only significant change required here is that we no longer set the
'min_width' attribute since that actually does something - the wrong
thing - now. We want this attribute to set a lower bound on the wrap
width as opposed to an absolute minimum we can use, which is what
setting the 'min_width' attribute would do.
While we're here, we also remove a now useless bit of Python 2 code and
bump cmd2 to a slightly newer version.
[1] https://pypi.org/project/prettytable/#history
[2] https://github.com/jazzband/prettytable
Change-Id: Iceac729e7a9429e8ab25c60524a48d0aaeebeb37
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
Depends-On: https://review.opendev.org/c/openstack/requirements/+/774917
|
|\ |
|
| |
| |
| |
| |
| |
| |
| | |
Allow users to reverse sorting direction.
Change-Id: Iecd539139c5a7ce4abaaee2ff5632a2459437d51
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
|
|\ \
| |/ |
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
Implement the '__lt__' magic method, thus providing the minimal set of
rich comparison methods necessary to support sorting. This will allows
users using these formatters for the more basic types (i.e. not dicts)
to sort their output using the standard '--sort-column' option.
Change-Id: I08e1f1bc75fa6452f19dfb9d221c1daec194d58d
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
|
|\ \
| |/ |
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
One unfortunate change (or fortunate, depending on how you look at
types) in Python 3 is the inability to sort iterables of different
types. For example:
>>> x = ['foo', 'bar', None, 'qux']
>>> sorted(x)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: '<' not supported between instances of 'NoneType' and 'str'
Fortunately, we can take advantage of the fact that by providing a
function for the 'key' that returns a tuple, we can sort on multiple
conditions. In this case, "when the first key returns that two elements
are equal, the second key is used to compare." [1] We can use this to
first separate the values by whether they are None or not, punting those
that are not to the end, before sorting the non-None values normally.
For example:
>>> x = ['foo', 'bar', None, 'qux']
>>> sorted(x, key=lambda k: (k is None, k))
['bar', 'foo', 'qux', None]
We were already using this feature implicitly through our use of
'operator.itemgetter(*indexes)', which will return a tuple if there is
more than one item in 'indexes', and now we simply make that explicit,
fixing the case where we're attempting to compare a comparable type
with None. For all other cases, such as comparing a value that isn't
comparable, we surround things with a try-catch and a debug logging
statement to allow things to continue.
Note that we could optimize what we're done further by building a key
value that covers all indexes, rather than using a for loop to do so.
For example:
>>> x = [('baz', 2), (None, 0), ('bar', 3), ('baz', 4), ('qux', 0)]
>>> sorted(x, key=lambda k: list(
... itertools.chain((k[i] is None, k[i]) for i in (0, 1)))
... )
[('bar', 3), ('baz', 2), ('baz', 4), ('qux', 0), (None, 0)]
However, this would be harder to grok and would also mean we're unable
to handle exceptions on a single column where e.g. there are mixed types
or types that are not comparable while still sorting on the other
columns. Perhaps this would be desirable for some users, but sorting on
a best-effort basis does seem wiser and generally more user friendly.
Anyone that wants to sort on such columns should ensure their types are
comparable or implement their own sorting implementation.
[1] https://www.kite.com/python/answers/how-to-sort-by-two-keys-in-python
Change-Id: I4803051a6dd05c143a15923254af97e32cd39693
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
Story: 2008456
Task: 41466
|
|/
|
|
| |
Change-Id: I040fccd1714dccd7a87aaf10d397ad3a3ef476d3
|
|\ |
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
Replace the following items with Python 3 style code.
- six.moves
- six.PY2
- six.PY3
- six.string_types
- six.text_type
Change-Id: I1656b976864c8f2343e658a4abf432d30c151d0b
|
|/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Currently, comparing instances of this fails:
>>> from cliff.columns import FormattableColumn
>>> class Test(FormattableColumn):
... def human_readable(self):
... return str(self._data)
...
>>> data = {'x': 'y'}
>>> x = Test(data)
>>> y = Test(data)
>>> x == y
False
Clearly it should not. Resolve this by implementing a custom comparison.
Change-Id: I4b96475ca6a689f4055dc5ea34b82b3867a65555
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
Story: #2008320
Task: #41218
|
|
|
|
|
|
|
|
| |
With the advent of importlib, entry points are no long a setuptools-only
thing. Update the docs to reflect that.
Change-Id: I099f397ddb4d71879597cfe67ef2a1eff4a8d1af
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
|
|
|
|
| |
Change-Id: Ib97cbf2c9b108932c437a6d69a6ab629244702b3
|
|
|
|
|
|
|
|
|
| |
If we receive SIGINT, exit gracefully: run the clean_up method; don't
print a stacktrace; exit with error code 130 (128 + SIGINT).
Change-Id: I77687133d5482912523814a28e42f4f3a1a146d5
Story: 2008124
Task: 40846
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Provide a new exception class for the help action to use to indicate
that the app should exit, instead of calling sys.exit(). This allows
argument parsing errors in interactive mode to print help without
exiting the entire application, while still being treated as a
short-cut to avoid every command plugin having to process argument
errors itself.
Change-Id: If882b305ff9186f97ece6c77ef8c1b888c24a72d
Story: 2008071
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The Bifrost team got an errors on their CLI that also affects OSC. When
in interactive mode, if argparse fails to parse the input due to, say,
a missing parameter, argparse by default thows a SystemExit(2), but
cmd2 doesn't like it because that could've been a signal to stop the
CLI, so it breaks the interactive session. This fix aims to bypass that
and keep the CLI running so we don't have to start it at every parameter
we forget to type in.
Change-Id: I0e2006a9625e2f8dbdbc0e5921acfb3853a06ee9
Story: 2008071
Task: 40782
|
|
|
|
|
|
|
|
|
| |
Switch to using stevedore now so that when the cache implementation is
released all cliff applications can take advantage of the performance
benefits.
Change-Id: Ib7bf53091470b55ab87082d315ca283d3600a636
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
|
|
|
|
|
|
|
|
|
|
|
|
| |
After [1] and [2], there is no need to cap the version of cmd2.
This will also fix the current "rally_openstack" import problems
experienced in the CI: http://paste.openstack.org/show/794701/
[1]https://review.opendev.org/#/c/712591/
[2]https://review.opendev.org/#/c/734629/
Change-Id: Ie15e3f5058c4bd104978d9f31f0590d6c795024b
|
|\ |
|
| |
| |
| |
| |
| | |
Closes-Bug: #1810213
Change-Id: I8c926152aa43359be376ec3dea83c42ecc499e80
|
|/
|
|
|
|
|
|
| |
osc-lib adds support for named groups of commands. There's nothing
particularly openstackclient about this support, so add it here.
This way when we add defered plugin loading, it'll work.
Change-Id: Ia0260d2607f4a240b39e90da4b5b09e7cdfde04f
|
|
|
|
|
|
| |
These are for <3.2
Change-Id: I376e3601d5799e11590b2814714655692159de99
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The __future__ module [1] was used in this context to ensure compatibility
between python 2 and python 3.
We previously dropped the support of python 2.7 [2] and now we only support
python 3 so we don't need to continue to use this module and the imports
listed below.
Imports commonly used and their related PEPs:
- `division` is related to PEP 238 [3]
- `print_function` is related to PEP 3105 [4]
- `unicode_literals` is related to PEP 3112 [5]
- `with_statement` is related to PEP 343 [6]
- `absolute_import` is related to PEP 328 [7]
[1] https://docs.python.org/3/library/__future__.html
[2] https://governance.openstack.org/tc/goals/selected/ussuri/drop-py27.html
[3] https://www.python.org/dev/peps/pep-0238
[4] https://www.python.org/dev/peps/pep-3105
[5] https://www.python.org/dev/peps/pep-3112
[6] https://www.python.org/dev/peps/pep-0343
[7] https://www.python.org/dev/peps/pep-0328
Change-Id: I7fa3bef0c7acd2b1f781bf12cc5a653cbc51d8c5
|
|
|
|
|
|
|
| |
we currently don't support py2 and py3 has removed mock to
unittest module.
Change-Id: I5c13f6d2edc219957f5902227497aa24249ea74e
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Cliff provides an additional conflict handler for argparse - 'ignore'.
To make this work it subclasses the argparse argument container classes
and adds a handle_conflict_ignore method. It also overrides the group
creation methods to return a subclassed argument group or mutually
exclusive argument group objects. This works, until you add a nested
argument group, at which point a standard argument group object is
returned which does not support the ignore conflict handler.
This change fixes the issue by returning subclassed group objects for
nested groups.
Change-Id: I517c61f24ba6194ff6181e115a3a23adbce3ea53
Story: 2005891
Task: 33749
|
|
|
|
|
|
|
|
|
| |
This allows consumers to let cliff know who they are, so the
autoprogram-sphinx directive doesn't produce messages like
This command is provided by the $me plugin.
Change-Id: I2d5a527910ddc64f83d0cba39c584b8b05a299b7
|
|\ |
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
This small improvement helps to decrease the amount of typing.
$ openstack resource provider list
...
^ too long?
$ alias os=openstack
$ os r p l
...
^ much better!
Change-Id: I713eab2bd9f949da01c03b65ff16a01de92e3e62
|
|\ \ |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | | |
This only affects interactive mode.
The desire is to enable a behaviour similar to the shell's set +errexit.
To do this required changing function returns in a number of places in
order to propogate the exit code back up to the app.
Change-Id: I1f2606cb43c8064e465e87d6801ed8d169daa26a
|