From 43ca777f7f21ef5e007bb788dea7591c8d1350a5 Mon Sep 17 00:00:00 2001
From: Ryan Reed <git@ryanreed.net>
Date: Thu, 30 Jun 2022 13:15:58 -0400
Subject: [PATCH] Remove the need for pydantic (overkill for this)

---
 pyproject.toml        |  3 +--
 tests/test_project.py | 13 +++++--------
 transpose/__init__.py |  5 +++++
 transpose/console.py  | 25 ++++++-------------------
 4 files changed, 17 insertions(+), 29 deletions(-)

diff --git a/pyproject.toml b/pyproject.toml
index e0c5fed..96906db 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -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 = "*"
 
diff --git a/tests/test_project.py b/tests/test_project.py
index db8c0af..0da6854 100644
--- a/tests/test_project.py
+++ b/tests/test_project.py
@@ -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)
 
diff --git a/transpose/__init__.py b/transpose/__init__.py
index b06f8c3..304fb59 100644
--- a/transpose/__init__.py
+++ b/transpose/__init__.py
@@ -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)
diff --git a/transpose/console.py b/transpose/console.py
index f2e76f4..2f37837 100644
--- a/transpose/console.py
+++ b/transpose/console.py
@@ -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":