Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'python2 --version' sends output to stderr, redirect to stdout to cat… #20979

Closed
wants to merge 9 commits into from
17 changes: 10 additions & 7 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 @@
"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"
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]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
verstr = completed.stderr.decode('utf-8').split("Python ")[1]
verstr = completed.stderr.decode('utf-8').split("Python ")[1].strip()

Just to be safe.

if verstr.endswith("+"):
verstr = verstr[:-1]
version = Version(verstr)
Expand All @@ -162,7 +165,7 @@
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 @@ -925,7 +928,7 @@
filecontents += 'set(CMAKE_AUTOMOC_MACRO_NAMES "Q_OBJECT" "Q_GADGET" "Q_GADGET_EXPORT" "Q_NAMESPACE" "Q_NAMESPACE_EXPORT")\n'
save(self, os.path.join(self.package_folder, self._cmake_core_extras_file), filecontents)

def _create_private_module(module, dependencies=[]):

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

View workflow job for this annotation

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

Dangerous default value [] as argument
if "Core" not in dependencies:
dependencies.append("Core")
dependencies_string = ';'.join(f'Qt5::{dependency}' for dependency in dependencies)
Expand Down Expand Up @@ -994,7 +997,7 @@
reqs.append(corrected_req)
return reqs

def _create_module(module, requires=[], has_include_dir=True):

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

View workflow job for this annotation

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

Dangerous default value [] as argument
componentname = f"qt{module}"
assert componentname not in self.cpp_info.components, f"Module {module} already present in self.cpp_info.components"
self.cpp_info.components[componentname].set_property("cmake_target_name", f"Qt5::{module}")
Expand Down
Loading