-
Notifications
You must be signed in to change notification settings - Fork 49
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
Initial commit for plugin internals refactor #763
base: main
Are you sure you want to change the base?
Conversation
bfa1029
to
f4c1af4
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #763 +/- ##
==========================================
- Coverage 75.51% 75.50% -0.02%
==========================================
Files 305 305
Lines 26348 26295 -53
==========================================
- Hits 19897 19853 -44
+ Misses 6451 6442 -9
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
68299b4
to
84e83ea
Compare
2192994
to
85f4ebc
Compare
85f4ebc
to
43b0585
Compare
43b0585
to
e830c4e
Compare
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 noticed plugins/general/example.py
and plugins/os/unix/packagemanager.py
still have a __findable__
property, which is now no longer needed.
Another thing I noticed is that the -l
no longer lists the plugins from _os.py
.
And a third thing I noticed that if I run a namespace plugin, e.g. webserver.access, which is listed when doing target-query MyTarget -l
, before it printed an error like:
Error while parsing sysvol/windows/system32/inetsrv/config/applicationHost.config: ...
but now it errors with:
target-query: error: argument -f/--function contains invalid plugin(s): webserver.access
arglist = getattr(obj, "__args__", []) | ||
arglist.append((args, kwargs)) |
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.
arglist = getattr(obj, "__args__", []) | |
arglist.append((args, kwargs)) | |
obj.__args__.append((args, kwargs)) |
This can be simplified similar as in alias()
@@ -182,7 +293,6 @@ class attribute. Namespacing results in your plugin needing to be prefixed | |||
|
|||
With the following three being assigned in :func:`register`: |
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.
With the following three being assigned in :func:`register`: | |
With the following two being assigned in :func:`register`: |
The hostname as string. | ||
""" | ||
raise NotImplementedError | ||
members: dict[str, list] = function_index.setdefault(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.
members: dict[str, list] = function_index.setdefault(name, {}) | |
members: dict[str, FunctionDescriptor] = function_index.setdefault(name, {}) |
# Function descriptor lookup | ||
# {"<function_name>": {"<module_path>": FunctionDescriptor}} | ||
"__functions__": {}, |
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.
From the code it looks like this has the same None
/__os__
/__child__
subdivision as the __plugins__
key.
DefaultPlugin, then plugins are returned as if no ``osfilter`` was | ||
specified. | ||
registry = _get_plugins() | ||
__functions__: dict[str, dict[str, FunctionDescriptor]] = registry.get("__functions__", {}) |
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.
__functions__: dict[str, dict[str, FunctionDescriptor]] = registry.get("__functions__", {}) | |
__functions__: dict[str, dict[str, dict[str, FunctionDescriptor]]] = registry.get("__functions__", {}) |
There is an other None
/ __os__
/ __child__
level
"""Retrieve all child plugin descriptors.""" | ||
yield from plugins(special_keys={"_child"}, only_special_keys=True) | ||
# Skip plugins that don't want to be found by wildcards | ||
if not descriptor or not descriptor.exported or (not show_hidden and not descriptor.findable): |
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.
if not descriptor or not descriptor.exported or (not show_hidden and not descriptor.findable): | |
if not descriptor.exported or (not show_hidden and not descriptor.findable): |
I don't think it is possible for _generate_long_paths()
to give back an entry without a descriptor.
def _generate_long_paths() -> dict[str, FunctionDescriptor]: | ||
"""Generate a dictionary of all long paths to their function descriptors.""" | ||
paths = {} | ||
for value in _get_plugins().get("__functions__", {}).get(None, {}).values(): |
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.
Shouldn't the functions for __os__
not also be added? Otherwise they will not be found by a non-exact match in find_plugin_functions()
.
result = [] | ||
seen = set() | ||
for descriptor in descriptors: | ||
print(descriptor) |
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.
print(descriptor) |
debug left over
return list(descriptors) | ||
|
||
|
||
# Class for specific types of plugins |
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.
# Class for specific types of plugins | |
# Classes for specific types of plugins |
@@ -265,7 +326,7 @@ def test_incompatible_plugin(target_bare: Target) -> None: | |||
target_bare.add_plugin(_TestIncompatiblePlugin) | |||
|
|||
|
|||
MOCK_PLUGINS = { | |||
MOCK_PLUGINS_OLD = { |
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.
As this is no longer used, it can be removed I think?
Initial commit for the plugin internals refactor. This removes a lot of slow and hard to understand code with (hopefully) faster and easier to understand code. Also fixes some consistency issues I came across while working on this.
There are some things I want to add, but I may do those in a separate PR:
_os.py
, but then_plugin.py
or something similar (Add support for plugin directories #788)path
field, for example.This should also cover #759.
Closes #889.