-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This allows to auto-detect and load all installed pulp-glue plugins. It is primarily useful for workflows where knowing all sub-types of an Entity is only important at runtime.
- Loading branch information
Showing
5 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Added `load_plugins` to `pulp_glue.common` so plugins providing a "pulp_glue.plugins" entrypoint can be enumerated and loaded. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# pulp_glue.common | ||
|
||
::: pulp_glue.common |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,32 @@ | ||
import sys | ||
import typing as t | ||
|
||
if sys.version_info >= (3, 10): | ||
from importlib.metadata import entry_points | ||
else: | ||
from importlib_metadata import entry_points | ||
|
||
__version__ = "0.30.0.dev" | ||
|
||
# Keep track to prevent loading plugins twice | ||
loaded_plugins: t.Set[str] = set() | ||
|
||
|
||
def load_plugins(enabled_plugins: t.Optional[t.List[str]] = None) -> None: | ||
""" | ||
Load glue plugins that provide a `pulp_glue.plugins` entrypoint. | ||
This may be needed when you rely on the `TYPE_REGISTRY` attributes but cannot load the modules | ||
explicitely. | ||
Parameters: | ||
enabled_plugins: Optional list of plugins to consider for loading. | ||
""" | ||
for entry_point in entry_points(group="pulp_glue.plugins"): | ||
name = entry_point.name | ||
if ( | ||
enabled_plugins is None or entry_point.name in enabled_plugins | ||
) and entry_point.name not in loaded_plugins: | ||
plugin = entry_point.load() | ||
if hasattr(plugin, "mount"): | ||
plugin.mount() | ||
loaded_plugins.add(name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters