radn-dev/xmetrics/common.py

24 lines
693 B
Python

import os
from collections import Counter
from functools import lru_cache
from pathlib import Path
from subprocess import check_output
@lru_cache()
def _counter(commit: str, unique: bool) -> Counter:
check_output(["git", "checkout", commit], text=True)
ctr = Counter()
for path in Path(os.getenv("SRCDIR", "src")).rglob(os.getenv("SRCPATTERN", "*.rs")):
lines = path.read_bytes().splitlines()
lines = (line.strip() for line in lines)
lines = (line for line in lines if line)
if unique:
lines = set(lines)
ctr.update(lines)
return ctr
def counter(commit: str, unique: bool) -> Counter:
return _counter(commit, unique)