-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
478 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
AnalyzerManager | ||
=========================================== | ||
|
||
|
||
.. autodata:: duetector.managers.analyzer.PROJECT_NAME | ||
.. autofunction:: duetector.managers.analyzer.init_analyzer | ||
|
||
|
||
.. autoclass:: duetector.managers.analyzer.AnalyzerManager | ||
:members: | ||
:undoc-members: | ||
:inherited-members: | ||
:show-inheritance: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Expose for plugin system | ||
from . import db | ||
|
||
registers = [db] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import pluggy | ||
|
||
project_name = "duetector.analyzer" | ||
hookimpl = pluggy.HookimplMarker(project_name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +0,0 @@ | ||
from .base import Manager | ||
from .collector import CollectorManager | ||
from .filter import FilterManager | ||
from .tracer import TracerManager | ||
|
||
__all__ = ["Manager", "CollectorManager", "FilterManager", "TracerManager"] | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import sys | ||
from typing import Any, Dict, List, Optional | ||
|
||
import pluggy | ||
|
||
import duetector.analyzer.register | ||
from duetector.analyzer.base import Analyzer | ||
from duetector.extension.analyzer import project_name | ||
from duetector.log import logger | ||
from duetector.managers.base import Manager | ||
|
||
PROJECT_NAME = project_name #: Default project name for pluggy | ||
hookspec = pluggy.HookspecMarker(PROJECT_NAME) | ||
|
||
|
||
@hookspec | ||
def init_analyzer(config) -> Optional[Analyzer]: | ||
""" | ||
Initialize analyzer from config | ||
None means the analyzer is not available | ||
Also the analyzer can be disabled by config, Manager will discard disabled analyzer | ||
""" | ||
|
||
|
||
class AnalyzerManager(Manager): | ||
""" | ||
Manager for all analyzers. | ||
Analyzers are initialized from config, and can be ``disabled`` by config. | ||
""" | ||
|
||
config_scope = "analyzer" | ||
""" | ||
Config scope for ``AnalyzerManager``. | ||
""" | ||
|
||
def __init__(self, config: Optional[Dict[str, Any]] = None, *args, **kwargs): | ||
super().__init__(config, *args, **kwargs) | ||
|
||
self.pm = pluggy.PluginManager(PROJECT_NAME) | ||
self.pm.add_hookspecs(sys.modules[__name__]) | ||
self.pm.load_setuptools_entrypoints(PROJECT_NAME) | ||
self.register(duetector.analyzer.register) | ||
|
||
def init(self, analyzer_type=Analyzer, ignore_disabled=True) -> List[Analyzer]: | ||
""" | ||
Initialize all analyzers from config. | ||
Args: | ||
analyzer_type: Only return analyzers of this type | ||
ignore_disabled: Ignore disabled analyzers | ||
""" | ||
if self.disabled: | ||
logger.info("AnalyzerManager disabled.") | ||
return [] | ||
|
||
objs = [] | ||
for f in self.pm.hook.init_analyzer(config=self.config._config_dict): | ||
if not f or (f.disabled and ignore_disabled): | ||
logger.debug(f"Analyzer {f.__class__.__name__} is not available (None or Disabled)") | ||
continue | ||
if not isinstance(f, analyzer_type): | ||
logger.debug( | ||
f"Skip Analyzer {f.__class__.__name__} (Not a instance of {analyzer_type})" | ||
) | ||
continue | ||
|
||
objs.append(f) | ||
|
||
return objs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.