-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cast #915
base: main
Are you sure you want to change the base?
Cast #915
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Added `detail_context` to master-detail contexts. |
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. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# pulp_glue.common | ||
|
||
::: pulp_glue.common |
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) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,15 @@ documentation = "https://pulpproject.org/pulp-glue/docs/dev/" | |
repository = "https://github.com/pulp/pulp-cli" | ||
changelog = "https://pulpproject.org/pulp-cli/changes/" | ||
|
||
[project.entry-points."pulp_glue.plugins"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have you opened up the corresponding PRs in our other cli-plugin repositories? They won't be registered as loaded until they have made this change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is right, but i think it should be safe to fade this in slowly. |
||
ansible = "pulp_glue.ansible" | ||
certguard = "pulp_glue.certguard" | ||
container = "pulp_glue.container" | ||
core = "pulp_glue.core" | ||
file = "pulp_glue.file" | ||
python = "pulp_glue.python" | ||
rpm = "pulp_glue.rpm" | ||
|
||
[tool.setuptools.packages.find] | ||
where = ["."] | ||
include = ["pulp_glue.*"] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import random | ||
import string | ||
import typing as t | ||
|
||
import pytest | ||
|
||
from pulp_glue.common import load_plugins, loaded_plugins | ||
from pulp_glue.common.context import PulpContext, PulpRepositoryContext | ||
from pulp_glue.file.context import PulpFileRepositoryContext | ||
|
||
pytestmark = pytest.mark.glue | ||
|
||
|
||
@pytest.fixture | ||
def file_repository(pulp_ctx: PulpContext) -> t.Dict[str, t.Any]: | ||
name = "".join(random.choices(string.ascii_letters, k=8)) | ||
file_repository_ctx = PulpFileRepositoryContext(pulp_ctx) | ||
yield file_repository_ctx.create(body={"name": name}) | ||
file_repository_ctx.delete() | ||
|
||
|
||
def test_plugin_loading() -> None: | ||
load_plugins() | ||
assert "core" in loaded_plugins | ||
|
||
|
||
def test_type_registry() -> None: | ||
assert "file:file" in PulpRepositoryContext.TYPE_REGISTRY | ||
|
||
|
||
def test_detail_context(pulp_ctx: PulpContext, file_repository: t.Dict[str, t.Any]) -> None: | ||
master_ctx = PulpRepositoryContext(pulp_ctx) | ||
detail_ctx = master_ctx.detail_context(pulp_href=file_repository["pulp_href"]) | ||
assert isinstance(detail_ctx, PulpFileRepositoryContext) | ||
assert detail_ctx.entity["name"] == file_repository["name"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently none of the pulp_glue plugins have a
mount
method, do you see the need for one in the future?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure. This would be better "have" than "need".