Ejemplo n.º 1
0
 async def analyze(self, tup: NativeTreeMetricInput) -> Iterable[Metric]:
     rate: Dict[str, Dict[bool, int]] = {
         "blobs": {
             True: 0,
             False: 0
         },
         "trees": {
             True: 0,
             False: 0
         },
         "other": {
             True: 0,
             False: 0
         },
     }
     q: List[Object] = [tup.tree]
     while q:
         obj = q.pop(0)
         is_cached = obj.id in self.cache
         if isinstance(obj, Tree):
             q.extend(list(obj))
             rate["trees"][is_cached] += 1
         elif isinstance(obj, Blob):
             rate["blobs"][is_cached] += 1
         else:
             rate["other"][is_cached] += 1
         self.cache.add(obj.id)
     return [Metric(self.name, rate, False)]
Ejemplo n.º 2
0
 async def cache_hit(self, tup: NativeBlobMetricInput) -> Iterable[Metric]:
     return [
         Metric(
             self.name,
             None,
             True,
             ObjectIdentifier(tup.blob.id, tup.path),
         )
     ]
Ejemplo n.º 3
0
 async def analyze(self, tup: NativeTreeMetricInput) -> Iterable[Metric]:
     n = 0
     q: List[Object] = [tup.tree]
     while q:
         obj = q.pop(0)
         if isinstance(obj, Blob):
             n += 1
         elif isinstance(obj, Tree):
             q.extend(list(obj))
     return [Metric(self.name, n, False)]
Ejemplo n.º 4
0
 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
Ejemplo n.º 5
0
 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
Ejemplo n.º 6
0
 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
Ejemplo n.º 7
0
 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
Ejemplo n.º 8
0
 async def analyze(self, tup: NativeTreeMetricInput) -> Iterable[Metric]:
     n = 0
     q: List[Object] = [tup.tree]
     while q:
         obj = q.pop(0)
         if isinstance(obj, Blob):
             if obj.is_binary:
                 continue
             n += obj.data.count(b"\n") + 1
         elif isinstance(obj, Tree):
             q.extend(list(obj))
     return [Metric(self.name, n, False)]
Ejemplo n.º 9
0
 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
Ejemplo n.º 10
0
 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
Ejemplo n.º 11
0
 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
Ejemplo n.º 12
0
 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
Ejemplo n.º 13
0
 async def analyze(self, tup: DirMetricInput) -> Iterable[Metric]:
     p = await create_subprocess_exec("tokei",
                                      "--output",
                                      "json",
                                      tup.path,
                                      stdout=PIPE)
     stdout, _ = await p.communicate()
     data = loads(bytes(stdout).decode("utf-8"))
     result = [
         Metric(
             self.name,
             {
                 "category": category_name,
                 "blanks": report["stats"]["blanks"],
                 "code": report["stats"]["code"],
                 "comments": report["stats"]["comments"],
             },
             False,
             ObjectIdentifier(
                 descend_tree(tup.tree, report["name"][len(tup.path) + 1:]),
                 report["name"][len(tup.path) + 1:],
             ),
         ) for category_name, reports in data["Total"]["children"].items()
         for report in reports
     ]
     result.append(
         Metric(
             self.name,
             {
                 "blanks": data["Total"]["blanks"],
                 "code": data["Total"]["code"],
                 "comments": data["Total"]["comments"],
             },
             False,
         ))
     return result
Ejemplo n.º 14
0
    async def analyze(self, tup: NativeTreeMetricInput) -> Iterable[Metric]:
        parent_trees = tuple(parent.tree.obj for parent in tup.commit.parents)
        if not parent_trees:  # orphan commit is diffed to empty tree
            diffs = [tup.tree.obj.diff_to_tree(swap=True)]

        else:
            diffs = [
                tup.tree.obj.diff_to_tree(parent_tree, swap=True)
                for parent_tree in parent_trees
            ]
        touched_lines = [
            line.content for diff in diffs for patch in diff
            for hunk in patch.hunks for line in hunk.lines
            if line.content_offset > -1
        ]
        return [Metric(self.name, touched_lines, False)]