blender/tests/python/bl_pyapi_bpy_app.py
Sybren A. Stüvel e6f3c6a4ac Python: add bpy.app.cachedir
Give BPY access to Blender's cache directory, via `bpy.app.cachedir`.
This is similar to the already-existing `bpy.app.tempdir`.

This is needed for the Remote Asset Library system, to be able to
cache data from Python without having to re-implement the same logic
there.

```py
import bpy

print(bpy.app.cachedir)  # '/home/sybren/.cache/blender/'
```

Ref: #47684
Pull Request: https://projects.blender.org/blender/blender/pulls/152779
2026-01-16 12:31:03 +01:00

39 lines
940 B
Python

# SPDX-FileCopyrightText: 2026 Blender Authors
#
# SPDX-License-Identifier: GPL-2.0-or-later
# blender -b -P tests/python/bl_pyapi_bpy_app.py -- --verbose
__all__ = (
"main",
)
import os.path
import sys
import unittest
import bpy
class AppCachedirTest(unittest.TestCase):
def test_app_cachedir(self) -> None:
match sys.platform:
case 'darwin':
expect = '$HOME/Library/Caches/Blender/'
case 'win32':
expect = '%USERPROFILE%\\AppData\\Local\\Blender Foundation\\Blender\\Cache\\'
case _: # Linux or other POSIX-ish system.
expect = '$HOME/.cache/blender/'
expect = os.path.expandvars(expect)
self.assertEqual(expect, bpy.app.cachedir)
def main():
import sys
sys.argv = [__file__] + (sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else [])
unittest.main()
if __name__ == '__main__':
main()