PyAPI: add bpy.path.is_autoexec

Expose the excluded paths check used by the file selector's
"Trusted Source" option so scripts can match its behavior.

Ref !163464
This commit is contained in:
Campbell Barton 2026-09-03 09:04:18 +00:00
parent e877ae3863
commit 20ca120140
5 changed files with 80 additions and 5 deletions

View file

@ -35,6 +35,32 @@ class TestBpyPath(unittest.TestCase):
self.assertEqual(ensure_ext('demoBlend', 'blend', case_sensitive=True), 'demoBlendblend')
self.assertEqual(ensure_ext('demo', '', case_sensitive=True), 'demo')
def test_is_autoexec(self):
import bpy
from bpy.path import is_autoexec
prefs = bpy.context.preferences
use_scripts_auto_execute = prefs.filepaths.use_scripts_auto_execute
self.addCleanup(setattr, prefs.filepaths, "use_scripts_auto_execute", use_scripts_auto_execute)
path_cmp = prefs.autoexec_paths.new()
self.addCleanup(prefs.autoexec_paths.remove, path_cmp)
path_cmp.path = "/untrusted/"
self.assertFalse(is_autoexec("/untrusted/"))
self.assertFalse(is_autoexec(b"/untrusted/"))
self.assertTrue(is_autoexec("/trusted/"))
path_cmp.use_glob = True
path_cmp.path = "*/download*"
self.assertFalse(is_autoexec("/home/user/downloads/"))
self.assertTrue(is_autoexec("/home/user/projects/"))
# The preference to enable auto-execution isn't taken into account.
prefs.filepaths.use_scripts_auto_execute = False
self.assertFalse(is_autoexec("/home/user/downloads/"))
if __name__ == '__main__':
import sys