diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1da9e3a..0e359cd 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/psf/black - rev: 22.12.0 + rev: 23.3.0 hooks: - id: black args: [--safe, --quiet, --line-length=100] @@ -12,7 +12,7 @@ repos: - id: check-yaml - id: debug-statements - repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks - rev: v2.5.0 + rev: v2.8.0 hooks: - id: pretty-format-yaml args: [--autofix, --indent, '2', --preserve-quotes] @@ -40,7 +40,7 @@ repos: hooks: - id: setup-cfg-fmt - repo: https://github.com/tdegeus/conda_envfile - rev: v0.4.1 + rev: v0.4.2 hooks: - id: conda_envfile_parse files: environment.yaml diff --git a/shelephant/__init__.py b/shelephant/__init__.py index d3f0acb..58de1f8 100644 --- a/shelephant/__init__.py +++ b/shelephant/__init__.py @@ -76,7 +76,6 @@ def shelephant_diff(args: list[str]): remote = {"files": remote, "prefix": os.path.dirname(args.remote), "list": True} for field in [local, remote]: - if "host" in field: field["dirname"] = field["host"] + ":" + field["prefix"] else: @@ -119,9 +118,7 @@ def shelephant_diff(args: list[str]): for filename, value in zip( [args.get_new, args.get_diff, args.get_all], [ret["<-"], ret["!="], ret["<-"] + ret["!="]] ): - if filename is not None: - stop = True tmp = {"files": value} for key in ["host", "prefix"]: @@ -133,9 +130,7 @@ def shelephant_diff(args: list[str]): [args.send_new, args.send_diff, args.send_all], [ret["->"], ret["!="], ret["->"] + ret["!="]], ): - if filename is not None: - assert "host" not in local, "Not supported by shelephant_send." assert len(os.path.dirname(args.local)) == 0, "Not supported by shelephant_send." stop = True diff --git a/shelephant/checksum.py b/shelephant/checksum.py index 0ee1348..c203baf 100644 --- a/shelephant/checksum.py +++ b/shelephant/checksum.py @@ -58,7 +58,6 @@ def get(filepaths, yaml_hostinfo=None, hybrid=False, progress=False): # Compute if not yaml_hostinfo: - for i in tqdm.trange(n, disable=not progress, desc="Processing"): if os.path.isfile(filepaths[i]): ret[i] = sha256(filepaths[i]) diff --git a/shelephant/cli/shelephant_checksum.py b/shelephant/cli/shelephant_checksum.py index f0ad34d..4c22ab1 100644 --- a/shelephant/cli/shelephant_checksum.py +++ b/shelephant/cli/shelephant_checksum.py @@ -74,5 +74,4 @@ def main(): if __name__ == "__main__": - main() diff --git a/shelephant/cli/shelephant_cp.py b/shelephant/cli/shelephant_cp.py index b24267d..e9c4bcc 100644 --- a/shelephant/cli/shelephant_cp.py +++ b/shelephant/cli/shelephant_cp.py @@ -126,5 +126,4 @@ def main(): if __name__ == "__main__": - main() diff --git a/shelephant/cli/shelephant_dump.py b/shelephant/cli/shelephant_dump.py index 3d971c8..1fb98c5 100644 --- a/shelephant/cli/shelephant_dump.py +++ b/shelephant/cli/shelephant_dump.py @@ -114,5 +114,4 @@ def main(): if __name__ == "__main__": - main() diff --git a/shelephant/cli/shelephant_extract.py b/shelephant/cli/shelephant_extract.py index 0ff57db..0a81241 100644 --- a/shelephant/cli/shelephant_extract.py +++ b/shelephant/cli/shelephant_extract.py @@ -95,5 +95,4 @@ def main(): if __name__ == "__main__": - main() diff --git a/shelephant/cli/shelephant_get.py b/shelephant/cli/shelephant_get.py index 70c9fd1..4280d59 100644 --- a/shelephant/cli/shelephant_get.py +++ b/shelephant/cli/shelephant_get.py @@ -109,7 +109,6 @@ def print_help(self): data = yaml.read(source) if "host" not in data: - detail.copy( copy_function=shutil.copy2, files=data["files"], @@ -129,7 +128,6 @@ def print_help(self): ) elif args.scp: - detail.copy_ssh( copy_function=scp.from_remote, use_rsync=False, @@ -153,7 +151,6 @@ def print_help(self): ) else: - detail.copy_ssh( copy_function=rsync.from_remote, use_rsync=True, @@ -182,5 +179,4 @@ def main(): if __name__ == "__main__": - main() diff --git a/shelephant/cli/shelephant_hostinfo.py b/shelephant/cli/shelephant_hostinfo.py index ec221fd..87d7666 100644 --- a/shelephant/cli/shelephant_hostinfo.py +++ b/shelephant/cli/shelephant_hostinfo.py @@ -67,7 +67,6 @@ def remove(data, rm): - files = np.array(data["files"]) sorter = np.argsort(files) files = files[sorter] @@ -88,7 +87,6 @@ def remove(data, rm): def main_impl(): - # Parse command-line arguments class Parser(argparse.ArgumentParser): @@ -161,9 +159,7 @@ def print_help(self): args_dict = vars(args) for item in ["files", "checksum"]: - if args_dict[item]: - key = list(filter(None, args_dict[item + "_key"].split("/"))) filename = args_dict[item] @@ -206,5 +202,4 @@ def main(): if __name__ == "__main__": - main() diff --git a/shelephant/cli/shelephant_merge.py b/shelephant/cli/shelephant_merge.py index d82164f..c2a72d5 100644 --- a/shelephant/cli/shelephant_merge.py +++ b/shelephant/cli/shelephant_merge.py @@ -81,7 +81,6 @@ def print_help(self): output_dir = os.path.dirname(output) if not args.no_path: - paths = [os.path.dirname(args.main), os.path.dirname(args.branch)] for var, path in zip([main, branch], paths): @@ -94,7 +93,6 @@ def print_help(self): raise OSError("Files have an incompatible structure") if type(main) == list and type(branch) == list: - if args.skip: pass elif args.replace: @@ -103,7 +101,6 @@ def print_help(self): main += branch elif type(main) == dict and type(branch) == dict: - if args.skip: mergedeep.merge(branch, main, strategy=mergedeep.Strategy.REPLACE) main = branch @@ -113,7 +110,6 @@ def print_help(self): mergedeep.merge(main, branch, strategy=mergedeep.Strategy.ADDITIVE) else: - raise OSError("Files have an incompatible structure") yaml.dump(output, main, args.force) @@ -124,5 +120,4 @@ def main(): if __name__ == "__main__": - main() diff --git a/shelephant/cli/shelephant_mv.py b/shelephant/cli/shelephant_mv.py index 14ebcf1..7d143ce 100644 --- a/shelephant/cli/shelephant_mv.py +++ b/shelephant/cli/shelephant_mv.py @@ -103,5 +103,4 @@ def main(): if __name__ == "__main__": - main() diff --git a/shelephant/cli/shelephant_parse.py b/shelephant/cli/shelephant_parse.py index 1d85652..7483beb 100644 --- a/shelephant/cli/shelephant_parse.py +++ b/shelephant/cli/shelephant_parse.py @@ -43,5 +43,4 @@ def main(): if __name__ == "__main__": - main() diff --git a/shelephant/cli/shelephant_rm.py b/shelephant/cli/shelephant_rm.py index 7442629..1e4c6da 100644 --- a/shelephant/cli/shelephant_rm.py +++ b/shelephant/cli/shelephant_rm.py @@ -75,5 +75,4 @@ def main(): if __name__ == "__main__": - main() diff --git a/shelephant/cli/shelephant_send.py b/shelephant/cli/shelephant_send.py index 3a94d2f..d2695d5 100644 --- a/shelephant/cli/shelephant_send.py +++ b/shelephant/cli/shelephant_send.py @@ -122,7 +122,6 @@ def print_help(self): dest_dir = data["prefix"] if "host" not in data: - detail.copy( copy_function=shutil.copy2, files=files, @@ -141,7 +140,6 @@ def print_help(self): ) elif args.scp: - detail.copy_ssh( copy_function=scp.to_remote, use_rsync=False, @@ -164,7 +162,6 @@ def print_help(self): ) else: - detail.copy_ssh( copy_function=rsync.to_remote, use_rsync=True, @@ -192,5 +189,4 @@ def main(): if __name__ == "__main__": - main() diff --git a/shelephant/convert.py b/shelephant/convert.py index 5cd227d..c8fa0ab 100644 --- a/shelephant/convert.py +++ b/shelephant/convert.py @@ -41,7 +41,6 @@ def _squash_detail(data, parent_key="", sep="_"): items = [] for k, v in data.items(): - new_key = parent_key + sep + k if parent_key else k if isinstance(v, collections.abc.MutableMapping): diff --git a/shelephant/detail.py b/shelephant/detail.py index d9666f6..5f7944c 100644 --- a/shelephant/detail.py +++ b/shelephant/detail.py @@ -94,11 +94,9 @@ def copy( raise OSError(f'Input file "{file:s}" does not exists') if not os.path.isdir(dest_dir): - create = [True for i in range(n)] elif check_rsync: - tmp = diff( source_dir=src_dir, dest_dir=dest_dir, @@ -111,7 +109,6 @@ def copy( overwrite = tmp["overwrite"] else: - if checksum: src_checksums = get(src, yaml_hostinfo_src, progress=not quiet) dest_checksums = get(dest, yaml_hostinfo_dest, progress=not quiet) @@ -292,11 +289,9 @@ def copy_ssh( color = theme(theme_name.lower()) if not os.path.isdir(dest_dir) and not to_remote: - create = [True for i in range(n)] elif check_rsync: - tmp = diff( source_dir=src_dir if to_remote else host + ":" + src_dir, dest_dir=host + ":" + dest_dir if to_remote else dest_dir, @@ -310,7 +305,6 @@ def copy_ssh( overwrite = tmp["overwrite"] else: - if checksum is True: src_checksums = get(src, yaml_hostinfo_src, progress=not quiet) dest_checksums = get(dest, yaml_hostinfo_dest, progress=not quiet) diff --git a/shelephant/rich.py b/shelephant/rich.py index 1d5d828..d018b18 100644 --- a/shelephant/rich.py +++ b/shelephant/rich.py @@ -71,7 +71,6 @@ class String: """ def __init__(self, data, width=None, align="<", color=None, dummy=0): - self.data = data self.width = width self.color = color diff --git a/shelephant/rsync.py b/shelephant/rsync.py index dc14532..d4373b9 100644 --- a/shelephant/rsync.py +++ b/shelephant/rsync.py @@ -26,7 +26,6 @@ def _rsync(source_dir, dest_dir, files, verbose=False, progress=True): """ with tempfile.TemporaryDirectory() as temp_dir: - temp_file = os.path.join(temp_dir, "rsync.txt") with open(temp_file, "w") as file: @@ -35,7 +34,6 @@ def _rsync(source_dir, dest_dir, files, verbose=False, progress=True): # Run without printing output if not progress: - cmd = 'rsync -a --files-from="{files:s}" "{source_dir:s}" "{dest_dir:s}"'.format( source_dir=source_dir, dest_dir=dest_dir, files=temp_file ) @@ -141,7 +139,6 @@ def diff( """ with tempfile.TemporaryDirectory() as temp_dir: - temp_file = os.path.join(temp_dir, "rsync.txt") files = [os.path.normpath(file) for file in files] diff --git a/tests/ssh_generate.py b/tests/ssh_generate.py index 4f2a7b4..8ccd7dd 100644 --- a/tests/ssh_generate.py +++ b/tests/ssh_generate.py @@ -8,7 +8,6 @@ def run(cmd): for dirname in ["myssh_send", "myssh_get"]: - if os.path.isdir(dirname): shutil.rmtree(dirname) diff --git a/tests/ssh_test.py b/tests/ssh_test.py index 330c2a7..46b6267 100644 --- a/tests/ssh_test.py +++ b/tests/ssh_test.py @@ -23,7 +23,6 @@ def run(cmd): class Test_ssh(unittest.TestCase): def test_all(self): - operations = [ "bar.txt -> bar.txt", "foo.txt == foo.txt", @@ -105,7 +104,6 @@ def test_all(self): if __name__ == "__main__": - Test_ssh.PREFIX = sys.argv.pop() Test_ssh.HOST = sys.argv.pop() diff --git a/tests/test_main.py b/tests/test_main.py index caa8acb..05bebd1 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -15,21 +15,18 @@ def run(cmd, verbose=False): class Test_tools(unittest.TestCase): def test_flatten(self): - arg = [1, [2, 2, 2], 4] ret = [1, 2, 2, 2, 4] self.assertEqual(ret, shelephant.convert.flatten(arg)) def test_squash(self): - arg = {"foo": [1, 2], "bar": {"foo": [3, 4], "bar": 5}} ret = [1, 2, 3, 4, 5] self.assertEqual(ret, shelephant.convert.squash(arg)) def test_deepest_dirs(self): - dirnames = [ "foo/bar", "foo/bar/mydir", @@ -57,7 +54,6 @@ def test_deepest_dirs(self): class Test_checksum(unittest.TestCase): def test_basic(self): - with open("foo.txt", "w") as file: file.write("foo") @@ -81,7 +77,6 @@ def test_basic(self): os.remove("shelephant_checksum.yaml") def test_hybrid(self): - with open("foo.txt", "w") as file: file.write("foo") @@ -110,7 +105,6 @@ def test_hybrid(self): os.remove("shelephant_hostinfo.yaml") def test_recursive(self): - letters = ["a", "b", "c", "d", "e", "f", "g"] for letter in letters: @@ -166,7 +160,6 @@ def test_recursive(self): class Test_dump(unittest.TestCase): def test_basic(self): - with open("myfile_foo.txt", "w") as file: file.write("foo") @@ -214,7 +207,6 @@ def test_basic(self): shutil.rmtree("mydir") def test_append(self): - with open("foo.txt", "w") as file: file.write("foo") @@ -242,7 +234,6 @@ def test_append(self): os.remove("shelephant_dump.yaml") def test_exclude(self): - shelephant_dump(["a.txt", "b.bak", "c.h5", "-E", ".bak", "-o", "dump.yaml"]) self.assertEqual( @@ -255,7 +246,6 @@ def test_exclude(self): class Test_extract(unittest.TestCase): def test_single_path(self): - data = { "foo": ["foo.txt", "bar.txt"], "bar": ["foo.pdf", "bar.pdf"], @@ -271,7 +261,6 @@ def test_single_path(self): os.remove("dump.yaml") def test_multiple_paths(self): - data = { "foo": ["foo.txt", "bar.txt"], "bar": ["foo.pdf", "bar.pdf"], @@ -295,7 +284,6 @@ def test_multiple_paths(self): os.remove("dump.yaml") def test_multiple_paths_squash(self): - data = { "foo": ["foo.txt", "bar.txt"], "bar": ["foo.pdf", "bar.pdf"], @@ -321,7 +309,6 @@ def test_multiple_paths_squash(self): class Test_merge(unittest.TestCase): def test_basic(self): - with open("foo.txt", "w") as file: file.write("foo") @@ -369,7 +356,6 @@ def test_basic(self): class Test_hostinfo(unittest.TestCase): def test_basic(self): - for dirname in ["mysrc", "mydest"]: if os.path.isdir(dirname): shutil.rmtree(dirname) @@ -405,7 +391,6 @@ def test_basic(self): shutil.rmtree("mydest") def test_remove(self): - with open("foo.txt", "w") as file: file.write("foo") @@ -435,7 +420,6 @@ def test_remove(self): class Test_get(unittest.TestCase): def test_basic(self): - for dirname in ["mysrc", "mydest"]: if os.path.isdir(dirname): shutil.rmtree(dirname) @@ -479,7 +463,6 @@ def test_basic(self): shutil.rmtree("mydest") def test_partial(self): - for dirname in ["mysrc", "mydest"]: if os.path.isdir(dirname): shutil.rmtree(dirname) @@ -525,7 +508,6 @@ def test_partial(self): shutil.rmtree("mydest") def test_partial_localchecksum(self): - for dirname in ["mysrc", "mydest"]: if os.path.isdir(dirname): shutil.rmtree(dirname) @@ -587,7 +569,6 @@ def test_partial_localchecksum(self): shutil.rmtree("mydest") def test_partial_rsync(self): - for dirname in ["mysrc", "mydest"]: if os.path.isdir(dirname): shutil.rmtree(dirname) @@ -633,7 +614,6 @@ def test_partial_rsync(self): class Test_send(unittest.TestCase): def test_basic(self): - for dirname in ["mysrc", "mydest"]: if os.path.isdir(dirname): shutil.rmtree(dirname) @@ -685,7 +665,6 @@ def test_basic(self): os.remove("shelephant_hostinfo.yaml") def test_empty_remote(self): - for dirname in ["mysrc", "mydest"]: if os.path.isdir(dirname): shutil.rmtree(dirname) @@ -728,7 +707,6 @@ def test_empty_remote(self): os.remove("hostinfo.yaml") def test_partial(self): - for dirname in ["mysrc", "mydest"]: if os.path.isdir(dirname): shutil.rmtree(dirname) @@ -777,7 +755,6 @@ def test_partial(self): os.remove("shelephant_hostinfo.yaml") def test_partial_localchecksum(self): - for dirname in ["mysrc", "mydest"]: if os.path.isdir(dirname): shutil.rmtree(dirname) @@ -850,7 +827,6 @@ def test_partial_localchecksum(self): os.remove("local.yaml") def test_partial_rsync(self): - for dirname in ["mysrc", "mydest"]: if os.path.isdir(dirname): shutil.rmtree(dirname) @@ -897,7 +873,6 @@ def test_partial_rsync(self): class Test_mv(unittest.TestCase): def test_basic(self): - for dirname in ["mysrc", "mydest"]: if os.path.isdir(dirname): shutil.rmtree(dirname) @@ -932,7 +907,6 @@ def test_basic(self): class Test_cp(unittest.TestCase): def test_basic(self): - for dirname in ["mysrc", "mydest"]: if os.path.isdir(dirname): shutil.rmtree(dirname) @@ -967,7 +941,6 @@ def test_basic(self): shutil.rmtree("mydest") def test_rsync(self): - for dirname in ["mysrc", "mydest"]: if os.path.isdir(dirname): shutil.rmtree(dirname) @@ -1012,7 +985,6 @@ def test_rsync(self): shutil.rmtree("mydest") def test_nested(self): - for dirname in ["mysrc", "mybak"]: if os.path.isdir(dirname): shutil.rmtree(dirname) @@ -1054,7 +1026,6 @@ def test_nested(self): class Test_rm(unittest.TestCase): def test_basic(self): - with open("foo.txt", "w") as file: file.write("foo") @@ -1072,7 +1043,6 @@ def test_basic(self): class Test_diff(unittest.TestCase): def test_basic(self): - for dirname in ["mysrc", "mydest"]: if os.path.isdir(dirname): shutil.rmtree(dirname) @@ -1112,7 +1082,6 @@ def test_basic(self): class Test_parse(unittest.TestCase): def test_basic(self): - with open("foo.txt", "w") as file: file.write("foo") @@ -1130,5 +1099,4 @@ def test_basic(self): if __name__ == "__main__": - unittest.main()