diff --git a/.appveyor.yml b/.appveyor.yml index 3745d7e..dc1edee 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -15,6 +15,6 @@ init: - cmd: set PATH=%PY_DIR%;%PY_DIR%\Scripts;%PATH% install: pip install -e .[tests] - + test_script: pytest -rsv diff --git a/meld_all.py b/meld_all.py new file mode 100644 index 0000000..00ad268 --- /dev/null +++ b/meld_all.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python +""" +useful for updating templates. + +e.g. + +meld_all .appveyor.yml + +meld_all .appveyor.yml -l Fortran +""" +from pathlib import Path +from argparse import ArgumentParser +import filecmp +import subprocess +try: + import ghlinguist as ghl + LANG = ghl.linguist(Path(__file__).parent, rtype=True) +except ImportError: + ghl = None + +EXE = 'meld' + + +def meldloop(root: Path, filename: Path, language: str=LANG, exe: str=EXE): + flist = list(root.rglob(filename.name)) + + print(f'comparing {len(flist)} files vs {filename}') + + # Not using check_call due to spurious errors + for f in flist: + if filecmp.cmp(f, filename, shallow=False): + continue + + if ghl is not None: + if ghl.linguist(f.parent, rtype=True) != language: + continue + + subprocess.run([exe, str(filename), str(f)]) + + +def main(): + p = ArgumentParser() + p.add_argument('filename', help='filename to compare against') + p.add_argument('root', help='top-level directory to search under', nargs='?') + p.add_argument('-l', '--language', help='language to template', default=LANG) + p.add_argument('-exe', help='program to compare with', default=EXE) + p = p.parse_args() + + fn = Path(p.filename).expanduser() + if not fn.is_file(): + raise FileNotFoundError(f'{fn} is not a file') + + root = fn.resolve().parents[1] if not p.root else Path(p.root).expanduser() + if not root.is_dir(): + raise FileNotFoundError(f'{root} is not a directory') + + meldloop(root, fn, p.language, p.exe) + + +if __name__ == '__main__': + main() diff --git a/setup.cfg b/setup.cfg index cedd205..6361f4f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -43,6 +43,8 @@ tests = mypy io = pycurl +meld = + ghlinguist [options.entry_points] console_scripts = @@ -54,6 +56,7 @@ console_scripts = findvid = findvid:main getIP = getIP:main memfree = memfree:main + meld_all = meld_all:main spellcheck = spellcheck:main tarcp = tarcp:main