🥅 Do not support pyc plugins

A pyc file alone should really never happen anyhow in our plugin setup,
and they would not load under Py3 anyhow as we can't parse the
compatibility information right now.

Simply removing their support altogether as it should not have been
utilized anywhere anyhow as far as I am aware, and never was officially
documented as supported to boot.
This commit is contained in:
Gina Häußge committed 2020-11-12 10:11:49 +01:00
1 parent 9a57362602
commit a4b44a8b0f
2 files changed
+16 -39

No files matched your search

+5 -27
View File
@@ -665,7 +665,7 @@ class PluginInfo(object):
@property
def parsed_metadata(self):
"""The plugin metadata parsed from the plugin ``__init__.py``'s AST."""
"""The plugin metadata parsed from the plugin's AST."""
return self._cached_parsed_metadata
@property
@@ -680,27 +680,8 @@ class PluginInfo(object):
def looks_like_plugin(self):
"""
Returns whether the plugin actually looks like a plugin (has control properties) or not.
Note that compiled (.pyc) plugins for now will return True here as well, since we
currently cannot easily parse metadata from them.
"""
return (
self.parsed_metadata.get("has_control_properties", False) or self.is_compiled
)
@property
def is_compiled(self):
path = self.location
if not path:
return False
if os.path.isdir(path):
path = os.path.join(self.location, "__init__.py")
if not os.path.isfile(path):
return False
return path.endswith(".pyc")
return self.parsed_metadata.get("has_control_properties", False)
def _parse_metadata(self):
result = {}
@@ -1003,11 +984,8 @@ class PluginManager(object):
try:
if entry.is_dir():
init_py = os.path.join(entry.path, "__init__.py")
init_pyc = os.path.join(entry.path, "__init__.pyc")
if not os.path.isfile(init_py) and not os.path.isfile(
init_pyc
):
if not os.path.isfile(init_py):
# neither does exist, we ignore this
continue
@@ -1015,8 +993,8 @@ class PluginManager(object):
elif entry.is_file():
key, ext = os.path.splitext(entry.name)
if ext not in (".py", ".pyc") or key.startswith("__"):
# neither py nor pyc, or starts with __ (like __init__), we ignore this
if ext not in (".py",) or key.startswith("__"):
# not py, or starts with __ (like __init__), we ignore this
continue
else:
+11 -12
View File
@@ -104,10 +104,10 @@ class PluginTestCase(unittest.TestCase):
assert "__plugin_implementation__" in str(w[-1].message)
def test_plugin_loading(self):
self.assertEqual(9, len(self.plugin_manager.enabled_plugins))
self.assertEqual(10, len(self.plugin_manager.plugins))
self.assertEqual(7, len(self.plugin_manager.enabled_plugins))
self.assertEqual(8, len(self.plugin_manager.plugins))
self.assertEqual(2, len(self.plugin_manager.plugin_hooks))
self.assertEqual(5, len(self.plugin_manager.plugin_implementations))
self.assertEqual(4, len(self.plugin_manager.plugin_implementations))
self.assertEqual(3, len(self.plugin_manager.plugin_implementations_by_type))
# hook_plugin
@@ -156,7 +156,7 @@ class PluginTestCase(unittest.TestCase):
in self.plugin_manager.plugin_implementations_by_type
)
self.assertEqual(
2,
1,
len(
self.plugin_manager.plugin_implementations_by_type[
octoprint.plugin.AssetPlugin
@@ -180,7 +180,7 @@ class PluginTestCase(unittest.TestCase):
)
all_implementations = self.plugin_manager.plugin_implementations
self.assertEqual(5, len(all_implementations))
self.assertEqual(4, len(all_implementations))
for name, impl in all_implementations.items():
self.assertTrue(name in self.plugin_manager.enabled_plugins)
plugin = self.plugin_manager.enabled_plugins[name]
@@ -271,7 +271,7 @@ class PluginTestCase(unittest.TestCase):
octoprint.plugin.AssetPlugin
)
self.assertListEqual(
["asset_plugin", "asset_plugin_2"],
["asset_plugin"],
list(map(lambda x: x._identifier, implementations)),
)
@@ -320,13 +320,12 @@ class PluginTestCase(unittest.TestCase):
client2.on_plugin_message.assert_called_once_with(plugin, data, permissions=None)
def test_broken_plugin(self):
for key in ("not_a_plugin",):
self.assertTrue(key in self.plugin_manager.plugins)
self.assertTrue("not_a_plugin" in self.plugin_manager.plugins)
plugin = self.plugin_manager.plugins[key]
self.assertFalse(plugin.looks_like_plugin)
self.assertFalse(plugin.loaded)
self.assertFalse(plugin.enabled)
plugin = self.plugin_manager.plugins["not_a_plugin"]
self.assertFalse(plugin.looks_like_plugin)
self.assertFalse(plugin.loaded)
self.assertFalse(plugin.enabled)
@ddt.data(
(