✨ Blacklist: support pythonversions & pluginversions

Also deprecate plain versions key.

That way we can now easier define blacklisted version ranges and also
limit blacklisting to specific python versions (on top of OctoPrint and
plugin versions).
This commit is contained in:
Gina Häußge committed 2021-04-15 17:31:15 +02:00
1 parent 61ed63d233
commit 17958a460d
3 files changed
+32 -9

No files matched your search

+12 -6
View File
@@ -734,7 +734,7 @@ def get_plugin_blacklist(settings, connectivity_checker=None):
import yaml
from octoprint.util import bom_aware_open
from octoprint.util.version import is_octoprint_compatible
from octoprint.util.version import is_octoprint_compatible, is_python_compatible
logger = log.getLogger(__name__ + ".startup")
@@ -765,13 +765,19 @@ def get_plugin_blacklist(settings, connectivity_checker=None):
):
continue
if "version" in entry:
if "pythonversions" in entry and not is_python_compatible(
*entry["pythonversions"]
):
continue
if "pluginversions" in entry:
logger.debug(
"Blacklisted plugin: {}, version: {}".format(
entry["plugin"], entry["version"]
"Blacklisted plugin: {}, versions: {}".format(
entry["plugin"], ", ".join(entry["pluginversions"])
)
)
result.append((entry["plugin"], entry["version"]))
for version in entry["pluginversions"]:
result.append((entry["plugin"], version))
elif "versions" in entry:
logger.debug(
"Blacklisted plugin: {}, versions: {}".format(
@@ -779,7 +785,7 @@ def get_plugin_blacklist(settings, connectivity_checker=None):
)
)
for version in entry["versions"]:
result.append((entry["plugin"], version))
result.append((entry["plugin"], "=={}".format(version)))
else:
logger.debug("Blacklisted plugin: {}".format(entry["plugin"]))
result.append(entry["plugin"])
+2 -1
View File
@@ -67,7 +67,8 @@ def plugin_manager(
this defaults to the entry point ``octoprint.plugin``.
plugin_disabled_list (list): A list of plugin identifiers that are currently disabled. If not provided this
defaults to all plugins for which ``enabled`` is set to ``False`` in the settings.
plugin_blacklist (list): A list of plugin identifiers/identifier-version tuples that are currently blacklisted.
plugin_blacklist (list): A list of plugin identifiers/identifier-requirement tuples
that are currently blacklisted.
plugin_restart_needing_hooks (list): A list of hook namespaces which cause a plugin to need a restart in order
be enabled/disabled. Does not have to contain full hook identifiers, will be matched with startswith similar
to logging handlers
+18 -2
View File
@@ -837,11 +837,27 @@ class PluginManager(object):
if plugin_considered_bundled is None:
plugin_considered_bundled = []
processed_blacklist = []
for entry in plugin_blacklist:
if isinstance(entry, tuple):
key, version = entry
try:
processed_blacklist.append(
(key, pkg_resources.Requirement.parse(version))
)
except Exception:
self.logger.warning(
"Invalid version requirement {} for blacklist "
"entry {}, ignoring".format(version, key)
)
else:
processed_blacklist.append(entry)
self.plugin_folders = plugin_folders
self.plugin_bases = plugin_bases
self.plugin_entry_points = plugin_entry_points
self.plugin_disabled_list = plugin_disabled_list
self.plugin_blacklist = plugin_blacklist
self.plugin_blacklist = processed_blacklist
self.plugin_restart_needing_hooks = plugin_restart_needing_hooks
self.plugin_obsolete_hooks = plugin_obsolete_hooks
self.plugin_validators = plugin_validators
@@ -1310,7 +1326,7 @@ class PluginManager(object):
def matches_plugin(entry):
if isinstance(entry, (tuple, list)) and len(entry) == 2:
entry_key, entry_version = entry
return entry_key == key and entry_version == version
return entry_key == key and version in entry_version
return False
return any(map(lambda entry: matches_plugin(entry), self.plugin_blacklist))