def meldloop(root: Path, filename: Path, language: str=None, exe: str=EXE, strict: bool=False, fast: bool=False): assert root.is_dir(), f'{root} is not a directory' assert filename.is_file() flist = list(root.rglob(filename.name)) si = 1 if strict else 2 if not fast and language is None: language = ghl.linguist(filename.parent, rtype=True) print(f'comparing {len(flist)} files vs {filename} {language}') # Not using check_call due to spurious errors for f in flist: if filecmp.cmp(f, filename, shallow=False): print(f'SAME: {f.parent}') continue if not fast and ghl is not None: langlist = ghl.linguist(f.parent) if langlist is None: logging.warning(f'SKIP: {f.parent}') continue thislangs = [l[0] for l in langlist[:si]] if language not in thislangs: print(f'SKIP: {f.parent} {thislangs}') continue subprocess.run([exe, str(filename), str(f)])
def main(): p = ArgumentParser() p.add_argument("path", help="path to examine with GitHub Linguist", nargs="?", default=".") p.add_argument("-t", "--type", help="print only detected repo type (as GitHub would declare)", action="store_true") p = p.parse_args() langs = ghl.linguist(p.path, rtype=p.type) if isinstance(langs, str): print(langs) elif isinstance(langs, list): for l in langs: print(f"{l[0]} {l[1]}%")
def test_norepo(tmpdir): assert ghl.linguist(tmpdir.mkdir("empty")) is None
def test_linguist(): langs = ghl.linguist(R) assert langs[0][0] == "Python"
def test_type(): assert ghl.linguist(R, rtype=True) == "Python"