From d94eb62e9f7dd5deb74f489f037022473f12a15f Mon Sep 17 00:00:00 2001 From: Chad Wilson Date: Mon, 25 Nov 2024 12:01:41 +0800 Subject: [PATCH] Only do --user installs if we think we are not in a venv/virtualenv (#409) Signed-off-by: Chad Wilson --- build.py | 11 +++++++---- check_and_install_getgauge.py | 6 +++++- python.json | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/build.py b/build.py index 6114d8d..befca3a 100644 --- a/build.py +++ b/build.py @@ -28,15 +28,18 @@ def install(): plugin_zip = create_zip() call(['gauge', 'uninstall', 'python', '-v', get_version()]) - exit_code = call(['gauge', 'install', 'python', '-f', - os.path.join(BIN, plugin_zip)]) + exit_code = call(['gauge', 'install', 'python', '-f', os.path.join(BIN, plugin_zip)]) generate_package() p = os.listdir("dist")[0] print(f"Installing getgauge package using pip: \n\tpip install dist/{p}") - call([sys.executable, "-m", "pip", "install", - f"dist/{p}", "--upgrade", "--user"]) + install_cmd = [sys.executable, "-m", "pip", "install", f"dist/{p}", "--upgrade"] + if not in_venv(): + install_cmd.append("--user") + call(install_cmd) sys.exit(exit_code) +def in_venv(): + return sys.prefix != sys.base_prefix def create_setup_file(): with open("setup.tmpl", "r", encoding="utf-8") as tmpl: diff --git a/check_and_install_getgauge.py b/check_and_install_getgauge.py index b61787a..e7b2289 100644 --- a/check_and_install_getgauge.py +++ b/check_and_install_getgauge.py @@ -14,11 +14,15 @@ def get_version(): return '' def install_getgauge(getgauge_version): - install_cmd = [sys.executable, "-m", "pip", "install", getgauge_version, "--user"] + install_cmd = [sys.executable, "-m", "pip", "install", getgauge_version] + if not in_venv(): + install_cmd.append("--user") if "dev" in getgauge_version: install_cmd.append("--pre") check_output([" ".join(install_cmd)], shell=True) +def in_venv(): + return sys.prefix != sys.base_prefix def assert_versions(): python_plugin_version = get_version() diff --git a/python.json b/python.json index e64bace..b21d717 100644 --- a/python.json +++ b/python.json @@ -1,6 +1,6 @@ { "id": "python", - "version": "0.4.7", + "version": "0.4.8", "description": "Python support for gauge", "run": { "windows": [