src\wily\operators\raw.py
-- -- --- --- --- --- --- --- ------- ------- ------- | """
-- -- --- --- --- --- --- --- ------- ------- ------- | Raw statistics operator.
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- | Includes insights like lines-of-code, number of comments. Does not measure complexity.
-- -- --- --- --- --- --- --- ------- ------- ------- | """
-- -- --- --- --- --- --- --- ------- ------- ------- | import radon.cli.harvest as harvesters
-- -- --- --- --- --- --- --- ------- ------- ------- | from radon.cli import Config
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- | from wily import logger
-- -- --- --- --- --- --- --- ------- ------- ------- | from wily.lang import _
-- -- --- --- --- --- --- --- ------- ------- ------- | from wily.operators import BaseOperator, Metric, MetricType
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
03 -- --- --- --- --- --- --- ------- ------- ------- | class RawMetricsOperator(BaseOperator):
03 -- --- --- --- --- --- --- ------- ------- ------- | """Raw Metrics Operator."""
03 -- --- --- --- --- --- --- ------- ------- ------- |
03 -- --- --- --- --- --- --- ------- ------- ------- | name = "raw"
03 -- --- --- --- --- --- --- ------- ------- ------- | defaults = {
03 -- --- --- --- --- --- --- ------- ------- ------- | "exclude": None,
03 -- --- --- --- --- --- --- ------- ------- ------- | "ignore": None,
03 -- --- --- --- --- --- --- ------- ------- ------- | "summary": False,
03 -- --- --- --- --- --- --- ------- ------- ------- | "include_ipynb": True,
03 -- --- --- --- --- --- --- ------- ------- ------- | "ipynb_cells": True,
03 -- --- --- --- --- --- --- ------- ------- ------- | }
03 -- --- --- --- --- --- --- ------- ------- ------- | metrics = (
03 -- --- --- --- --- --- --- ------- ------- ------- | Metric("loc", _("Lines of Code"), int, MetricType.Informational, sum),
03 -- --- --- --- --- --- --- ------- ------- ------- | Metric("lloc", _("L Lines of Code"), int, MetricType.AimLow, sum),
03 -- --- --- --- --- --- --- ------- ------- ------- | Metric("sloc", _("S Lines of Code"), int, MetricType.AimLow, sum),
03 -- --- --- --- --- --- --- ------- ------- ------- | Metric("comments", _("Multi-line comments"), int, MetricType.AimHigh, sum),
03 -- --- --- --- --- --- --- ------- ------- ------- | Metric("multi", _("Multi lines"), int, MetricType.Informational, sum),
03 -- --- --- --- --- --- --- ------- ------- ------- | Metric("blank", _("blank lines"), int, MetricType.Informational, sum),
03 -- --- --- --- --- --- --- ------- ------- ------- | Metric(
03 -- --- --- --- --- --- --- ------- ------- ------- | "single_comments",
03 -- --- --- --- --- --- --- ------- ------- ------- | _("Single comment lines"),
03 -- --- --- --- --- --- --- ------- ------- ------- | int,
03 -- --- --- --- --- --- --- ------- ------- ------- | MetricType.Informational,
03 -- --- --- --- --- --- --- ------- ------- ------- | sum,
03 -- --- --- --- --- --- --- ------- ------- ------- | ),
03 -- --- --- --- --- --- --- ------- ------- ------- | )
03 -- --- --- --- --- --- --- ------- ------- ------- | default_metric_index = 0 # LOC
03 -- --- --- --- --- --- --- ------- ------- ------- |
03 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | def __init__(self, config, targets):
03 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | """
03 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | Instantiate a new raw operator.
03 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
03 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | :param config: The wily configuration.
03 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | :type config: :class:`WilyConfig`
03 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | """
03 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | # TODO: Use config from wily.cfg for harvester
03 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | logger.debug(f"Using {targets} with {self.defaults} for Raw metrics")
03 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | self.harvester = harvesters.RawHarvester(
03 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | targets, config=Config(**self.defaults)
03 -- 000 000 000 000 000 000 0000.00 0000.00 0000.00 | )
03 -- --- --- --- --- --- --- ------- ------- ------- |
03 02 000 000 000 000 000 000 0000.00 0000.00 0000.00 | def run(self, module, options):
03 02 000 000 000 000 000 000 0000.00 0000.00 0000.00 | """
03 02 000 000 000 000 000 000 0000.00 0000.00 0000.00 | Run the operator.
03 02 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
03 02 000 000 000 000 000 000 0000.00 0000.00 0000.00 | :param module: The target module path.
03 02 000 000 000 000 000 000 0000.00 0000.00 0000.00 | :type module: ``str``
03 02 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
03 02 000 000 000 000 000 000 0000.00 0000.00 0000.00 | :param options: Any runtime options.
03 02 000 000 000 000 000 000 0000.00 0000.00 0000.00 | :type options: ``dict``
03 02 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
03 02 000 000 000 000 000 000 0000.00 0000.00 0000.00 | :return: The operator results.
03 02 000 000 000 000 000 000 0000.00 0000.00 0000.00 | :rtype: ``dict``
03 02 000 000 000 000 000 000 0000.00 0000.00 0000.00 | """
03 02 000 000 000 000 000 000 0000.00 0000.00 0000.00 | logger.debug("Running raw harvester")
03 02 000 000 000 000 000 000 0000.00 0000.00 0000.00 | results = {}
03 02 000 000 000 000 000 000 0000.00 0000.00 0000.00 | for filename, metrics in dict(self.harvester.results).items():
03 02 000 000 000 000 000 000 0000.00 0000.00 0000.00 | results[filename] = {"total": metrics}
03 02 000 000 000 000 000 000 0000.00 0000.00 0000.00 | return results