MCPcopy
hub / github.com/GitGuardian/ggshield / enable_installed_plugin

Function enable_installed_plugin

ggshield/core/plugin/loader.py:111–159  ·  view source on GitHub ↗

Enable the canonical plugin key and migrate any stale aliases. Older ggshield versions wrote the enable row under the wheel's distribution name; the loader now keys discovery on the ``ggshield.plugins`` entry-point name. After a fresh install or update we therefore need to: 1.

(
    enterprise_config: EnterpriseConfig,
    plugin_name: str,
    version: str,
    wheel_path: Path,
)

Source from the content-addressed store, hash-verified

109
110
111def enable_installed_plugin(
112 enterprise_config: EnterpriseConfig,
113 plugin_name: str,
114 version: str,
115 wheel_path: Path,
116) -> str:
117 """Enable the canonical plugin key and migrate any stale aliases.
118
119 Older ggshield versions wrote the enable row under the wheel's
120 distribution name; the loader now keys discovery on the
121 ``ggshield.plugins`` entry-point name. After a fresh install or
122 update we therefore need to:
123
124 1. Write the canonical row under the entry-point name (so
125 ``discover_plugins`` finds it enabled).
126 2. Remove any pre-existing row under a known alias (the caller's
127 ``plugin_name`` — catalog reference or distribution name — and
128 the wheel's distribution name as encoded in
129 ``wheel_path.parent.name``).
130 3. Carry over the user's ``auto_update`` choice from any removed
131 alias so an explicit ``auto_update: false`` survives the
132 migration. When more than one alias exists, the strictest
133 (``False``) wins so user intent is never silently relaxed.
134
135 Update.py passes the loader's discovered canonical name as
136 ``plugin_name`` (already the entry-point name), so the legacy
137 alias only becomes visible via ``wheel_path.parent.name``. Install
138 paths pass either the catalog reference or the distribution name,
139 both of which become aliases here.
140 """
141 config_key = resolve_config_key(wheel_path, fallback=plugin_name)
142
143 legacy_keys = {plugin_name, wheel_path.parent.name}
144 legacy_keys.discard(config_key)
145
146 carried_auto_update: Optional[bool] = None
147 for legacy_key in legacy_keys:
148 legacy = enterprise_config.plugins.get(legacy_key)
149 if legacy is None:
150 continue
151 # Honor the strictest setting found across aliases.
152 if carried_auto_update is None or not legacy.auto_update:
153 carried_auto_update = legacy.auto_update
154 enterprise_config.remove_plugin(legacy_key)
155
156 enterprise_config.enable_plugin(config_key, version=version)
157 if carried_auto_update is not None:
158 enterprise_config.plugins[config_key].auto_update = carried_auto_update
159 return config_key
160
161
162@dataclass

Callers 6

_install_from_urlFunction · 0.90
update_cmdFunction · 0.90

Calls 4

resolve_config_keyFunction · 0.85
getMethod · 0.80
remove_pluginMethod · 0.80
enable_pluginMethod · 0.80

Tested by

no test coverage detected