Commit Graph

794 Commits

Author SHA1 Message Date
Ghanshyam Mann b6119d504d 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
2024-01-11 15:37:23 -08:00
Benjamin A. Beasley 156e1eb0b9 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
2023-11-29 22:13:41 +09:00
Zuul 3ee0725a09 Merge "Handle complex objects in yaml formatter better" 2023-09-11 09:24:42 +00:00
Zuul 76b5df665b Merge "Autofit table output if stdout is a tty" 2023-09-11 09:24:41 +00:00
Zuul a3920dd0ae Merge "Add pre-commit" 2023-09-11 09:24:39 +00:00
Zuul 3a3be7615f Merge "Fix pre-commit issues" 2023-09-11 09:24:38 +00:00
Zuul 53c050b8d0 Merge "Use upper-constraint in doc generation" 2023-09-11 09:24:37 +00:00
Zuul a907200768 Merge "Clarification of the algorithm used" 2023-09-11 08:49:56 +00:00
Pavlo Shchelokovskyy 606644c13a 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
2023-09-05 14:31:40 +00:00
Stephen Finucane 2f3e17dfd1 Add pre-commit
We don't use hacking here, funnily enough.

Change-Id: I30734bc140db9ccb4d019961466d668159ab3991
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2023-09-05 10:17:38 +01:00
Stephen Finucane 13424d1214 Fix pre-commit issues
Mostly trailing spaces.

Change-Id: I3cde0f4bc51bdeb3e82859a131f866728234c9ad
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2023-09-05 10:17:38 +01:00
Pavlo Shchelokovskyy e02f89cd69 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
2023-08-29 13:00:36 +00:00
Pavlo Shchelokovskyy 6096869f70 Fix flake8 violation E721
use isinstance for type check instead of type(..) ==

Change-Id: I062f9423f418caee33ab892b8b499ea22d4be38a
2023-08-29 13:00:36 +00:00
Takashi Kajinami 989c440fe6 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
2023-08-21 09:53:41 +09:00
Jiri Podivin 72e81d7d84 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
2023-03-01 09:18:15 +01:00
Stephen Finucane fb9a3a9b2d Strip trailing periods when getting description
This yields slightly prettier output.

Change-Id: Ibec7cd861eacc3630182d6a782ffaf361f449aa6
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2022-12-12 18:14:52 +00:00
Jiri Podivin f2215ba0e7 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
2022-10-27 10:47:05 +02:00
Zuul 91c62985fb Merge "columns: Useful __str__, __repr__ implementation" 2022-10-04 18:15:39 +00:00
Zuul d1b46e9f97 Merge "Replace abc.abstractproperty with property and abc.abstractmethod" 2022-10-04 18:15:37 +00:00
Stephen Finucane 67217b0e56 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>
2022-10-03 14:23:47 +01:00
OpenStack Release Bot 9614d30450 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
2022-09-09 11:21:06 +00:00
Zuul 58c853d101 Merge "Removing brackets around tested conditional" 2022-08-04 18:00:46 +00:00
Jiri Podivin 56b700afca 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
2022-08-04 16:32:44 +02:00
ljhuang 4ba0a97f85 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
2022-08-04 13:03:13 +08:00
Zuul f782f42b94 Merge "Remove final use of pkg_resources" 2022-07-18 18:49:03 +00:00
Zuul 468d80e3ac Merge "Defer loading PyYAML" 2022-07-18 18:49:01 +00:00
Zuul 13f08e4828 Merge "Defer loading cmd2" 2022-07-18 18:40:53 +00:00
Zuul 1b3d1b55b0 Merge "requirements: Remove explicit python-subunit dependency" 2022-07-18 18:40:51 +00:00
Zuul 2b9cc5d28f Merge "requirements: Remove explicit pbr dependency" 2022-07-18 18:31:11 +00:00
Stephen Finucane 86061ad87d 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>
2022-07-15 16:08:26 +01:00
Zuul 03817f32ae Merge "requirements: Remove explicit pyparsing dependency" 2022-07-14 16:04:13 +00:00
Zuul 4854816403 Merge "Update Python testing per Zed cycle testing runtime" 2022-05-27 13:29:50 +00:00
Zuul f363c274b5 Merge "setup.cfg: Replace dashes with underscores" 2022-05-25 18:07:25 +00:00
Stephen Finucane 3e0eed49c5 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>
2022-05-25 17:09:04 +01:00
Stephen Finucane 6811218817 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>
2022-05-25 17:09:04 +01:00
Stephen Finucane 98095d406a 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>
2022-05-25 17:09:04 +01:00
Stephen Finucane a8418879c0 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>
2022-05-25 17:09:04 +01:00
Stephen Finucane 3d93a6464d 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>
2022-05-25 17:09:04 +01:00
Stephen Finucane 3e2e0139de 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>
2022-05-25 17:08:36 +01:00
Takashi Kajinami 5df8c37e06 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
2022-05-24 17:52:48 +09:00
Zuul 8d2af7876e Merge "Add Python3 yoga unit tests" 2022-03-04 21:16:20 +00:00
Jiri Podivin a04a48f4f7 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
2021-11-19 13:58:06 +01:00
Zuul 78dea943d7 Merge "Automatically page interactive root help output" 2021-09-20 22:58:33 +00:00
OpenStack Release Bot b1736c160d 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
2021-09-10 14:34:27 +00:00
Zuul 734bc0c5da Merge "Colourise and automatically page help output" 2021-08-06 18:29:46 +00:00
Zuul 865ab44713 Merge "Update unit test to satisfy python3.10+" 2021-08-06 18:03:40 +00:00
Zuul b171761821 Merge "Add conflict_handler parameter as attribut in Command class" 2021-07-20 17:06:26 +00:00
Zane Bitter 4e7c882c3c 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
2021-07-12 21:03:39 -04:00
Zane Bitter 8fa916e916 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
2021-07-12 21:03:32 -04:00
Joel Capitao 9b66f4066c 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
2021-06-15 14:53:54 +02:00