Esempio n. 1
0
class Halstead(NativeBlobMetric):
    filter = NativeBlobFilter(NativeBlobFilter.endswith(".py"))

    async def analyze(self, tup: NativeBlobMetricInput) -> Iterable[Metric]:
        try:
            h_data = h_visit(tup.blob.data.decode())
        except (SyntaxError, UnicodeDecodeError):
            return []  # TODO get an error output?
        result = [
            Metric(
                self.name,
                fn_data._asdict(),
                False,
                ObjectIdentifier(tup.blob.id, tup.path),
                fn_name,
            )
            for fn_name, fn_data in h_data.functions
        ]
        result.append(
            Metric(
                self.name,
                h_data.total._asdict(),
                False,
                ObjectIdentifier(tup.blob.id, tup.path),
            )
        )
        return result
Esempio n. 2
0
class Nesting(NativeBlobMetric):
    filter = NativeBlobFilter(NativeBlobFilter.endswith(".py"))

    async def analyze(self, tup: NativeBlobMetricInput) -> Iterable[Metric]:
        result = [
            Metric(
                self.name,
                NestingASTVisitor().visit(parse(tup.blob.obj.data)).result,
                False,
                ObjectIdentifier(tup.blob.id, tup.path),
            )
        ]
        return result
Esempio n. 3
0
class Pylinecount(NativeBlobMetric):
    filter = NativeBlobFilter(NativeBlobFilter.is_binary())

    async def analyze(self, tup: NativeBlobMetricInput) -> Iterable[Metric]:
        result = [
            Metric(
                self.name,
                tup.blob.obj.data.count(b"\n") + 1,
                False,
                ObjectIdentifier(tup.blob.id, tup.path),
            )
        ]
        return result
Esempio n. 4
0
class Linelength(NativeBlobMetric):
    filter = NativeBlobFilter(NativeBlobFilter.is_binary())

    async def analyze(self, tup: NativeBlobMetricInput) -> Iterable[Metric]:
        result = [
            Metric(
                self.name,
                len(line),
                False,
                ObjectIdentifier(tup.blob.id, tup.path),
                f"L{i+1}",
            ) for i, line in enumerate(tup.blob.obj.data.split(b"\n"))
        ]
        return result
Esempio n. 5
0
class Linecount(NativeBlobMetric):
    filter = NativeBlobFilter(NativeBlobFilter.is_binary())

    async def analyze(self, tup: NativeBlobMetricInput) -> Iterable[Metric]:
        p = await create_subprocess_exec("wc", "-l", stdin=PIPE, stdout=PIPE)
        stdout, _ = await p.communicate(tup.blob.data)
        result = [
            Metric(
                self.name,
                int(stdout),
                False,
                ObjectIdentifier(tup.blob.id, tup.path),
            )
        ]
        return result
Esempio n. 6
0
class Raw(NativeBlobMetric):
    filter = NativeBlobFilter(NativeBlobFilter.endswith(".py"))

    async def analyze(self, tup: NativeBlobMetricInput) -> Iterable[Metric]:
        try:
            r_data = analyze(tup.blob.data.decode())
        except (SyntaxError, UnicodeDecodeError):
            return []  # TODO get an error output?
        result = [
            Metric(
                self.name,
                r_data._asdict(),
                False,
                ObjectIdentifier(tup.blob.id, tup.path),
            )
        ]
        return result
class Maintainability(NativeBlobMetric):
    filter = NativeBlobFilter(NativeBlobFilter.endswith(".py"))

    async def analyze(self, tup: NativeBlobMetricInput) -> Iterable[Metric]:
        try:
            mi_data = mi_visit(tup.blob.data.decode(), multi=True)
        except (SyntaxError, UnicodeDecodeError):
            return []  # TODO get an error output?
        result = [
            Metric(
                self.name,
                float(mi_data),
                False,
                ObjectIdentifier(tup.blob.id, tup.path),
            )
        ]
        return result
Esempio n. 8
0
class Complexity(NativeBlobMetric):
    filter = NativeBlobFilter(NativeBlobFilter.endswith(".py"))

    async def analyze(self, tup: NativeBlobMetricInput) -> Iterable[Metric]:
        try:
            cc_data = cc_visit(tup.blob.data)
        except (SyntaxError, UnicodeDecodeError):
            return []  # TODO get an error output?
        result = [
            Metric(
                self.name,
                subobject.complexity,
                False,
                ObjectIdentifier(tup.blob.id, tup.path),
                subobject.fullname,
            ) for subobject in cc_data
        ]
        return result