Repository: iterative/dvc
Pull request #10603 (2024-10-24 02:15:51)

build(deps): update platformdirs requirement from <4,>=3.1.1 to >=3.1.1,<5
Updates the requirements on [platformdirs](https://github.com/tox-dev/platformdirs) to permit the latest version.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a href="https://github.com/tox-dev/platformdirs/releases">platformdirs's releases</a>.</em></p>
<blockquote>
<h2>4.3.6</h2>
<!-- raw HTML omitted -->
<h2>What's Changed</h2>
<ul>
<li>Fix readme download target by <a href="https://github.com/gaborbernat"><code>@​gaborbernat</code></a> in <a href="https://redirect.github.com/tox-dev/platformdirs/pull/307">tox-dev/platformdirs#307</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a href="https://github.com/tox-dev/platformdirs/compare/4.3.5...4.3.6">https://github.com/tox-dev/platformdirs/compare/4.3.5...4.3.6</a></p>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a href="https://github.com/tox-dev/platformdirs/blob/main/CHANGES.rst">platformdirs's changelog</a>.</em></p>
<blockquote>
<h1>platformdirs Changelog</h1>
<p>The changes of more recent versions are <code>tracked here &lt;https://github.com/tox-dev/platformdirs/releases&gt;</code>_.</p>
<h2>platformdirs 4.0.0 (2023-11-10)</h2>
<ul>
<li>UNIX: revert site_cache_dir to use <code>/var/cache</code> instead of <code>/var/tmp</code></li>
</ul>
<h2>platformdirs 3.8.1 (2023-07-06)</h2>
<ul>
<li>BSD: provide a fallback for <code>user_runtime_dir</code></li>
</ul>
<h2>platformdirs 3.8.0 (2023-06-22)</h2>
<ul>
<li>Add missing user media directory docs</li>
</ul>
<h2>platformdirs 3.7.0 (2023-06-20)</h2>
<ul>
<li>Have user_runtime_dir return /var/run/user/uid for *BSD</li>
</ul>
<h2>platformdirs 3.6.0 (2023-06-19)</h2>
<ul>
<li>introduce <code>user_downloads_dir</code></li>
</ul>
<h2>platformdirs 3.5.3 (2023-06-09)</h2>
<ul>
<li>Use ruff</li>
</ul>
<h2>platformdirs 3.5.2 (2023-05-30)</h2>
<ul>
<li>test with 3.12.0.b1</li>
</ul>
<h2>platformdirs 3.5.1 (2023-05-11)</h2>
<ul>
<li>Add 3.12 support</li>
<li>Add tox.ini to sdist</li>
<li>removing Windows versions</li>
<li>Better handling for UNIX support</li>
</ul>
<h2>platformdirs 3.5.0 (2023-04-27)</h2>
<ul>
<li>introduce <code>user_music_dir</code></li>
</ul>
<h2>platformdirs 3.4.0 (2023-04-26)</h2>
<ul>
<li>introduce <code>user_videos_dir</code></li>
</ul>
<h2>platformdirs 3.3.0 (2023-04-25)</h2>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/tox-dev/platformdirs/commit/bc0405cb9c9439e6923b2dc090f91ad5daaf7dec"><code>bc0405c</code></a> Fix readme download target (<a href="https://redirect.github.com/tox-dev/platformdirs/issues/307">#307</a>)</li>
<li><a href="https://github.com/tox-dev/platformdirs/commit/c076da9e8ca199826bb5a9ba42b21632ac617869"><code>c076da9</code></a> Split build and publish for release (<a href="https://redirect.github.com/tox-dev/platformdirs/issues/306">#306</a>)</li>
<li><a href="https://github.com/tox-dev/platformdirs/commit/30199ecfcaceb72c1361410ed0d3b2aa9c319a60"><code>30199ec</code></a> Use upstream setup-uv with uv python (<a href="https://redirect.github.com/tox-dev/platformdirs/issues/305">#305</a>)</li>
<li><a href="https://github.com/tox-dev/platformdirs/commit/3ce64d0c873263556156f21bb9cf94a00b7c241d"><code>3ce64d0</code></a> Bump astral-sh/setup-uv from 2 to 3 (<a href="https://redirect.github.com/tox-dev/platformdirs/issues/304">#304</a>)</li>
<li><a href="https://github.com/tox-dev/platformdirs/commit/67691e23c98134a7d7c94ad25e2b7c647aa3e7aa"><code>67691e2</code></a> [pre-commit.ci] pre-commit autoupdate (<a href="https://redirect.github.com/tox-dev/platformdirs/issues/303">#303</a>)</li>
<li><a href="https://github.com/tox-dev/platformdirs/commit/85feea9d67e6d87b2640f20572862b79f4c6792e"><code>85feea9</code></a> don't include outdated changelog in docs (<a href="https://redirect.github.com/tox-dev/platformdirs/issues/301">#301</a>)</li>
<li><a href="https://github.com/tox-dev/platformdirs/commit/580dffd03281bba560dfbeb80518d9b2f2b4a107"><code>580dffd</code></a> Update check.yml (<a href="https://redirect.github.com/tox-dev/platformdirs/issues/302">#302</a>)</li>
<li><a href="https://github.com/tox-dev/platformdirs/commit/c596271d168161caf14f24abd951e0e0d96f24f5"><code>c596271</code></a> Fix multi-path returned from <code>_path</code> methods on MacOS (<a href="https://redirect.github.com/tox-dev/platformdirs/issues/299">#299</a>)</li>
<li><a href="https://github.com/tox-dev/platformdirs/commit/a420284fdeb471e8914ea3602902642ba3ddbfb7"><code>a420284</code></a> Use uv as installer (<a href="https://redirect.github.com/tox-dev/platformdirs/issues/300">#300</a>)</li>
<li><a href="https://github.com/tox-dev/platformdirs/commit/49a89efaa912351008dc8f71c17b4ba609e70d79"><code>49a89ef</code></a> Update README.rst</li>
<li>Additional commits viewable in <a href="https://github.com/tox-dev/platformdirs/compare/3.1.1...4.3.6">compare view</a></li>
</ul>
</details>
<br />


Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)


</details>


Patch:
diff --git a/dvc/dirs.py b/dvc/dirs.py
index 59223b767..c6737678d 100644
--- a/dvc/dirs.py
+++ b/dvc/dirs.py
@@ -21,6 +21,19 @@ def global_config_dir():
 
 
 def site_cache_dir():
+    from platformdirs import PlatformDirs
+    from platformdirs.unix import Unix
+
+    if issubclass(Unix, PlatformDirs):
+        # Return the cache directory shared by users, e.g. `/var/tmp/$appname`
+        # NOTE: platformdirs>=5 changed `site_cache_dir` to return /var/cache/$appname.
+        # as the following path is considered insecure.
+        # For details, see: https://github.com/tox-dev/platformdirs/pull/239
+
+        # FIXME: keeping the old behavior temporarily to avoid dependency conflict.
+        #        In the future, consider migrating to a more secure directory.
+        return f"/var/tmp/{APPNAME}"  # noqa: S108
+
     return os.getenv(env.DVC_SITE_CACHE_DIR) or platformdirs.site_cache_dir(
         APPNAME, APPAUTHOR, opinion=True
     )
diff --git a/pyproject.toml b/pyproject.toml
index 4a72156d8..7bc860c08 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -57,7 +57,7 @@ dependencies = [
     "omegaconf",
     "packaging>=19",
     "pathspec>=0.10.3",
-    "platformdirs<4,>=3.1.1",
+    "platformdirs<5,>=3.1.1",
     "psutil>=5.8",
     "pydot>=1.2.4",
     "pygtrie>=2.3.2",


Test patch:
diff --git a/tests/unit/test_dirs.py b/tests/unit/test_dirs.py
index 5ae2acba0..0098c0cbf 100644
--- a/tests/unit/test_dirs.py
+++ b/tests/unit/test_dirs.py
@@ -1,4 +1,8 @@
-from dvc.dirs import global_config_dir
+import sys
+
+import pytest
+
+from dvc.dirs import global_config_dir, site_cache_dir
 from dvc.env import DVC_GLOBAL_CONFIG_DIR
 
 
@@ -6,3 +10,8 @@ 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
+
+
+@pytest.mark.skipif(sys.platform != "linux", reason="Only for Unix platforms")
+def test_site_cache_dir_on_unix():
+    assert site_cache_dir() == "/var/tmp/dvc"