How to use the wily.operators.BaseOperator function in wily

To help you get started, we’ve selected a few wily examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tonybaloney / wily / test / unit / test_build_unit.py View on Github external
return [
            Revision(
                key="12345",
                author_name="Local User",  # Don't want to leak local data
                author_email="-",  # as above
                date=12_345_679,
                message="None",
                files=[],
            )
        ]

    def checkout(self, revision, options):
        pass  # noop


class MockOperatorCls(BaseOperator):
    name = "test"
    data = {}

    def __init__(self, *args, **kwargs):
        pass

    def run(self, module, options):
        return self.data


MockOperator = Operator("mock", MockOperatorCls, "for testing", OperatorLevel.File)

MockArchiver = Archiver("mock", MockArchiverCls, "for testing")


@pytest.fixture
github tonybaloney / wily / src / wily / operators / halstead.py View on Github external
"""
Halstead operator.

Measures all of the halstead metrics (volume, vocab, difficulty)
"""
import radon.cli.harvest as harvesters
from radon.cli import Config

from wily import logger
from wily.operators import BaseOperator, MetricType, Metric


class HalsteadOperator(BaseOperator):
    """Halstead Operator."""

    name = "halstead"
    defaults = {
        "exclude": None,
        "ignore": None,
        "min": "A",
        "max": "C",
        "multi": True,
        "show": False,
        "sort": False,
        "by_function": True,
        "include_ipynb": True,
        "ipynb_cells": True,
    }
github tonybaloney / wily / src / wily / operators / maintainability.py View on Github external
from wily import logger
from wily.operators import BaseOperator, MetricType, Metric


def mode(data):
    """
    Return the modal value of a iterable with discrete values.
    
    If there is more than 1 modal value, arbritrarily return the first top n.
    """
    c = Counter(data)
    mode, freq = c.most_common(1)[0]
    return mode


class MaintainabilityIndexOperator(BaseOperator):
    """MI Operator."""

    name = "maintainability"
    defaults = {
        "exclude": None,
        "ignore": None,
        "min": "A",
        "max": "C",
        "multi": True,
        "show": False,
        "sort": False,
        "include_ipynb": True,
        "ipynb_cells": True,
    }

    metrics = (
github tonybaloney / wily / src / wily / operators / cyclomatic.py View on Github external
Cyclomatic complexity metric for each function/method.

Provided by the radon library.
"""
import statistics

import radon
import radon.cli.harvest as harvesters
from radon.cli import Config
from radon.visitors import Function, Class

from wily import logger
from wily.operators import BaseOperator, Metric, MetricType


class CyclomaticComplexityOperator(BaseOperator):
    """Cyclomatic complexity operator."""

    name = "cyclomatic"
    defaults = {
        "exclude": None,
        "ignore": None,
        "min": "A",
        "max": "F",
        "no_assert": True,
        "show_closures": False,
        "order": radon.complexity.SCORE,
        "include_ipynb": True,
        "ipynb_cells": True,
    }

    metrics = (
github tonybaloney / wily / src / wily / operators / raw.py View on Github external
"""
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.operators import BaseOperator, MetricType, Metric


class RawMetricsOperator(BaseOperator):
    """Raw Metrics Operator."""

    name = "raw"
    defaults = {
        "exclude": None,
        "ignore": None,
        "summary": False,
        "include_ipynb": True,
        "ipynb_cells": True,
    }
    metrics = (
        Metric("loc", "Lines of Code", int, MetricType.Informational, sum),
        Metric("lloc", "L Lines of Code", int, MetricType.AimLow, sum),
        Metric("sloc", "S Lines of Code", int, MetricType.AimLow, sum),
        Metric("comments", "Multi-line comments", int, MetricType.AimHigh, sum),
        Metric("multi", "Multi lines", int, MetricType.Informational, sum),
github tonybaloney / wily / wily / operators / mccabe.py View on Github external
from wily.operators import BaseOperator


class MccabeOperator(BaseOperator):
    name = "mccabe"

    def __init__(self, config):
        pass