-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
117 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
[run] | ||
cover_pylib = false | ||
omit = | ||
/home/travis/virtualenv/* | ||
*/site-packages/* | ||
*/bin/* | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,4 @@ | ||
#!/usr/bin/env python | ||
import setuptools | ||
import sys | ||
|
||
if sys.version_info < (3, 6): | ||
raise SystemExit("Python >= 3.6 required") | ||
|
||
setuptools.setup() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
from .base import files_to_meld, meld_files | ||
from .base import files_to_diff, diff_gui |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,66 @@ | ||
import typing | ||
import typing as T | ||
from pathlib import Path | ||
import shutil | ||
import subprocess | ||
import logging | ||
import filecmp | ||
import os | ||
|
||
try: | ||
import ghlinguist as ghl | ||
except (ImportError, FileNotFoundError): | ||
ghl = None | ||
__all__ = ["files_to_diff", "diff_gui"] | ||
|
||
|
||
def files_to_meld(root: Path, ref: Path, language: str = None, strict: bool = False) -> typing.Iterator[Path]: | ||
|
||
si = 1 if strict else 2 | ||
def files_to_diff(root: Path, ref: Path) -> T.Iterator[Path]: | ||
""" | ||
Yield filenames that match criteria (same filename but different contents). | ||
""" | ||
|
||
ref = Path(ref).expanduser() | ||
ref = Path(ref).expanduser().resolve() | ||
if not ref.is_file(): | ||
raise FileNotFoundError(f"specify a reference file, not a directory {ref}") | ||
|
||
root = Path(root).expanduser() | ||
root = Path(root).expanduser().resolve() | ||
if not root.is_dir(): | ||
raise NotADirectoryError(f"{root} is not a directory") | ||
|
||
for new in root.rglob(ref.name): | ||
if new.samefile(ref): | ||
continue | ||
|
||
if filecmp.cmp(new, ref, shallow=False): # type: ignore # mypy .pyi needs updating | ||
if filecmp.cmp(new, ref, shallow=False): # type: ignore # MyPy .pyi incorrect | ||
logging.info(f"SAME: {new.parent}") | ||
continue | ||
|
||
if language and ghl is not None: | ||
langlist = ghl.linguist(new.parent) | ||
if langlist is None: | ||
logging.info(f"SKIP: {new.parent}") | ||
continue | ||
|
||
thislangs = [lang[0] for lang in langlist[:si]] | ||
if language not in thislangs: | ||
logging.info(f"SKIP: {new.parent} {thislangs}") | ||
continue | ||
|
||
yield new | ||
|
||
|
||
def meld_files(ref: Path, new: Path, rexe: str): | ||
def diff_gui(ref: Path, new: Path, exe: str = None) -> None: | ||
""" | ||
run file comparison program (often meld) on file pair | ||
run file comparison GUI on file pair | ||
Not using check_call due to spurious errors | ||
""" | ||
|
||
exe = shutil.which(rexe) | ||
diff_cli = "FC.exe" if os.name == "nt" else "diff" | ||
|
||
if not exe: | ||
for e in ("meld", "code", diff_cli): | ||
exe = shutil.which(e) | ||
if exe: | ||
break | ||
|
||
exe = shutil.which(exe) | ||
if not exe: | ||
raise FileNotFoundError(f"{rexe} not found. Try -n option to just see which files differ.") | ||
# Not using check_call due to spurious errors | ||
new = Path(new).expanduser() | ||
ref = Path(ref).expanduser() | ||
subprocess.run([exe, str(ref), str(new)]) | ||
raise FileNotFoundError("diff GUI not found. Try -n option to just see which files differ.") | ||
|
||
new = Path(new).expanduser().resolve() | ||
ref = Path(ref).expanduser().resolve() | ||
|
||
if "code" in Path(exe).name.lower(): | ||
cmd = [exe, "--wait", "--diff", str(ref), str(new)] | ||
else: | ||
# assuming just the plain executable name without options | ||
# this is how "meld" works | ||
cmd = [exe, str(ref), str(new)] | ||
|
||
logging.info(cmd) | ||
subprocess.run(cmd) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import pytest | ||
from pathlib import Path | ||
|
||
|
||
@pytest.fixture | ||
def gen_file(tmp_path): | ||
f1 = tmp_path / "a/hi.txt" | ||
f2 = tmp_path / "b/hi.txt" | ||
|
||
make_file(f1) | ||
make_file(f2) | ||
|
||
return f1, f2 | ||
|
||
|
||
def make_file(path: Path): | ||
path.parent.mkdir(exist_ok=True, parents=True) | ||
path.write_text("hello") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/usr/bin/env python | ||
import pytest | ||
import os | ||
|
||
import meldutils as mu | ||
|
||
|
||
def test_find(gen_file): | ||
f1, f2 = gen_file | ||
|
||
files = list(mu.files_to_diff(f1.parents[1], f1)) | ||
|
||
assert len(files) == 0 | ||
|
||
# add a whitespace to one file to make the file slightly different than the other file | ||
with f2.open("a") as f: | ||
f.write(" ") | ||
|
||
files = list(mu.files_to_diff(f1.parents[1], f1)) | ||
|
||
assert len(files) == 1 | ||
|
||
|
||
def test_diff(gen_file): | ||
""" | ||
show output of this test with | ||
pytest -s | ||
""" | ||
f1, f2 = gen_file | ||
f2.write_text("hi") | ||
|
||
# this needs to be FC.exe in case run from PowerShell | ||
diff_cli = "FC.exe" if os.name == "nt" else "diff" | ||
|
||
mu.diff_gui(f1, f2, diff_cli) | ||
|
||
|
||
if __name__ == "__main__": | ||
pytest.main([__file__]) |
This file was deleted.
Oops, something went wrong.