Browse Source

Cleaning up imports

pull/3/head
Ryan Reed 2 years ago
parent
commit
ee2c068990
4 changed files with 20 additions and 20 deletions
  1. +2
    -1
      src/transpose/__init__.py
  2. +8
    -8
      src/transpose/transpose.py
  3. +3
    -3
      src/transpose/utils.py
  4. +7
    -8
      tests/test_transpose.py

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

@ -1,6 +1,7 @@
from importlib.metadata import version
import os
from importlib.metadata import version
from .logger import create_logger
DEFAULT_XDG_PATH = os.environ.get("XDG_DATA_HOME", f"{os.environ['HOME']}/.local/share")


+ 8
- 8
src/transpose/transpose.py View File

@ -1,4 +1,4 @@
from pathlib import Path
import pathlib
from .exceptions import TransposeError
from .utils import check_path, create_cache, get_cache, move, remove, symlink
@ -11,13 +11,13 @@ class Transpose:
store_path: str,
cache_filename: str = None,
) -> None:
self.target_path = Path(target_path)
self.store_path = Path(store_path)
self.target_path = pathlib.Path(target_path)
self.store_path = pathlib.Path(store_path)
if not cache_filename:
cache_filename = ".transpose.json"
self.cache_filename = cache_filename
self.cache_path = Path(self.target_path).joinpath(cache_filename)
self.cache_path = pathlib.Path(self.target_path).joinpath(cache_filename)
def apply(self) -> None:
"""
@ -29,7 +29,7 @@ class Transpose:
)
cache = get_cache(self.cache_path)
original_path = Path(cache["original_path"])
original_path = pathlib.Path(cache["original_path"])
if original_path.is_symlink():
remove(original_path)
@ -48,7 +48,7 @@ class Transpose:
raise TransposeError(f"Target path does not exist: {self.target_path}")
cache = get_cache(self.cache_path)
original_path = Path(cache["original_path"])
original_path = pathlib.Path(cache["original_path"])
if original_path.is_symlink():
remove(original_path)
@ -64,14 +64,14 @@ class Transpose:
f"Original path, {original_path}, does not exist. Use '-f' to create the path"
)
new_cache_path = Path(original_path).joinpath(self.cache_filename)
new_cache_path = pathlib.Path(original_path).joinpath(self.cache_filename)
remove(new_cache_path)
def store(self, name: str) -> None:
"""
Moves a directory to a central location and creates a symlink to the old path.
"""
new_location = Path(self.store_path).joinpath(name)
new_location = pathlib.Path(self.store_path).joinpath(name)
if not check_path(path=self.target_path):
raise TransposeError(


+ 3
- 3
src/transpose/utils.py View File

@ -1,9 +1,9 @@
from pathlib import Path
from typing import Dict
import json
import shutil
from pathlib import Path
from typing import Dict
from . import version


+ 7
- 8
tests/test_transpose.py View File

@ -1,8 +1,7 @@
import json
import pathlib
import pytest
from pathlib import Path
from transpose import Transpose, version, DEFAULT_CACHE_FILENAME
from transpose.exceptions import TransposeError
@ -16,19 +15,19 @@ def test_init():
store_path=STORE_DIR,
)
assert t.cache_filename == ".transpose.json"
assert t.cache_path == Path(TARGET_DIR).joinpath(".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"
)
assert t.cache_filename == ".transpose.txt"
assert t.cache_path == Path(TARGET_DIR).joinpath(".transpose.txt")
assert t.cache_path == pathlib.Path(TARGET_DIR).joinpath(".transpose.txt")
@setup_env()
def test_apply():
store_path = Path(STORE_DIR)
target_path = Path(TARGET_DIR)
store_path = pathlib.Path(STORE_DIR)
target_path = pathlib.Path(TARGET_DIR)
store_path.rmdir()
target_path.rename(store_path)
@ -50,8 +49,8 @@ def test_store_restore():
)
t.store("TestStore")
target_path = Path(TARGET_DIR)
store_path = Path(STORE_DIR).joinpath("TestStore")
target_path = pathlib.Path(TARGET_DIR)
store_path = pathlib.Path(STORE_DIR).joinpath("TestStore")
assert store_path.is_dir() and not store_path.is_symlink()
assert target_path.is_dir() and target_path.is_symlink()


Loading…
Cancel
Save