You can extend diff-quality by creating a plugin using the pluggy package.
1. Define the Entry Point
In your plugin's setup.py, define a diff_cover entry point. The key must be diff_cover and the value must follow the format TOOL_NAME = YOUR_PACKAGE.PLUGIN_MODULE.
setup(
...
entry_points={
'diff_cover': [
'sqlfluff = sqlfluff.diff_quality_plugin'
],
},
...
)
2. Implement the Plugin
Your module must contain a function named diff_cover_report_quality decorated with @diff_cover_hookimpl. This function must return an object (typically a subclass of BaseViolationReporter) that implements:
supported_extensions: A list of file extensions (e.g., ['sql']).violations(src_path): Returns a list of Violation objects.measured_lines(src_path): (Optional) Returns line information.installed(): A static method returning True.
3. Usage
Once installed, you can run the tool using the name defined in your entry point:
diff-quality --violations sqlfluff
from diff_cover.hook import hookimpl as diff_cover_hookimpl
from diff_cover.violationsreporters.base import BaseViolationReporter, Violation
class SQLFluffViolationReporter(BaseViolationReporter):
supported_extensions = ['sql']
def __init__(self):
super(SQLFluffViolationReporter, self).__init__('sqlfluff')
def violations(self, src_path):
return [
Violation(violation.line_number, violation.description)
for violation in get_linter().get_violations(src_path)
]
def measured_lines(self, src_path):
return None
@staticmethod
def installed():
return True
@diff_cover_hookimpl
def diff_cover_report_quality():
return SQLFluffViolationReporter()