From 494cfaa7bfbe0496cea78741d99c0e329cdc31ed Mon Sep 17 00:00:00 2001 From: Ryan Reed Date: Tue, 26 Jul 2022 22:26:06 -0400 Subject: [PATCH 1/2] BREAKING CHANGE: Moving store_path to only the store action --- README.md | 2 +- src/transpose/console.py | 19 +++++++++---------- src/transpose/transpose.py | 6 ++---- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index ba18ef0..1f8c49f 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ transpose restore ~/.local/share/transpose/zsh # Remove symlink, move ~/.local/ transpose apply ~/.local/share/transpose/zsh # Recreate symlink in cache location transpose create ~/.config/zsh ~/.local/share/transpose/zsh # Recreate cache file -transpose -s /mnt/backups store ~/.config/zsh zsh_config # Move ~/.config/zsh -> /mnt/backups/zsh_config, create symlink, create cache +transpose store ~/.config/zsh zsh_config -s /mnt/backups # Move ~/.config/zsh -> /mnt/backups/zsh_config, create symlink, create cache transpose --cache-filename .mycache.json restore /mnt/backups/zsh_config # Use /mnt/backup/.zsh_config.json for restoring a stored directory ``` diff --git a/src/transpose/console.py b/src/transpose/console.py index c1c2e15..9976cd9 100644 --- a/src/transpose/console.py +++ b/src/transpose/console.py @@ -9,7 +9,6 @@ def entry_point() -> None: t = Transpose( target_path=args.target_path, - store_path=args.store_path, cache_filename=args.cache_filename, ) @@ -20,7 +19,7 @@ def entry_point() -> None: elif args.action == "restore": t.restore() elif args.action == "store": - t.store(name=args.name) + t.store(store_path=args.store_path, name=args.name) def parse_arguments(args=None): @@ -43,14 +42,6 @@ def parse_arguments(args=None): """, ) parser.add_argument("--version", action="version", version=f"Transpose {version}") - parser.add_argument( - "-s", - "--store-path", - dest="store_path", - nargs="?", - default=store_path, - help="The path to where the targets should be stored (default: %(default)s)", - ) subparsers = parser.add_subparsers( help="Transpose Action", dest="action", required=True @@ -105,6 +96,14 @@ def parse_arguments(args=None): default=None, help="The name of the directory that will be created in the store path (default: target_path)", ) + store_parser.add_argument( + "-s", + "--store-path", + dest="store_path", + nargs="?", + default=store_path, + help="The path to where the targets should be stored (default: %(default)s)", + ) return parser.parse_args(args) diff --git a/src/transpose/transpose.py b/src/transpose/transpose.py index d2e979b..c359c66 100644 --- a/src/transpose/transpose.py +++ b/src/transpose/transpose.py @@ -8,11 +8,9 @@ class Transpose: def __init__( self, target_path: str, - store_path: str, cache_filename: str = None, ) -> None: self.target_path = pathlib.Path(target_path) - self.store_path = pathlib.Path(store_path) if not cache_filename: cache_filename = ".transpose.json" @@ -86,14 +84,14 @@ class Transpose: new_cache_path = pathlib.Path(original_path).joinpath(self.cache_filename) remove(new_cache_path) - def store(self, name: str = None) -> None: + def store(self, store_path: str, name: str = None) -> None: """ Moves a directory to a central location and creates a symlink to the old path. """ if name is None: name = self.target_path.name - new_location = pathlib.Path(self.store_path).joinpath(name) + new_location = pathlib.Path(store_path).joinpath(name) if not check_path(path=self.target_path): raise TransposeError( From bdab905c353a14f75e2a0bd69abbf5d4ee3a8ae3 Mon Sep 17 00:00:00 2001 From: Ryan Reed Date: Tue, 26 Jul 2022 22:27:19 -0400 Subject: [PATCH 2/2] test: Updating tests to support moving store_path to store action --- tests/test_console.py | 4 ++-- tests/test_transpose.py | 38 +++++++++----------------------------- 2 files changed, 11 insertions(+), 31 deletions(-) diff --git a/tests/test_console.py b/tests/test_console.py index 8c2f056..7e5dc03 100644 --- a/tests/test_console.py +++ b/tests/test_console.py @@ -10,13 +10,13 @@ def test_parse_arguments(): args = parse_arguments( [ - "--store-path", - "/mnt/store", "store", "--cache-filename", "test-cache-file.json", "MyTarget", "/tmp/some/path", + "--store-path", + "/mnt/store", ] ) assert args.cache_filename == "test-cache-file.json" diff --git a/tests/test_transpose.py b/tests/test_transpose.py index 1d83c26..67239c4 100644 --- a/tests/test_transpose.py +++ b/tests/test_transpose.py @@ -16,16 +16,11 @@ from .utils import ( def test_init(): - t = Transpose( - target_path=TARGET_DIR, - store_path=STORE_DIR, - ) + t = Transpose(target_path=TARGET_DIR) assert t.cache_filename == ".transpose.json" assert t.cache_path == pathlib.Path(TARGET_DIR).joinpath(".transpose.json") - t = Transpose( - target_path=TARGET_DIR, store_path=STORE_DIR, cache_filename=".transpose.txt" - ) + t = Transpose(target_path=TARGET_DIR, cache_filename=".transpose.txt") assert t.cache_filename == ".transpose.txt" assert t.cache_path == pathlib.Path(TARGET_DIR).joinpath(".transpose.txt") @@ -35,10 +30,7 @@ def test_apply(): store_path = pathlib.Path(STORE_DIR) target_path = pathlib.Path(TARGET_DIR) - t = Transpose( - target_path=STORE_DIR, - store_path=STORE_DIR, - ) + t = Transpose(target_path=STORE_DIR) with open(t.cache_path, "r") as f: cache = json.load(f) @@ -65,10 +57,7 @@ def test_create(): target_path = pathlib.Path(TARGET_DIR) stored_path = pathlib.Path(STORE_DIR).joinpath(STORED_DIR) - t = Transpose( - target_path=str(target_path), - store_path=str(stored_path), - ) + t = Transpose(target_path=str(target_path)) # Missing stored path stored_path.rename("tmp") @@ -91,11 +80,8 @@ def test_create(): @setup_store() def test_store(): - t = Transpose( - target_path=TARGET_DIR, - store_path=STORE_DIR, - ) - t.store() + t = Transpose(target_path=TARGET_DIR) + t.store(store_path=STORE_DIR) target_path = pathlib.Path(TARGET_DIR) store_path = pathlib.Path(STORE_DIR).joinpath(target_path.name) @@ -108,11 +94,8 @@ def test_store(): @setup_store() def test_store_named(): - t = Transpose( - target_path=TARGET_DIR, - store_path=STORE_DIR, - ) - t.store("TestStore") + t = Transpose(target_path=TARGET_DIR) + t.store(store_path=STORE_DIR, name="TestStore") target_path = pathlib.Path(TARGET_DIR) store_path = pathlib.Path(STORE_DIR).joinpath("TestStore") @@ -128,10 +111,7 @@ def test_restore(): target_path = pathlib.Path(TARGET_DIR) stored_path = pathlib.Path(STORE_DIR).joinpath(STORED_DIR) - t = Transpose( - target_path=str(stored_path), - store_path=STORE_DIR, - ) + t = Transpose(target_path=str(stored_path)) # Missing Cache File cache = t.cache_path.read_text()