Repository: iterative/dvc
Pull request #10107 (2023-11-23 18:25:01)

fix(config): respect global config env variable
Minor fix in the way we handle config dirs. I think it's not documented and primarily used for test. We plan to start using it to isolate tests in Studio and isolate repos on workers.

------------

* [X] ❗ I have followed the [Contributing to DVC](https://dvc.org/doc/user-guide/contributing/core) checklist.

* [X] 📖 If this PR requires [documentation](https://dvc.org/doc) updates, I have created a separate PR (or issue, at least) in [dvc.org](https://github.com/iterative/dvc.org) and linked it here.

Thank you for the contribution - we'll try to review it as soon as possible. 🙏


codecov[bot]: ## [Codecov](https://app.codecov.io/gh/iterative/dvc/pull/10107?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iterative) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Comparison is base [(`06b9196`)](https://app.codecov.io/gh/iterative/dvc/commit/06b9196371b4a0cf83eb25f950d32a348b9b922b?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iterative) 90.48% compared to head [(`588e0e4`)](https://app.codecov.io/gh/iterative/dvc/pull/10107?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iterative) 90.08%.


<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##             main   #10107      +/-   ##
==========================================
- Coverage   90.48%   90.08%   -0.41%     
==========================================
  Files         487      488       +1     
  Lines       37384    37391       +7     
  Branches     5433     5424       -9     
==========================================
- Hits        33826    33682     -144     
- Misses       2918     3024     +106     
- Partials      640      685      +45     
```



</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/iterative/dvc/pull/10107?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iterative).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iterative).


Patch:
diff --git a/dvc/dirs.py b/dvc/dirs.py
index dcb52b9e4..59223b767 100644
--- a/dvc/dirs.py
+++ b/dvc/dirs.py
@@ -15,7 +15,7 @@ def system_config_dir():
 
 
 def global_config_dir():
-    return os.getenv(env.DVC_SYSTEM_CONFIG_DIR) or platformdirs.user_config_dir(
+    return os.getenv(env.DVC_GLOBAL_CONFIG_DIR) or platformdirs.user_config_dir(
         APPNAME, APPAUTHOR
     )
 


Test patch:
diff --git a/tests/unit/test_dirs.py b/tests/unit/test_dirs.py
new file mode 100644
index 000000000..5ae2acba0
--- /dev/null
+++ b/tests/unit/test_dirs.py
@@ -0,0 +1,8 @@
+from dvc.dirs import global_config_dir
+from dvc.env import DVC_GLOBAL_CONFIG_DIR
+
+
+def test_global_config_dir_respects_env_var(monkeypatch):
+    path = "/some/random/path"
+    monkeypatch.setenv(DVC_GLOBAL_CONFIG_DIR, path)
+    assert global_config_dir() == path