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>
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>
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>
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>
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>
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>
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
It is not needed and stevedore is a fundamental package which should
try to keep its requirements list small.
Change-Id: I701613977f6c243c13d118d8822fe5db0e12f97e
This allows to get the list of valid entry points names declared for a
namespace, without loading them.
Change-Id: If9132edc14c2772732fd4ec0dc5dc3ebc4a56b3c
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
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
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
There were a few typos in the descriptions of the exceptions
in exception.py
These have been fixed.
Change-Id: I21310f1f296406b93bf599b92505ad55aae528a1
Closes-Bug: #1615661
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>
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>
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
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
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
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
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
occuring -> occurring
for patterns_loading.rst
Plus some source comment spelling fix.
Change-Id: Ia6c79588e70a4150fdcb8e71d14a4bba47a70a23
Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
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>
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
Add a restructuredtext directive for documenting a set of plugins with
the needed hooks to make it available is sphinx.
Change-Id: I1a24f9326b4e54174d9dc0ae366315fe29c3ac1b
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
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
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
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
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
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
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
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
A previous change added an argument to several methods without
updating their docstrings to describe it.
Change-Id: I10c753a2d935c0a4ae87ff9258c91f1530d398db