Browse Source

Remove the need for pydantic (overkill for this)

pull/2/head
Ryan Reed 2 years ago
parent
commit
43ca777f7f
4 changed files with 17 additions and 29 deletions
  1. +1
    -2
      pyproject.toml
  2. +5
    -8
      tests/test_project.py
  3. +5
    -0
      transpose/__init__.py
  4. +6
    -19
      transpose/console.py

+ 1
- 2
pyproject.toml View File

@ -6,13 +6,12 @@ authors = ["Ryan Reed"]
[tool.poetry.dependencies]
python = "^3.7"
pydantic = "*"
python-dotenv = "*"
[tool.poetry.dev-dependencies]
black = "==22.6"
flake8 = "==3.8.4"
pre-commit = "*"
python-dotenv = "*"
pytest = "*"
pytest-sugar = "*"


+ 5
- 8
tests/test_project.py View File

@ -6,8 +6,7 @@ from pathlib import Path
from contextlib import contextmanager
from tempfile import TemporaryDirectory
from transpose import Transpose, version
from transpose.console import Config
from transpose import Transpose, version, DEFAULT_CACHE_FILENAME
from transpose.utils import check_path, create_cache, get_cache, move, remove, symlink
@ -17,8 +16,6 @@ SYMLINK_DIR = "symlink_test"
CACHE_FILE_CONTENTS = {"version": version, "original_path": TARGET_DIR}
config = Config()
@contextmanager
def setup():
@ -31,7 +28,7 @@ def setup():
os.mkdir(STORE_DIR)
os.symlink(TARGET_DIR, SYMLINK_DIR)
cache_path = Path(TARGET_DIR, config.cache_filename)
cache_path = Path(TARGET_DIR).joinpath(DEFAULT_CACHE_FILENAME)
with open(str(cache_path), "w") as f:
json.dump(CACHE_FILE_CONTENTS, f)
yield
@ -45,7 +42,7 @@ def test_check_path():
nonexisting_dir = Path("nonexistent")
symlink_dir = Path(SYMLINK_DIR)
cache_path = Path(TARGET_DIR).joinpath(config.cache_filename)
cache_path = Path(TARGET_DIR).joinpath(DEFAULT_CACHE_FILENAME)
assert check_path(existing_dir) is True
assert check_path(nonexisting_dir) is False
@ -71,7 +68,7 @@ def test_cache_create():
@setup()
def test_cache_get():
cache_path = Path(TARGET_DIR).joinpath(config.cache_filename)
cache_path = Path(TARGET_DIR).joinpath(DEFAULT_CACHE_FILENAME)
cache = get_cache(cache_path)
assert cache["version"] == CACHE_FILE_CONTENTS["version"]
@ -90,7 +87,7 @@ def test_file_move():
@setup()
def test_file_remove():
cache_path = Path(TARGET_DIR).joinpath(config.cache_filename)
cache_path = Path(TARGET_DIR).joinpath(DEFAULT_CACHE_FILENAME)
symlink_filepath = Path(TARGET_DIR).joinpath(SYMLINK_DIR)
target_filepath = Path(TARGET_DIR)


+ 5
- 0
transpose/__init__.py View File

@ -1,4 +1,9 @@
from .logger import create_logger
import os
DEFAULT_XDG_PATH = os.environ.get("XDG_DATA_HOME", f"{os.environ['HOME']}/.local/share")
DEFAULT_CACHE_FILENAME = ".transpose.json"
DEFAULT_STORE_PATH = f"{DEFAULT_XDG_PATH}/transpose"
version_info = (0, 9, 0)
version = ".".join(str(c) for c in version_info)


+ 6
- 19
transpose/console.py View File

@ -1,32 +1,19 @@
import argparse
import os
from pydantic import BaseSettings
from transpose import Transpose, version
default_xdg_path = os.environ.get("XDG_DATA_HOME", f"{os.environ['HOME']}/.local/share")
class Config(BaseSettings):
store_path: str = f"{default_xdg_path}/transpose"
cache_filename: str = ".transpose.json"
class Config:
env_file = ".env"
env_file_encoding = "utf-8"
env_nested_delimiter = "__"
env_prefix = "TRANSPOSE_"
from transpose import Transpose, version, DEFAULT_STORE_PATH, DEFAULT_CACHE_FILENAME
def entry_point() -> None:
config = Config()
store_path = os.environ.get("TRANSPOSE_STORE_PATH", DEFAULT_STORE_PATH)
cache_filename = os.environ.get("TRANSPOSE_CACHE_FILENAME", DEFAULT_CACHE_FILENAME)
args = parse_arguments()
t = Transpose(
target_path=args.target_path,
store_path=config.store_path,
cache_filename=config.cache_filename,
store_path=store_path,
cache_filename=cache_filename,
)
if args.action == "restore":


Loading…
Cancel
Save