Commit Graph

114 Commits (e9204ee7b702f67c4de1c777db9482b065126407)

Author SHA1 Message Date
Doug Hellmann e9204ee7b7
add property methods to extension for more entry point values
The underlying EntryPoint class has some similar methods to fetch
these values, but they depend on the version of importlib.metadata
that is installed, so this provides a consistent API

Change-Id: I7a1b9541f0e4042a224e49c890ba3c63e8a5a259
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
2020-07-12 17:50:24 -04:00
Doug Hellmann bc04ca91e0
sphinxext: fix warning message for detailed list
Fix the way the warning for undocumented modules in a detail list is
produced. The new importlib.metadata.EntryPoint type is derived from
namedtuple so using string interpolation means the multi-part tuple
causes an error. Take the opportunity to include a more detailed
message.

Change-Id: I02223a982258a1bf8fc28fa91c7c090c7ac3554e
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
2020-07-12 15:01:34 -04:00
Doug Hellmann d5297167e0 switch to importlib.metadata package
Load entry points using 'importlib.metadata' instead of 'pkg_resources'.

Include a caching layer.  The cache stores the parsed text data from all
of the ini input files in a single JSON file with a name based on the
hash of the path entries and the mtimes. This should produce a unique
filename for each import path, regardless of the use of a virtualenv.

The data is stored in a format that means no other files need to be
examined or parsed in order to return EntryPoint objects.

Change-Id: I8b08f289d446f4775eac1e1a91997fa96f25f641
Depends-On: Ic6db7af34c87a636bfe55bacae03c42154f4b9c7
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
2020-07-06 08:39:52 -04:00
Michał Górny 34b9a13049 Replace external mock with built-in unittest.mock
Now that stevedore does not support Python 2 anymore, there is no need
to ever use the external 'mock' package.  Python 3.3+ has it integrated
as 'unittest.mock', so just use that.

Change-Id: I28a50cac12670bb6987b4c7794a15e15aa1fe965
Signed-off-by: Michał Górny <mgorny@gentoo.org>
2020-06-05 15:46:27 +02:00
Hervé Beraud db43e802fb Stop to use the __future__ module.
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: I5f8107287877dc5dc4a12c1f85e8671c8d49f56f
2020-06-03 10:34:57 +02:00
Sean McGinnis edc7f06a92 Mark sphinx extensions thread safe
This adds the return of some metadata to our sphinx extension setup to
indicate they are thread safe. This is needed to allow consuming
projects to do multithreaded docs builds. In some cases, this can save a
noticeable amount of time in job execution.

Change-Id: I43e8f0c992eaec9f5b669eea4ae551c8a3273588
Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
2020-04-21 15:14:20 +01:00
Stephen Finucane 1aca4bcbb7 Drop Python 2.7 support
Change-Id: I7ae34cb701111adb2968e9b0c153dfd60aeb2fbb
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
Sem-Ver: api-break
2020-04-21 15:14:10 +01:00
liuwei b13d7fe599 update git.openstack.org to opendev
Change-Id: Ie3617d76b6131386c2fa241b41888436ed44909f
2019-04-25 01:07:11 +00:00
zhangwen1 aa0f033838 Delete repeated param description.
Change-Id: Icdccc700a91f893a4427ee89c140de9a153e4c54
2019-03-14 18:49:08 +08:00
Sean McGinnis 5b39123aa4 Update sphinx logging to not use app object
Logging via the application object was deprecated in sphinx 1.6 and is
now removed in the master branch that will become 2.0. This updates our
sphinx extension to use the recommended sphinx.util.logging instead.

Closes-bug: #1798174

Change-Id: Ie66579146d68680905c3eac3d256369309130cf4
Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
2018-10-16 13:52:37 -05:00
qingszhao e43f7c5743 Removed older version of python added 3.5
In setup.cfg file the python 3.5 is added

Change-Id: I6dbad224fb05d0f2fdb70828d157429bb1cf6282
2018-09-29 20:59:54 +08:00
Daniel Watkins b8e1c16cf5 Add an ExtensionManager.items() method
The ExtensionManager.items() method is analogous to the Mapping.items()
method.

(This also refactors the _extensions_by_name generation logic out of
__getitem__.)

Change-Id: Iad3a58aec7908eb3a829892bbea567705ab2dd97
2017-08-10 16:01:58 -04:00
Thomas Bechtold 27500a3d92 Remove oslotest from test-requirements
It is not needed and stevedore is a fundamental package which should
try to keep its requirements list small.

Change-Id: I701613977f6c243c13d118d8822fe5db0e12f97e
2017-05-23 12:11:35 +02:00
Julien Danjou 6d56b58e22 extension: add entry_point_names method
This allows to get the list of valid entry points names declared for a
namespace, without loading them.

Change-Id: If9132edc14c2772732fd4ec0dc5dc3ebc4a56b3c
2017-01-13 15:52:38 +01:00
Julien Danjou eb04fc4a3e extension: expose _find_entry_points as list_entry_points
Having the ability to list the entry points without loading them can be quite
useful. Expose the internal method externally to help with that.

Change-Id: Id675f335957a95fcfce61934dfbfbb2c64af761a
2017-01-13 15:51:49 +01:00
Kevin Benton 04f5e154e5 Allow suppression of warnings from DriverManager
Some projects (e.g. Neutron) using the DriverManager with
another fallback mechanism when the alias doesn't exist don't
want the "Could not load warning" messages in the logs.

This patch allows the warn_on_missing_entrypoint kwarg to be
passed to DriverManager which passes it up to its parent
NamedExtensionManager.

Change-Id: Ia6f5f749fc2f73ca6091fa6d58506fddb058902a
2017-01-09 10:25:47 -08:00
Cao Xuan Hoang b43ac31d0e Add Apache 2.0 license to source file
As per OpenStack licensing guide lines [1]:
[H102 H103] Newly contributed Source Code should be licensed under
the Apache 2.0 license.

[1] http://docs.openstack.org/developer/hacking/#openstack-licensing

Change-Id: I81aa361c3a50bc76dd360002712a3a7b786621c4
2016-11-28 13:32:32 +07:00
Yvonne Stachowski c27ce0b878 Fix typos in exception.py
There were a few typos in the descriptions of the exceptions
in exception.py

These have been fixed.

Change-Id: I21310f1f296406b93bf599b92505ad55aae528a1
Closes-Bug: #1615661
2016-08-22 15:47:02 +00:00
Doug Hellmann 62398ed4a3 do not emit warnings for missing hooks
Add a flag to disable the default warning log messages in the
NamedExtensionManager and then have the HookManager pass False by
default.

Change-Id: I78c91bcfd8cd41929f25057791157f82eb4a3a50
Closes-Bug: #1611387
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
2016-08-09 17:02:00 -04:00
Jenkins bca3451dc6 Merge "make error reporting for extension loading quieter" 2016-07-14 03:38:44 +00:00
Doug Hellmann 4ec5022e4b make error reporting for extension loading quieter
Only log the full traceback for an import error from an extension if
debug logging is enabled. This avoids spurious tracebacks in the log
when an application probes for all available extensions or when a
dependency of an extension is not installed (in that case the error
message itself should be sufficient to debug the issue).

Change-Id: I43c24f3791d575c2ecf0d08d82d9de5d74ec1150
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
2016-07-13 11:55:57 -04:00
liangjingtao c8a3964ab7 Replace assertEquals() with assertEqual()
Fllow the hacking: http://docs.openstack.org/developer/hacking.
AssertEquals() logs a DeprecationWarning in Python 3.x,use
assertEqual() instead.This patch is to fix it.

Change-Id: I72f29a5f0858797140be20e3cad395a02b174bcb
Closes-Bug: #1600764
2016-07-11 18:56:09 +08:00
ChangBo Guo(gcb) 1218ab61a1 Fix NamedExtensionManager fails when loading failing extension in order
NamedExtensionManager refer to extensions by names passed by caller.
A keyError is raised when name_order=True and can't load all extensions.

Closes-Bug: #1575185
Change-Id: I79769d4296efe98727751adc19bb8f33d75ba729
2016-07-04 15:46:58 +08:00
Cyril Roelandt 6f81f6f1c1 NamedExtensionManager: call a callback when some names cannot be found
This will allow users to find out errors in their code that are currently
silently ignored.

Change-Id: I405511f9acc5319b1e4373be084f6a7c97556acf
2016-06-24 19:39:41 +02:00
Jenkins 5bb52db732 Merge "Trival:Remove unused logging import" 2016-01-15 07:08:18 +00:00
caoyue c28a2b1409 Trival:Remove unused logging import
Change-Id: Ic3a14308e8fbd1b545eb31a4f5a3f5ec6573c578
2016-01-15 10:58:15 +08:00
ChangBo Guo(gcb) 72e3e1177d Remove work around for NullHandler
logging module added NullHandler in Python 2.7, we have
dropped Python 2.6 support now, so don't need the work around
any more.

Change-Id: Ib6fdbc2f92cd66f4846243221e696f1b1fa712df
2016-01-13 10:53:21 +08:00
Jamie Lennox 01b446c1fa Use Stevedore exceptions for finding extensions
When there are no extensions or multiple extensions found for a
namespace stevedore raises RuntimeErrors. This means that consuming
applications must catch RuntimeErrors when loading plugins which may
mask errors coming from the plugin itself.

Instead have stevedore raise an error specific to the failure case that
can be handled from an application.

Change-Id: I0ab0556a589453bd8631d77f42506100b278a83d
Closes-Bug: #1501324
2015-11-30 14:37:12 +11:00
ChangBo Guo(gcb) bb73a14d24 Clean up Python 2.6 related stuff
Change-Id: I303465277b30dff66129b6c65112b3e427ee6292
2015-11-26 18:09:38 +08:00
Doug Hellmann e327c8226f Show how to add a plugin in a separate package
One of the most common misconceptions about plugins is that they must be
installed to the same python package as the application. Update the
documentation to provide an explicit example of providing plugins from a
separate package.

Also clean up the package metadata for the existing example to remove
references to URLs and email addresses that no longer work.

Change-Id: I801b6ec3ff287c5342ce63a865167f55d31c78d3
Closes-Bug: #1394393
2015-09-24 19:30:48 +00:00
Zhao Lei 02c9e7e144 Fix spelling typo for maunal
occuring -> occurring
for patterns_loading.rst

Plus some source comment spelling fix.

Change-Id: Ia6c79588e70a4150fdcb8e71d14a4bba47a70a23
Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
2015-09-24 13:47:30 +00:00
Cleber Rosa e833f8709f Examples typo fix
This fixes a simple typo in the basic examples used in the tutorial.

Change-Id: I914676c91def2fe611b69735141b3ceb342d26a7
Signed-off-by: Cleber Rosa <cleber.gnu@gmail.com>
2015-08-28 14:36:47 -03:00
Joshua Harlow 710f88e3b1 Titlecase looks nicer sometimes in detailed mode
Instead of having lowercase sections it can be quite nice
to at least have titled sections (which seems to be more of the
normal way rst sections are written).

Change-Id: I6754937a7d0d837de9166b3246659711e262be6c
2015-07-20 11:43:45 -07:00
Doug Hellmann 6677b6a07b Document the signature for check_func
Change-Id: I718372d56def9c6abd715fd31bb1841e0fa1ad4f
2015-06-25 23:22:16 +00:00
Jenkins c43bf3b010 Merge "Add sphinx integration" 2015-05-28 01:54:56 +00:00
Doug Hellmann 7295f785f0 Add sphinx integration
Add a restructuredtext directive for documenting a set of plugins with
the needed hooks to make it available is sphinx.

Change-Id: I1a24f9326b4e54174d9dc0ae366315fe29c3ac1b
2015-05-27 23:36:04 +00:00
Jenkins e5f96a88a7 Merge "Fix Python versions supported" 2015-05-17 21:59:57 +00:00
Davanum Srinivas 2ef21b3210 Fix Python versions supported
We have CI for 2.6, 2.7, 3.4. So make sure
all references to other versions are removed and
all 3 versions above are correctly mentioned where
required.

Make sure we specify 3.4 everywhere needed

Change-Id: I2c90bccfc7495bf8197319196a12b2a8bd0519f1
2015-05-13 11:39:43 -04:00
Doug Hellmann f20b94c59b re-raise exception with full traceback
Rather than raising the exception using the local reference, use a bare
raise to ensure that the original traceback is preserved. This reports
the error as coming from inside the plugin code, rather than from inside
stevedore, and helps with debugging.

Change-Id: I4d7c002f378fb6491aa5c9e262084d70924112de
2015-04-23 14:58:13 +00:00
Doug Hellmann f5eea34ee0 Fix test for finding multiple drivers
The mocks in the old version of the test were not bypassing the right
things and the work required to actually bypass them properly was getting
ugly. Rather than mocking, instantiate a valid test instance and then
explicitly call the method that does the validation we're trying to test.

Change-Id: I26a6c6931cc8e95cc00127fd1ad7ab43f396389a
2015-03-03 14:21:58 -05:00
Doug Hellmann 37c94cd0d6 Use pkg_resources resolve() and require() instead of load()
setuptools 11.3 deprecated the require flag to load() in favor of two
new methods. If those methods are present, use them instead of calling
load(). If those methods are not present, continue to use load() as
before.

Change-Id: I800eec863e34ba4c7a90153e6ae2bfa953bfddd6
Closes-bug: #1407778
2015-01-05 14:57:32 -05:00
Abhishek Chanda bbafbe9dab Implement a __contains__ override for extension manager
Change-Id: I027c576e36fc0f4e016b6aec67f585bf2c03bd7b
Closes-Bug: #1374099
2014-12-04 13:57:06 -05:00
Abhishek Chanda 4f2b64720f Migrate tox to use testr
This patch moves all unit tests to use
testr as the test runner. This means all
tests need to be subclassed from unittest
to be discovered by testr

Change-Id: I9b0e782be87ea2b5db72b56ddad1d239a83e9ee3
Closes-Bug: #1330204
2014-10-09 15:30:08 -07:00
shuangtai d9d11fc612 use six.add_metaclass
Using six.add_metaclass instead of "__metaclass__" for Python 3.x
compatibility.

Change-Id: I8bf33fb1770511657587c8f7a33acfcf9a351e79
2014-06-10 14:33:40 +08:00
Julien Danjou 3668de2513 driver: raise by default on import failure
When using the DriverManager class, if the driver fails to load, it's
actually better by default to re-raise the exception. It's not something
possible when loading multiple extension, but it's safe to do so with
drivers. This just changes the default behaviour, and it can still be
overridden.

The upside of that change is that when you try to load a driver that
cannot be loaded because of missing dependency, you actually get the
ImportError backtrace on your screen rather than the useless:
  RuntimeError: No 'foo' driver found, looking for 'bar'

which doesn't help at all. And the default mechanism that logs via
LOG.error() doesn't print anything at the screen if the application
didn't configure the logging subsystem.

Change-Id: I67d9e13a07c822c54dd16ac9ae7716747a24dd73
2014-04-25 14:51:45 +02:00
Doug Hellmann 2bbf3eb569 Only log error when no load handler is set
Only log an error from loading a plugin if no load
failure handler callback is provided. Otherwise,
assume the handler will do any logging it wants.

Change-Id: Iac83f3c140067bc3d1996c40c0184e4a0d0b564a
2014-03-27 10:22:33 -07:00
Doug Hellmann 73a3a601fa Fix the test manager implementation
Partial-bug: #1273455

Change-Id: I5402d71197979e579a2145f7f775b3e693dccfcc
2014-01-27 17:28:44 -05:00
Doug Hellmann 79c4059234 Make requirements checking optional
Commit 3c2b1df85a hard-coded requirements
checking when a plugin is loaded to be turned off (the previous default
was turned on). This commit adds a parameter so the caller can decide.

Change-Id: I639c1fed7231b8adeab1e3ef9c863763a60bfd0d
2014-01-25 12:07:10 -05:00
Doug Hellmann 8c31425bba Update docstrings
A previous change added an argument to several methods without
updating their docstrings to describe it.

Change-Id: I10c753a2d935c0a4ae87ff9258c91f1530d398db
2014-01-25 12:04:22 -05:00
Jenkins 8a67d41e7a Merge "Allow a on_load_failure_callback to be provided" 2014-01-22 18:39:16 +00:00