Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f861328

Browse files
authoredJun 16, 2022
More reliable way to get Blender's Python interpreter path (#70)
* More reliable way to get Python Blender interpreter path * Test against latest versions in CI * Blender 3.3.0 hangs download * Comment job
1 parent 2fcfb14 commit f861328

File tree

6 files changed

+55
-19
lines changed

6 files changed

+55
-19
lines changed
 

‎.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 3.0.2
2+
current_version = 3.0.3
33

44
[bumpversion:file:pytest_blender/__init__.py]
55

‎.github/workflows/ci.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
# Test previous Blender versions
2828
- platform: ubuntu-latest
2929
pytest-version: '7.1.2'
30-
blender-version: '2.83.9'
30+
blender-version: '2.83.20'
3131
python-version: '3.8'
3232
- platform: ubuntu-latest
3333
pytest-version: '7.1.2'
@@ -41,8 +41,17 @@ jobs:
4141
# Test against Pytest v6
4242
- platform: ubuntu-latest
4343
pytest-version: '6.2.5'
44-
blender-version: '2.93.8'
44+
blender-version: '2.93.9'
4545
python-version: '3.9'
46+
# Latest Blender (Py311)
47+
#
48+
# FIXME: Blender uses for 3.2.0 Python3.10,
49+
# but the pytest-cov test fails because
50+
# it does not show coverage:
51+
#- platform: ubuntu-latest
52+
# pytest-version: '7.1.2'
53+
# blender-version: '3.2.0'
54+
# python-version: '3.11-dev'
4655
# Test in MacOS (Py310)
4756
- platform: macos-latest
4857
pytest-version: '7.1.2'

‎pytest_blender/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "3.0.2"
1+
__version__ = "3.0.3"
22

33
from pytest_blender.utils import (
44
get_addons_dir,

‎pytest_blender/__main__.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
import sys
33

44
from pytest_blender import __version__
5-
from pytest_blender.utils import get_blender_binary_path_python, which_blender
5+
from pytest_blender.utils import (
6+
GetPythonBlenderPathError,
7+
get_blender_binary_path_python,
8+
which_blender,
9+
)
610

711

812
__description__ = "Show a Blender's builtin Python interpreter location."
@@ -44,10 +48,14 @@ def parse_args(args):
4448

4549
def run(args):
4650
opts = parse_args(args)
47-
blender_python = get_blender_binary_path_python(opts.blender_executable)
48-
sys.stdout.write(f"{blender_python}\n")
49-
50-
return 0
51+
try:
52+
blender_python = get_blender_binary_path_python(opts.blender_executable)
53+
except GetPythonBlenderPathError as exc:
54+
sys.stderr.write(f"{exc.args[0]}\n")
55+
return 1
56+
else:
57+
sys.stdout.write(f"{blender_python}\n")
58+
return 0
5159

5260

5361
def main():

‎pytest_blender/utils.py

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
import os
2+
import pprint
23
import shutil
34
import subprocess
45
import sys
56
import zipfile
67

78

9+
PYTEST_BLENDER_NEW_ISSUE_URL = (
10+
"https://github.com/mondeja/pytest-blender/issues/new/choose"
11+
)
812
ZIP_ROOTS_IGNORE = [".DStore", ".git", ".gitignore", "__pycache__"]
913

1014

15+
class PytestBlenderException(Exception):
16+
pass
17+
18+
19+
class GetPythonBlenderPathError(PytestBlenderException):
20+
pass
21+
22+
1123
def zipify_addon_package(in_dirpath, out_dirpath):
1224
zipped_path = os.path.join(
1325
out_dirpath,
@@ -81,10 +93,11 @@ def get_blender_binary_path_python(blender_executable, blend_version=None):
8193
"""
8294
if blend_version is None:
8395
blend_version = get_blender_version(blender_executable)
96+
id_string = "BLENDER-PYTHON-PATH:"
8497
python_expr = (
85-
"import sys;print(sys.executable);"
98+
f"import sys;print('{id_string}',sys.executable);"
8699
if parse_version(blend_version) >= (2, 91)
87-
else "import bpy;print(bpy.app.binary_path_python)"
100+
else f"import bpy;print('{id_string}',bpy.app.binary_path_python)"
88101
)
89102

90103
stdout = subprocess.check_output(
@@ -99,14 +112,20 @@ def get_blender_binary_path_python(blender_executable, blend_version=None):
99112

100113
blender_python_path = None
101114
for line in stdout.decode("utf-8").splitlines():
102-
# this should be enough to support Windows and Unix based systems
103-
if (
104-
os.path.exists(line)
105-
and not os.path.isdir(line)
106-
and "py" in os.path.basename(line.lower())
107-
):
108-
blender_python_path = line
115+
if line.startswith(id_string):
116+
blender_python_path = line.split(" ", maxsplit=1)[1]
109117
break
118+
if blender_python_path is None:
119+
debugging_data = {
120+
"platform": sys.platform,
121+
"blender_executable": blender_executable,
122+
"stdout": stdout,
123+
}
124+
raise GetPythonBlenderPathError(
125+
"Failed to retrieve the Blender's Python interpreter path."
126+
f" Please, submit a report at {PYTEST_BLENDER_NEW_ISSUE_URL}"
127+
f" including the next data:\n{pprint.pformat(debugging_data)}"
128+
)
110129
return blender_python_path
111130

112131

‎setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = pytest_blender
3-
version = 3.0.2
3+
version = 3.0.3
44
description = Blender Pytest plugin.
55
long_description = file: README.md
66
long_description_content_type = text/markdown

0 commit comments

Comments
 (0)
Please sign in to comment.