Skip to content

Commit

Permalink
Run python2 version check via subprocess to capture stderr output.
Browse files Browse the repository at this point in the history
  • Loading branch information
wdobbe committed Nov 17, 2023
1 parent d7ad6ca commit 9948787
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions recipes/qt/5.x.x/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import os
import textwrap
import shutil
import subprocess

required_conan_version = ">=1.60.0 <2 || >=2.0.5"

Expand Down Expand Up @@ -148,12 +149,14 @@ def validate_build(self):
"in order to build Qt WebEngine")
raise ConanInvalidConfiguration(msg)

# In any case, check its actual version for compatibility
from six import StringIO # Python 2 and 3 compatible
mybuf = StringIO()
cmd_v = f"\"{python_exe}\" --version 2>&1"
self.run(cmd_v, mybuf)
verstr = mybuf.getvalue().strip().split("Python ")[1]
# In any case, check its actual version for compatibility.
# Note that python2 exe sends its version to stderr instead of stdout.
completed = subprocess.run( [python_exe, '--version'], stderr=subprocess.PIPE,

Check warning on line 154 in recipes/qt/5.x.x/conanfile.py

View workflow job for this annotation

GitHub Actions / Lint changed conanfile.py (v2 migration)

Using subprocess.run without explicitly set `check` is not recommended.
timeout=5 )
if completed.returncode != 0:
msg = ("Found python2 executable %s but could not run it" % python_exe)
raise ConanInvalidConfiguration(msg)
verstr = completed.stderr.decode('utf-8').split("Python ")[1]
if verstr.endswith("+"):
verstr = verstr[:-1]
version = Version(verstr)
Expand All @@ -162,7 +165,7 @@ def validate_build(self):
v_max = "3.0.0"
if (version >= v_min) and (version < v_max):
msg = ("Found valid Python 2 required for QtWebengine:"
f" version={mybuf.getvalue()}, path={python_exe}")
f" version={verstr}, path={python_exe}")
self.output.success(msg)
else:
msg = (f"Found Python 2 in path, but with invalid version {verstr}"
Expand Down Expand Up @@ -370,7 +373,7 @@ def requirements(self):
if self.options.get_safe("with_libpng", False) and not self.options.multiconfiguration:
self.requires("libpng/1.6.40")
if self.options.with_sqlite3 and not self.options.multiconfiguration:
self.requires("sqlite3/3.43.1")
self.requires("sqlite3/3.43.2")
if self.options.get_safe("with_mysql", False):
self.requires("libmysqlclient/8.1.0")
if self.options.with_pq:
Expand Down

0 comments on commit 9948787

Please sign in to comment.