Skip to content
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

Add initialization hook to plugin system #318

Open
wants to merge 54 commits into
base: main
Choose a base branch
from
Open

Conversation

willis89pr
Copy link
Collaborator

Summary

This change improves resource management and prepares the system for future enhancements that require plugin-specific setup.

Proposed changes

  • Introduced a new init_hook in hookspecs.py to allow plugins to perform initialization tasks, such as loading databases or setting up resources.
  • Implemented the init_hook in the js_file plugin to load the JavaScript library database during initialization.
  • Updated the plugin manager to call the init_hook using a helper function, ensuring plugins are initialized based on the command context.
  • Enhanced modularity and efficiency of the plugin system by allowing conditional initialization.

willis89pr and others added 30 commits November 4, 2024 20:15
Simpler string formatting.

Co-authored-by: Ryan Mast <[email protected]>
Fixed typo.

Co-authored-by: Ryan Mast <[email protected]>
pre-commit-ci bot and others added 11 commits November 12, 2024 17:28
- Introduced a new  in  to allow plugins to perform initialization tasks, such as loading databases or setting up resources.
- Implemented the  in the  plugin to load the JavaScript library database during initialization.
- Updated the plugin manager to call the  using a helper function, ensuring plugins are initialized based on the command context.
- Enhanced modularity and efficiency of the plugin system by allowing conditional initialization.

This change improves resource management and prepares the system for future enhancements that require plugin-specific setup.
@willis89pr willis89pr requested a review from nightlark January 7, 2025 21:58
pre-commit-ci bot and others added 10 commits January 7, 2025 21:59
- Introduced JSDatabaseManager class to manage the JavaScript library database.
- Removed the use of the global statement for js_lib_database to address pylint warning W0603.
- Updated functions to access the database through the JSDatabaseManager instance.
- Improved code organization and maintainability by encapsulating database logic within a class.
if hook_filter:
if not any(is_hook_implemented(pm, plugin, hook) for hook in hook_filter):
continue
plugin.init_hook(command_name=command_name)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably okay to fallback to initializing everything if no hook_filter is provided -- it will just likely be more things happening than needed if we ever leave it unset (probably only a very limited number of external users would be interested in this function, maybe pEyeOn or similar that tries to use some of our plugins).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't that make the use of hook_filter non-functional?

Copy link
Collaborator

@nightlark nightlark Jan 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Falling back to initializing everything that has an init_hook if hook_filter==None (or hook_filter==[]) is the current behavior. If hook_filter is a non-empty list then the continue statement and check on line 209 looks like it should be working as expected.

If you meant for hook_filter=None to not call any init_hook functions then the call to init_hook on line 211 should be indented one more level.

surfactant/infoextractors/js_file.py Outdated Show resolved Hide resolved
willis89pr and others added 2 commits January 8, 2025 12:29
changed click.echo to logger.info/error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants