diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-01-18 13:17:01 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-01-18 13:54:36 +0100 |
commit | abc412145c4dd2c659f783ae22f8915a39b01f1a (patch) | |
tree | 8feb0aa8c7df7f750b608291c9c666c083b000a0 /build_scripts | |
parent | 89a65deec3a4fd6e9e843283109c70f0b2fb8a13 (diff) |
qp5_tool: Add warning when the configured python binary is not under virtual env
On Windows, the virtual env needs to be created by the debug binary
python_d.exe in case of debug.
When changing the configuration to release, it can happen that
the system binary is used, which will then install to the system
Python and cause strange errors.
Change-Id: Ie3faf5d5f6a4cee3faec066f45cb3c6cbba416f5
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'build_scripts')
-rw-r--r-- | build_scripts/qp5_tool.py | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/build_scripts/qp5_tool.py b/build_scripts/qp5_tool.py index c45bae350..ad74edf47 100644 --- a/build_scripts/qp5_tool.py +++ b/build_scripts/qp5_tool.py @@ -268,11 +268,22 @@ def read_config_modules_argument(): def read_config_python_binary(): binary = read_config(PYTHON_KEY) - if binary: - return binary - # Use 'python3' unless virtualenv is set - use_py3 = (not os.environ.get('VIRTUAL_ENV') and which('python3')) - return 'python3' if use_py3 else 'python' + virtual_env = os.environ.get('VIRTUAL_ENV') + if not binary: + # Use 'python3' unless virtualenv is set + use_py3 = not virtual_env and which('python3') + binary = 'python3' if use_py3 else 'python' + if not os.path.isabs(binary): + abs_path = which(binary) + if abs_path: + binary = abs_path + else: + warnings.warn(f'Unable to find "{binary}"', RuntimeWarning) + if virtual_env: + if not binary.startswith(virtual_env): + w = f'Python "{binary}" is not under VIRTUAL_ENV "{virtual_env}"' + warnings.warn(w, RuntimeWarning) + return binary def get_config_file(base_name): |