aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2023-03-10 09:21:03 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-03-10 20:00:40 +0000
commitec9b16d3ba28c9d87f78bab41d4cb503f1f1fd72 (patch)
tree685fc74c5d1d4f0fdbf549c0c4c0d54bba422d37
parent2fee56b745dc4f39497b2cee4d338cb5196260d6 (diff)
pyside6-designer: Fix Python plugins to work with non-activated virtual environment
Set the VIRTUAL_ENV variable in case it is missing. Fixes: PYSIDE-2251 Change-Id: Iecd6c8d71d99987f0f4c03c5f974d2229ddbea40 Reviewed-by: Christian Tismer <tismer@stackless.com> (cherry picked from commit 9e5596222e87c9991771070abad96f22c33190b1) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--sources/pyside-tools/pyside_tool.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/sources/pyside-tools/pyside_tool.py b/sources/pyside-tools/pyside_tool.py
index 34c32c0e0..e06a4eaac 100644
--- a/sources/pyside-tools/pyside_tool.py
+++ b/sources/pyside-tools/pyside_tool.py
@@ -12,6 +12,21 @@ from subprocess import Popen, PIPE
import PySide6 as ref_mod
+VIRTUAL_ENV = "VIRTUAL_ENV"
+
+
+def is_virtual_env():
+ return sys.prefix != sys.base_prefix
+
+
+def init_virtual_env():
+ """PYSIDE-2251: Enable running from a non-activated virtual environment
+ as is the case for Visual Studio Code by setting the VIRTUAL_ENV
+ variable which is used by the Qt Designer plugin."""
+ if is_virtual_env() and not os.environ.get(VIRTUAL_ENV):
+ os.environ[VIRTUAL_ENV] = sys.prefix
+
+
def main():
# This will take care of "pyside6-lupdate" listed as an entrypoint
# in setup.py are copied to 'scripts/..'
@@ -113,6 +128,8 @@ def designer():
# PySide6/scripts.
pyside_dir = Path(__file__).resolve().parents[1]
+ init_virtual_env()
+
# https://www.python.org/dev/peps/pep-0384/#linkage :
# "On Unix systems, the ABI is typically provided by the python executable
# itself", that is, libshiboken does not link against any Python library
@@ -136,7 +153,7 @@ def designer():
os.environ['DYLD_INSERT_LIBRARIES'] = lib_path
elif sys.platform == 'win32':
# Find Python DLLs from the base installation
- if os.environ.get("VIRTUAL_ENV"):
+ if is_virtual_env():
_append_to_path_var("PATH", os.fspath(Path(sys._base_executable).parent))
# Add the Wiggly Widget example
wiggly_dir = os.fspath(pyside_dir / 'examples' / 'widgetbinding')