Skip to content

Commit 861c490

Browse files
committed
Allow selecting enabled plugins
fixes TBA
1 parent a373dff commit 861c490

File tree

3 files changed

+33
-13
lines changed

3 files changed

+33
-13
lines changed

CHANGES/+select_plugins.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added ``ENABLED_PLUGINS`` option to allow selecting installed plugins to be enabled.

pulpcore/app/settings.py

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212

1313
from contextlib import suppress
1414
from importlib import import_module
15+
from importlib.metadata import entry_points
1516
from logging import getLogger
1617
from pathlib import Path
17-
from pkg_resources import iter_entry_points
1818

1919
from cryptography.fernet import Fernet
2020
from django.core.exceptions import ImproperlyConfigured
@@ -81,14 +81,6 @@
8181
"pulpcore.app",
8282
]
8383

84-
# Enumerate the installed Pulp plugins during the loading process for use in the status API
85-
INSTALLED_PULP_PLUGINS = []
86-
87-
for entry_point in iter_entry_points("pulpcore.plugin"):
88-
plugin_app_config = entry_point.load()
89-
INSTALLED_PULP_PLUGINS.append(entry_point.module_name)
90-
INSTALLED_APPS.append(plugin_app_config)
91-
9284
# Optional apps that help with development, or augment Pulp in some non-critical way
9385
OPTIONAL_APPS = [
9486
"crispy_forms",
@@ -314,7 +306,7 @@
314306

315307
# HERE STARTS DYNACONF EXTENSION LOAD (Keep at the very bottom of settings.py)
316308
# Read more at https://dynaconf.readthedocs.io/en/latest/guides/django.html
317-
from dynaconf import DjangoDynaconf, Validator # noqa
309+
from dynaconf import DjangoDynaconf, Dynaconf, Validator # noqa
318310

319311
# Validators
320312
content_origin_validator = Validator(
@@ -380,14 +372,36 @@
380372
)
381373

382374

375+
def load_plugin_config_hook(settings):
376+
# Enumerate the installed Pulp plugins during the loading process for use in the status API
377+
ENABLED_PLUGINS = getattr(settings, "ENABLED_PLUGINS", None)
378+
installed_plugins = []
379+
installed_plugin_apps = []
380+
381+
for entry_point in entry_points()["pulpcore.plugin"]:
382+
if ENABLED_PLUGINS is not None and entry_point.name not in ENABLED_PLUGINS:
383+
continue
384+
installed_plugins.append(entry_point.module)
385+
installed_plugin_apps.append(entry_point.load())
386+
387+
plugin_settings = Dynaconf(
388+
PRELOAD_FOR_DYNACONF=[f"{module}.app.settings" for module in installed_plugins]
389+
)
390+
391+
data = {"dynaconf_merge": True}
392+
data.update(plugin_settings.as_dict())
393+
data.update(settings.as_dict())
394+
data["INSTALLED_APPS"].extend(installed_plugin_apps)
395+
data["INSTALLED_APPS"].append("dynaconf_merge_unique")
396+
return data
397+
398+
383399
settings = DjangoDynaconf(
384400
__name__,
385401
ENVVAR_PREFIX_FOR_DYNACONF="PULP",
386402
ENV_SWITCHER_FOR_DYNACONF="PULP_ENV",
387-
PRELOAD_FOR_DYNACONF=[
388-
"{}.app.settings".format(plugin_name) for plugin_name in INSTALLED_PULP_PLUGINS
389-
],
390403
ENVVAR_FOR_DYNACONF="PULP_SETTINGS",
404+
post_hooks=(load_plugin_config_hook,),
391405
load_dotenv=False,
392406
validators=[
393407
api_root_validator,

staging_docs/admin/learn/settings.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ The password for Redis.
157157
Pulp defines the following settings itself:
158158

159159

160+
### ENABLED_PLUGINS
161+
162+
An optional list of plugin names.
163+
If provided, Pulp will limit loading plugins to this list.
164+
If omitted, Pulp will load all installed plugins.
160165

161166
### API_ROOT
162167

0 commit comments

Comments
 (0)