@@ -17,34 +17,28 @@ def handle_(self, *, settings: DottedDict) -> None:
17
17
@classmethod
18
18
def find_paths (cls , settings : DottedDict ) -> list [str ]:
19
19
with tempfile .TemporaryDirectory () as tmpdir :
20
- filepath = Path (tmpdir ) / "print_sys_path.py"
21
- filepath .write_text (
22
- R"""
23
- import sys
20
+ dumped_result = Path (tmpdir ) / "sys_path.json"
21
+ dumper_path = Path (tmpdir ) / "sys_path_dumper.py"
22
+ dumper_path .write_text (
23
+ Rf"""
24
+ import bpy
24
25
import json
25
- json.dump({"executable": sys.executable, "paths": sys.path}, sys.stdout)
26
- exit(0)
26
+ import sys
27
+ with open(R"{ dumped_result } ", "w", encoding="utf-8") as f:
28
+ json.dump({{"executable": sys.executable, "paths": sys.path}}, f)
29
+ bpy.ops.wm.quit_blender()
27
30
""" .strip (),
28
31
encoding = "utf-8" ,
29
32
)
30
33
args = (
31
34
cls .get_dev_environment_subsetting (settings , "binary" ),
32
35
"--background" ,
33
36
"--python" ,
34
- str (filepath ),
37
+ str (dumper_path ),
35
38
)
36
39
result = run_shell_command (args , shell = False )
37
40
38
- if not result or result [2 ] != 0 :
39
- raise RuntimeError (f"Failed to run command: { args } " )
40
-
41
- # Blender prints a bunch of general information to stdout before printing the output of the python
42
- # script. We want to ignore that initial information. We do that by finding the start of the JSON
43
- # dict. This is a bit hacky and there must be a better way.
44
- if (index := result [0 ].find ('\n {"' )) == - 1 :
45
- raise RuntimeError ("Unexpected output when calling blender" )
41
+ if not result or result [2 ] != 0 :
42
+ raise RuntimeError (f"Failed to run command: { args } " )
46
43
47
- try :
48
- return json .loads (result [0 ][index :])["paths" ]
49
- except json .JSONDecodeError as e :
50
- raise RuntimeError (f"Failed to parse JSON: { e } " )
44
+ return json .loads (dumped_result .read_bytes ())["paths" ]
0 commit comments