addon manager: use get_python_exe from utils file

This commit is contained in:
Pesc0
2023-07-11 15:57:48 +02:00
parent 0e6ec6e3ac
commit be6ed4670b
6 changed files with 7 additions and 70 deletions

View File

@@ -270,38 +270,6 @@ installed addons will be checked for available updates
</item>
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="fclabel">
<property name="text">
<string>Path to Python executable (optional):</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="Gui::PrefFileChooser" name="gui::preffilechooser" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>300</width>
<height>0</height>
</size>
</property>
<property name="toolTip">
<string>The path to the Python executable for package installation with pip. Autodetected if needed and not specified.</string>
</property>
<property name="prefEntry" stdset="0">
<cstring>PythonExecutableForPip</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Addons</cstring>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<property name="text">

View File

@@ -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

View File

@@ -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)

View File

@@ -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,

View File

@@ -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()

View File

@@ -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"]