Repository: AgnostiqHQ/covalent
Pull request #1439 (2022-12-06 17:55:40)

fix default directory paths
- [ ] I have added the tests to cover my changes.
- [ ] I have updated the documentation and CHANGELOG accordingly.
- [ ] I have read the CONTRIBUTING document.


Updating the default paths to `directory` like environment variables to avoid creating re-dundant directories when self-hosting

github-actions[bot]: Hello. You may have forgotten to update the changelog!
Please edit [`CHANGELOG.md`](/AgnostiqHQ/covalent/blob/master/CHANGELOG.md) with a one-to-two sentence description of the change in the UNRELEASED section. You may include a small working example for new features.

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 43c3ca1c..d9e3b2fa 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -24,7 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ### Changed
 
-- Updated all references to `results_dir` to use the environment variable `COVALENT_DATA_DIR` if set or fall back to `~/.local/share/covalent/data`
+- Updated `directory` like default environment variable paths to avoid creating redundant nested directories when self-hosting
 
 ### Docs
 
diff --git a/covalent/_shared_files/defaults.py b/covalent/_shared_files/defaults.py
index c8c9a83d..bbe733c0 100644
--- a/covalent/_shared_files/defaults.py
+++ b/covalent/_shared_files/defaults.py
@@ -46,14 +46,13 @@ def get_default_sdk_config():
         "config_file": (
             os.environ.get("COVALENT_CONFIG_DIR")
             or os.environ.get("XDG_CONFIG_DIR")
-            or os.environ["HOME"] + "/.config"
+            or (os.environ["HOME"] + "/.config/covalent")
         )
-        + "/covalent/covalent.conf",
+        + "/covalent.conf",
         "log_dir": (
             os.environ.get("COVALENT_LOGDIR")
-            or (os.environ.get("XDG_CACHE_HOME") or (os.environ["HOME"] + "/.cache"))
-        )
-        + "/covalent",
+            or (os.environ.get("XDG_CACHE_HOME") or (os.environ["HOME"] + "/.cache/covalent"))
+        ),
         "log_level": os.environ.get("LOGLEVEL", "WARNING").lower(),
         "enable_logging": os.environ.get("COVALENT_LOG_TO_FILE", "true").lower(),
         "executor_dir": os.environ.get("COVALENT_EXECUTOR_DIR")
@@ -74,7 +73,7 @@ def get_default_dispatcher_config():
         "results_dir": os.environ.get("COVALENT_DATA_DIR")
         or os.path.join(os.environ["HOME"], ".local/share/covalent/data"),
         "log_dir": os.environ.get("COVALENT_LOGDIR")
-        or ((os.environ.get("XDG_CACHE_HOME") or (os.environ["HOME"] + "/.cache")) + "/covalent"),
+        or ((os.environ.get("XDG_CACHE_HOME") or (os.environ["HOME"] + "/.cache/covalent"))),
         "db_path": os.environ.get("COVALENT_DATABASE")
         or (
             (os.environ.get("XDG_DATA_HOME") or (os.environ["HOME"] + "/.local/share"))
@@ -86,9 +85,9 @@ def get_default_dispatcher_config():
 def get_default_dask_config():
     return {
         "cache_dir": os.environ.get("COVALENT_CACHE_DIR")
-        or ((os.environ.get("XDG_CACHE_HOME") or (os.environ["HOME"] + "/.cache")) + "/covalent"),
+        or ((os.environ.get("XDG_CACHE_HOME") or (os.environ["HOME"] + "/.cache/covalent"))),
         "log_dir": os.environ.get("COVALENT_LOGDIR")
-        or ((os.environ.get("XDG_CACHE_HOME") or (os.environ["HOME"] + "/.cache")) + "/covalent"),
+        or ((os.environ.get("XDG_CACHE_HOME") or (os.environ["HOME"] + "/.cache/covalent"))),
         "mem_per_worker": "auto",
         "threads_per_worker": 1,
         "num_workers": dask.system.CPU_COUNT,
@@ -114,7 +113,7 @@ def get_default_ui_config():
         else 48008,
         "dev_port": 49009,
         "log_dir": os.environ.get("COVALENT_LOGDIR")
-        or ((os.environ.get("XDG_CACHE_HOME") or (os.environ["HOME"] + "/.cache")) + "/covalent"),
+        or ((os.environ.get("XDG_CACHE_HOME") or (os.environ["HOME"] + "/.cache/covalent"))),
     }
 
 


Test patch:
diff --git a/tests/covalent_tests/shared_files/config_test.py b/tests/covalent_tests/shared_files/config_test.py
index f1b8bdcc..59dd7b27 100644
--- a/tests/covalent_tests/shared_files/config_test.py
+++ b/tests/covalent_tests/shared_files/config_test.py
@@ -32,8 +32,8 @@ DEFAULT_CONFIG = asdict(DefaultConfig())
 @pytest.mark.parametrize(
     "dir_env, conf_dir",
     [
-        ("COVALENT_CONFIG_DIR", "covalent/covalent.conf"),
-        ("XDG_CONFIG_DIR", "covalent/covalent.conf"),
+        ("COVALENT_CONFIG_DIR", "covalent.conf"),
+        ("XDG_CONFIG_DIR", "covalent.conf"),
         ("HOME", ".config/covalent/covalent.conf"),
     ],
 )