Browse Source

Replacing Path rename with shutil, removing need for -f

pull/2/head
Ryan Reed 2 years ago
parent
commit
9362f064f3
4 changed files with 2 additions and 36 deletions
  1. +0
    -7
      src/transpose/console.py
  2. +0
    -6
      src/transpose/transpose.py
  3. +2
    -1
      src/transpose/utils.py
  4. +0
    -22
      tests/test_transpose.py

+ 0
- 7
src/transpose/console.py View File

@ -14,7 +14,6 @@ def entry_point() -> None:
target_path=args.target_path,
store_path=store_path,
cache_filename=cache_filename,
force=args.force,
)
if args.action == "apply":
@ -33,12 +32,6 @@ def parse_arguments():
Move and symlink a path for easier management
""",
)
parser.add_argument(
"-f",
"--force",
action="store_true",
help="Force directory moves. For instance, create the store path if it does not exist",
)
parser.add_argument("--version", action="version", version=f"Transpose {version}")
subparsers = parser.add_subparsers(


+ 0
- 6
src/transpose/transpose.py View File

@ -10,7 +10,6 @@ class Transpose:
target_path: str,
store_path: str,
cache_filename: str = None,
force: bool = False,
) -> None:
self.target_path = Path(target_path)
self.store_path = Path(store_path)
@ -20,8 +19,6 @@ class Transpose:
self.cache_filename = cache_filename
self.cache_path = Path(self.target_path).joinpath(cache_filename)
self.force = force
def apply(self) -> None:
"""
Recreate the symlink from an existing cache file
@ -60,9 +57,6 @@ class Transpose:
f"Original path in cache file already exists: {original_path}"
)
if not original_path.parent.exists() and self.force:
original_path.parent.mkdir(parents=True)
try:
move(source=self.target_path, destination=original_path)
except FileNotFoundError:


+ 2
- 1
src/transpose/utils.py View File

@ -2,6 +2,7 @@ from pathlib import Path
from typing import Dict
import json
import shutil
from . import version
@ -62,7 +63,7 @@ def move(source: Path, destination: Path) -> None:
"""
Move a file using pathlib
"""
source.rename(destination)
shutil.move(source, destination)
def remove(path: Path) -> None:


+ 0
- 22
tests/test_transpose.py View File

@ -66,25 +66,3 @@ def test_store_restore():
assert not store_path.exists()
assert target_path.is_dir() and not target_path.is_symlink()
assert not t.cache_path.exists()
@setup_env()
def test_restore_force():
nonexistent_path = Path(STORE_DIR).joinpath("long/path")
# Overwrite cache file with nonexistent directory
cache_path = Path(TARGET_DIR).joinpath(DEFAULT_CACHE_FILENAME)
cache = {"version": version, "original_path": str(nonexistent_path)}
with open(str(cache_path), "w") as f:
json.dump(cache, f)
# Force not enabled, should raise exception
t = Transpose(target_path=TARGET_DIR, store_path=STORE_DIR)
with pytest.raises(TransposeError):
t.restore()
assert not nonexistent_path.exists()
# Force enabled, should create directory tree
t = Transpose(target_path=TARGET_DIR, store_path=STORE_DIR, force=True)
t.restore()
assert nonexistent_path.exists()

Loading…
Cancel
Save