diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2023-03-10 09:21:03 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2023-03-10 14:35:44 +0100 |
commit | 9e5596222e87c9991771070abad96f22c33190b1 (patch) | |
tree | 4e2f446ee59c5e78ce2eb69e03e9d37137eda765 /sources/pyside-tools | |
parent | c2c11d0678f90ceab601efc386d48a592e405b70 (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
Pick-to: 6.4
Change-Id: Iecd6c8d71d99987f0f4c03c5f974d2229ddbea40
Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/pyside-tools')
-rw-r--r-- | sources/pyside-tools/pyside_tool.py | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/sources/pyside-tools/pyside_tool.py b/sources/pyside-tools/pyside_tool.py index e23921dd4..cc60ab84f 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/..' @@ -115,6 +130,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 @@ -138,7 +155,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') |