* Update cliff from branch 'master'
to b6119d504deca17e8c092b12fae209d944c6fa73
- Test python 3.10 and 3.11
As per the current release tested runtime, we
need to test python 3.8 to python 3.11 so using the
generic python testing template which run the python
versions jobs as per the current release runtime.
Also, updating the same in python classifier in setup.cfg
Change-Id: I8db58eb19a9e39067e8102df81a647450b2c1cf9
* Update cliff from branch 'master'
to 156e1eb0b9b9ad5feaa4b3e772f2cbc6a7694cf5
- Use importlib.metadata on Python 3.10+
Favor importlib.metadata.packages_distributions() over
importlib_metadata.packages_distributions() where it is available, i.e.,
on Python 3.10 and later.
Depend on PyPI importlib_metadata only on Python 3.9 and older:
conditionalize the requirements.txt entry on Python version.
Change-Id: I624fc0059057de05bb2bacd9c1238cba71ebad2a
* Update cliff from branch 'master'
to 3ee0725a094b0f80fa72f6bfc8bc97fe20b8fde8
- Merge "Handle complex objects in yaml formatter better"
- Handle complex objects in yaml formatter better
this patch adds special handling of objects that have either 'toDict'
or 'to_dict' method, converting those to dictionary before passing
them to pyYaml.
The main immediate aim is to support instances of
openstack.utils.Munch class in the YAML output.
Story: 2010906
Task: 48728
Change-Id: If3718477533987b6b88b27ac639c6689a2e4b327
* Update cliff from branch 'master'
to 76b5df665bbef098e91590b75470f2144da6c758
- Merge "Autofit table output if stdout is a tty"
- Autofit table output if stdout is a tty
nobody enjoys reading mangled tables in the terminal.
Be smart and auto-enable "fit width" if the output is a tty,
while still printing full lines when output is redirected (e.g. pipe)
so that e.g. grep and friends continue to work as before.
Unfortunately, tty detection is not reliable enough on Windows,
so this feature is not enabled there.
Change-Id: I46137d16ea3054a43de4a9f76477bda59ebacf10
* Update cliff from branch 'master'
to 53c050b8d060549f7409dd905f7d985435efa6cd
- Merge "Use upper-constraint in doc generation"
- Use upper-constraint in doc generation
Currently doc jobs are broken because the latest sphinx 7.2.0 is not
compatible with the latest release of openstackdocstheme.
This updates the docs/releasenotes target to use the global upper
constraints to avoid that issue.
Also, the following flake8 error is fixed by this change.
cliff/tests/test_formatters_table.py:53:10: E721 do not compare types,
for exact checks use `is` / `is not`, for instance checks use
`isinstance()`
Change-Id: Ia923ba1d0e2cf3327317e142cfa38470d9f053d2
* Update cliff from branch 'master'
to a9072007685734d78ead96fa72ac81e1136980c4
- Merge "Clarification of the algorithm used"
- Clarification of the algorithm used
Link was pointing to a wrong wikipedia page, we are using
Damerau-Levenshtein metric, which allows for additional "swap"
operation. A subtle but important distinction.
Signed-off-by: Jiri Podivin <jpodivin@redhat.com>
Change-Id: I6cc2499c371b86aaf6636d7a46416bc947c11bb2
* Update cliff from branch 'master'
to 6096869f7060bf74586b4f491affd3dea6630a8b
- Fix flake8 violation E721
use isinstance for type check instead of type(..) ==
Change-Id: I062f9423f418caee33ab892b8b499ea22d4be38a
* Update cliff from branch 'master'
to 72e81d7d846a8e306fd8d98e2f15270a8a537620
- Removing helper functions providing Python < 3.3 compatibility
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
* Update cliff from branch 'master'
to fb9a3a9b2daa21317d0adceca86215c393e975e6
- Strip trailing periods when getting description
This yields slightly prettier output.
Change-Id: Ibec7cd861eacc3630182d6a782ffaf361f449aa6
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
* Update cliff from branch 'master'
to 91c62985fb6c529cecfed5354ae687d62c25a821
- Merge "columns: Useful __str__, __repr__ implementation"
- columns: Useful __str__, __repr__ implementation
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>
* Update cliff from branch 'master'
to d1b46e9f97a990cc8456ecfc7efc5263a41f24ba
- Merge "Replace abc.abstractproperty with property and abc.abstractmethod"
- Replace abc.abstractproperty with property and abc.abstractmethod
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
* Update cliff from branch 'master'
to 9614d30450c642dd176ba00e6b6c2a893d742171
- Add Python3 antelope unit tests
This is an automatically generated patch to ensure unit testing
is in place for all the of the tested runtimes for antelope.
See also the PTI in governance [1].
[1]: https://governance.openstack.org/tc/reference/project-testing-interface.html
Change-Id: I96731db47eee8597bce78d69529695d76db998e4
* Update cliff from branch 'master'
to 58c853d1015c8bde2afa777a9bb1246a65645f3f
- Merge "Removing brackets around tested conditional"
- Removing brackets around tested conditional
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
* Update cliff from branch 'master'
to f782f42b94446a3401b644c93a9f120e77d5fb9e
- Merge "Remove final use of pkg_resources"
- Remove final use of pkg_resources
'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>
* Update cliff from branch 'master'
to 468d80e3ac49aacd24c37d8be89621a333c901c8
- Merge "Defer loading PyYAML"
- 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>
* Update cliff from branch 'master'
to 13f08e4828a7c60f522d7fa5858487ec35a06699
- Merge "Defer loading cmd2"
- Defer loading cmd2
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>
* Update cliff from branch 'master'
to 1b3d1b55b0df50409f322be3a44f60c6a869b2a8
- Merge "requirements: Remove explicit python-subunit dependency"
- requirements: Remove explicit python-subunit dependency
We don't rely on this ourselves and stestr will bring it in for us.
Change-Id: I51f305ac080c41463081e7039421d238b81f5d95
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
* Update cliff from branch 'master'
to 2b9cc5d28fd3d41e25d7409f58da7e8ce8f0d42d
- Merge "requirements: Remove explicit pbr dependency"
- requirements: Remove explicit pbr dependency
We don't use pbr at runtime; ergo, there is no reason to include this in
requirements.txt.
While we're here, we remove a note that is no longer true with the new
dependency resolver introduced in pip 20.3.
Change-Id: I39ee12f052fff6d69f8fe97949e6e5df7511647b
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
* Update cliff from branch 'master'
to 03817f32ae8c9f72b2a17418db31dde4e6dea4e4
- Merge "requirements: Remove explicit pyparsing dependency"
- requirements: Remove explicit pyparsing dependency
This was added nearly a decade ago to work around a packaging bug in
cmd2. We don't use this explicitly ourselves so we can and should remove
it. Do that.
Change-Id: Ia6061a22b9037d157c0b2afecb4e06bbc62c2d74
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
* Update cliff from branch 'master'
to 4854816403a2a90f360cbe8a58c88abf2d53fd3b
- Merge "Update Python testing per Zed cycle testing runtime"
- Update Python testing per Zed cycle testing runtime
In the Zed cycle, we have dropped the Python 3.6/3.7 [1] testing and its
support. Update the Python classifiers to reflect this.
Change-Id: Ieb80faf01d87e7fa7d717b74de6c5ec518ef9b05
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
* Update cliff from branch 'master'
to f363c274b5ab93270e8881acf8025287e9e04fd5
- Merge "setup.cfg: Replace dashes with underscores"
- setup.cfg: Replace dashes with underscores
Resolves warnings like the following:
UserWarning: Usage of dash-separated 'description-file' will not be
supported in future versions. Please use the underscore name
'description_file' instead
Change-Id: I328d2e7843e3ba62a6de4ef221c4f8564a64f234
* Update cliff from branch 'master'
to 5df8c37e06e32094cf606f0f204e5bc4e9c792c5
- Migrate Python 3.6/7 jobs to Python 3.8
Support for Python 3.6 and 3.7 is being removed globally. The current
latest release of python-novaclient (18.0.0) does not support these two
versions. The next python-neutronclient release does not, either.
This migrates Python 3.6/7 jobs to Python 3.8 because 3.8 is now
the minimum supported version.
This also replaces Python3 yoga unit tests by zena unit tests.
Depends-on: https://review.opendev.org/843115
Change-Id: I03957cf4bd0a96cb1d07e80727c184854b869fc3
* Update cliff from branch 'master'
to 8d2af7876ef299fce0ea292284b7d1000aa5172b
- Merge "Add Python3 yoga unit tests"
- Add Python3 yoga unit tests
This is an automatically generated patch to ensure unit testing
is in place for all the of the tested runtimes for yoga.
See also the PTI in governance [1].
[1]: https://governance.openstack.org/tc/reference/project-testing-interface.html
Change-Id: I4b6bb766c1272e32b09d59fac226792404895bc1
* Update cliff from branch 'master'
to a04a48f4f7dc72b1bcc95a5c6a550c7650e35ab3
- Removing modindex link from docs
The global module documentation is no longer being generated
and the link points to a non-existent document.
The purpose of global module documentation is now fulfilled by
the automatically generated class, and function level reference
documents which are linked properly.
As such there is no need to keep the link around, or to
reestablish module level documentation.
Signed-off-by: Jiri Podivin <jpodivin@redhat.com>
Change-Id: I05e5144a36f33aa5feb996964d1a098b1716cf6a
* Update cliff from branch 'master'
to 78dea943d740664f2a8d9e2023468176448b7a31
- Merge "Automatically page interactive root help output"
- Automatically page interactive root help output
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
* Update cliff from branch 'master'
to 734bc0c5da6915f10823a3124e08ba3ddbd4cc63
- Merge "Colourise and automatically page help output"
- Colourise and automatically page help output
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
* Update cliff from branch 'master'
to 865ab44713db03deb8147925801c33a14eba16e3
- Merge "Update unit test to satisfy python3.10+"
- Update unit test to satisfy python3.10+
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] fb35fa49d1
Change-Id: I18d9f1bea7bb5a7afb273550314c36da7b466a69
* Update cliff from branch 'master'
to b17176182129caf735cee9ef47466b3fb21aaeb8
- Merge "Add conflict_handler parameter as attribut in Command class"
- Add conflict_handler parameter as attribut in Command class
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
* Update cliff from branch 'master'
to 392f3b2e7cb2dad8036ebbaefbb75dd758914421
- Handle SIGPIPE exit gracefully
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
* Update cliff from branch 'master'
to d562aae651f4e4346ee921d8eb67d24141695609
- Merge "setup.cfg: Replace dashes with underscores"
- setup.cfg: Replace dashes with underscores
Setuptools v54.1.0 introduces a warning that the use of
dash-separated options in 'setup.cfg' will not be supported
in a future version [1].
Get ahead of the issue by replacing the dashes with underscores.
Without this, we see 'UserWarning' messages
like the following on new enough
versions of setuptools:
UserWarning: Usage of dash-separated 'description-file' will not be
supported in future versions. Please use the underscore name
'description_file' instead
[1] https://github.com/pypa/setuptools/commit/a2e9ae4cb
Change-Id: Icccc9cc2b3a0d236746c4b58a8815d25d8b0a443
* Update cliff from branch 'master'
to 075345196d0747168a27d71aae4e3d97c5746907
- Replace getargspec with getfullargspec
inspect.getargspec() is deprecated since py3
[1] https://docs.python.org/3/library/inspect.html#inspect.getargspec
Change-Id: I7a1692d9979e9ffaf781de1f39f5bfa59a01cf3c
* Update cliff from branch 'master'
to 0062d33aee38c3745d28fa719df5186bf16c1123
- Add Python3 xena unit tests
This is an automatically generated patch to ensure unit testing
is in place for all the of the tested runtimes for xena.
See also the PTI in governance [1].
[1]: https://governance.openstack.org/tc/reference/project-testing-interface.html
Change-Id: Id810ebcb6620b4f6235ef3d616b858b4ab6b18b4
* Update cliff from branch 'master'
to 117a1005dc208b55aba93652856c8001b28a48ce
- requirements: Uncap PrettyTable
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
* Update cliff from branch 'master'
to 4d16d2bf6997fbbb5d160261eec3dc39425ff3bb
- Merge "Make 'FormattableColumn' comparable"
- Make 'FormattableColumn' comparable
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>
* Update cliff from branch 'master'
to a5bdcc6e789adb0182df0721909d7b657f9a50b5
- Merge "Handle null values when sorting"
- Handle null values when sorting
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
* Update cliff from branch 'master'
to 0d18e8812cfead09c0ce1dfbc213c4200a5ee230
- Remove unicode from code
Change-Id: I040fccd1714dccd7a87aaf10d397ad3a3ef476d3
* Update cliff from branch 'master'
to b04cba81ac966717472ae714b6c65c9cc7535978
- Remove lower-constraints
This is not part of the PTI and is currently broken. While discussions
are ongoing about removing it from every project, there's a definite
lean towards doing so. Let's do just that. We can re-add in the future
if necessary.
While we're here, we fix some indentation in 'tox.ini'.
Change-Id: Ib4784d9da96d05a54acdfbb3744af0cb053c0c6c
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
* Update cliff from branch 'master'
- Merge "trivial: Remove references to Python 2.7"
- trivial: Remove references to Python 2.7
There were some in both the docs and the demo application.
Change-Id: I58d14cd3a372f9bdf617cbfbcb5ce34169ac83f8
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
* Update cliff from branch 'master'
- Merge "List setuptools under install_requires"
- List setuptools under install_requires
pkg_resources is used at runtime, making setuptools a runtime
dependency.
Change-Id: Ib1775a319e8ed953cb34e3c09809b8ca7a32b947
* Update cliff from branch 'master'
- Merge "Update requirements URLs in tox config"
- Update requirements URLs in tox config
Update the URL to the upper-constraints file to point to the redirect
rule on releases.openstack.org so will switch to the correct
upper-constraints list automatically when the requirements repository branches.
Change-Id: Ia69a02b539230e65e25da65d5d76a9f650490256
* Update cliff from branch 'master'
- columns: Make 'FormattableColumn' comparable
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
* Update cliff from branch 'master'
- Merge "Update requirements"
- Update requirements
We also need to change the lower-constraint requirements to make them
py3.8 compatible. See https://bugs.launchpad.net/nova/+bug/1886298
Change-Id: Id06963dfdb20074cb9d8f0f2416a8e0937006059
* Update cliff from branch 'master'
- doc: Update bug tracker to storyboard
cliff now uses storyboard as the bug tracker, but the documents
have not been updated.
Change-Id: Ie2ceda088f708dee2d6dd0877087e9a5c27e928f