From be6ed4670bc16c980577ef2c2317ddb687ce470e Mon Sep 17 00:00:00 2001 From: Pesc0 Date: Tue, 11 Jul 2023 15:57:48 +0200 Subject: [PATCH] addon manager: use get_python_exe from utils file --- src/Mod/AddonManager/AddonManagerOptions.ui | 32 ----------------- .../addonmanager_dependency_installer.py | 4 ++- src/Mod/AddonManager/addonmanager_devmode.py | 3 +- .../addonmanager_preferences_defaults.json | 1 - .../AddonManager/addonmanager_utilities.py | 34 ------------------- .../manage_python_dependencies.py | 3 +- 6 files changed, 7 insertions(+), 70 deletions(-) diff --git a/src/Mod/AddonManager/AddonManagerOptions.ui b/src/Mod/AddonManager/AddonManagerOptions.ui index 7460e591ef..c935646f72 100644 --- a/src/Mod/AddonManager/AddonManagerOptions.ui +++ b/src/Mod/AddonManager/AddonManagerOptions.ui @@ -270,38 +270,6 @@ installed addons will be checked for available updates - - - - Path to Python executable (optional): - - - - - - - - 0 - 0 - - - - - 300 - 0 - - - - The path to the Python executable for package installation with pip. Autodetected if needed and not specified. - - - PythonExecutableForPip - - - Addons - - - diff --git a/src/Mod/AddonManager/addonmanager_dependency_installer.py b/src/Mod/AddonManager/addonmanager_dependency_installer.py index ccff230cf1..466809e2de 100644 --- a/src/Mod/AddonManager/addonmanager_dependency_installer.py +++ b/src/Mod/AddonManager/addonmanager_dependency_installer.py @@ -27,6 +27,8 @@ import os import subprocess from typing import List +from freecad.utils import get_python_exe + import addonmanager_freecad_interface as fci from addonmanager_pyside_interface import QObject, Signal, is_interruption_requested @@ -170,7 +172,7 @@ class DependencyInstaller(QObject): def _get_python(self) -> str: """Wrap Python access so test code can mock it.""" - python_exe = utils.get_python_exe() + python_exe = get_python_exe() if not python_exe: self.no_python_exe.emit() return python_exe diff --git a/src/Mod/AddonManager/addonmanager_devmode.py b/src/Mod/AddonManager/addonmanager_devmode.py index 87aae2d00b..860b9ab934 100644 --- a/src/Mod/AddonManager/addonmanager_devmode.py +++ b/src/Mod/AddonManager/addonmanager_devmode.py @@ -29,6 +29,7 @@ import subprocess import FreeCAD import FreeCADGui +from freecad.utils import get_python_exe from PySide.QtWidgets import ( QFileDialog, @@ -618,7 +619,7 @@ class DeveloperMode: FreeCAD.Console.PrintMessage( translate("AddonsInstaller", "Attempting to install Vermin from PyPi") + "...\n" ) - python_exe = utils.get_python_exe() + python_exe = get_python_exe() vendor_path = os.path.join(FreeCAD.getUserAppDataDir(), "AdditionalPythonPackages") if not os.path.exists(vendor_path): os.makedirs(vendor_path) diff --git a/src/Mod/AddonManager/addonmanager_preferences_defaults.json b/src/Mod/AddonManager/addonmanager_preferences_defaults.json index 2602c566f7..99a953bc55 100644 --- a/src/Mod/AddonManager/addonmanager_preferences_defaults.json +++ b/src/Mod/AddonManager/addonmanager_preferences_defaults.json @@ -25,7 +25,6 @@ "PrimaryAddonsSubmoduleURL": "https://raw.githubusercontent.com/FreeCAD/FreeCAD-addons/master/.gitmodules", "ProxyUrl": "", - "PythonExecutableForPip": "Not set", "RemoteIconCacheURL": "https://addons.freecad.org/icon_cache.zip", "SelectedAddon": "", "ShowBranchSwitcher": false, diff --git a/src/Mod/AddonManager/addonmanager_utilities.py b/src/Mod/AddonManager/addonmanager_utilities.py index 5d71023d34..9ceabc2e9a 100644 --- a/src/Mod/AddonManager/addonmanager_utilities.py +++ b/src/Mod/AddonManager/addonmanager_utilities.py @@ -345,40 +345,6 @@ def is_float(element: Any) -> bool: return False -def get_python_exe() -> str: - """Find Python. In preference order - A) The value of the PythonExecutableForPip user preference - B) The executable located in the same bin directory as FreeCAD and called "python3" - C) The executable located in the same bin directory as FreeCAD and called "python" - D) The result of a shutil search for your system's "python3" executable - E) The result of a shutil search for your system's "python" executable""" - prefs = fci.ParamGet("User parameter:BaseApp/Preferences/Addons") - python_exe = prefs.GetString("PythonExecutableForPip", "Not set") - fc_dir = fci.DataPaths().home_dir - if not python_exe or python_exe == "Not set" or not os.path.exists(python_exe): - python_exe = os.path.join(fc_dir, "bin", "python3") - if "Windows" in platform.system(): - python_exe += ".exe" - - if not python_exe or not os.path.exists(python_exe): - python_exe = os.path.join(fc_dir, "bin", "python") - if "Windows" in platform.system(): - python_exe += ".exe" - - if not python_exe or not os.path.exists(python_exe): - python_exe = shutil.which("python3") - - if not python_exe or not os.path.exists(python_exe): - python_exe = shutil.which("python") - - if not python_exe or not os.path.exists(python_exe): - return "" - - python_exe = python_exe.replace("/", os.path.sep) - prefs.SetString("PythonExecutableForPip", python_exe) - return python_exe - - def get_pip_target_directory(): # Get the default location to install new pip packages major, minor, _ = platform.python_version_tuple() diff --git a/src/Mod/AddonManager/manage_python_dependencies.py b/src/Mod/AddonManager/manage_python_dependencies.py index 24108d571a..4b42cd9298 100644 --- a/src/Mod/AddonManager/manage_python_dependencies.py +++ b/src/Mod/AddonManager/manage_python_dependencies.py @@ -36,6 +36,7 @@ from typing import Dict, List, Tuple import FreeCAD import FreeCADGui +from freecad.utils import get_python_exe from PySide import QtCore, QtGui, QtWidgets import addonmanager_utilities as utils @@ -89,7 +90,7 @@ def call_pip(args) -> List[str]: """Tries to locate the appropriate Python executable and run pip with version checking disabled. Fails if Python can't be found or if pip is not installed.""" - python_exe = utils.get_python_exe() + python_exe = get_python_exe() pip_failed = False if python_exe: call_args = [python_exe, "-m", "pip", "--disable-pip-version-check"]