Addon Manager: Create utility function to get pip
This commit is contained in:
committed by
Chris Hennes
parent
e849d8ac2e
commit
b7cfb36665
@@ -25,18 +25,15 @@
|
||||
""" Utilities to work across different platforms, providers and python versions """
|
||||
|
||||
from datetime import datetime
|
||||
from typing import Optional, Any
|
||||
import ctypes
|
||||
from typing import Optional, Any, List
|
||||
import os
|
||||
import platform
|
||||
import re
|
||||
import shutil
|
||||
import stat
|
||||
import subprocess
|
||||
import time
|
||||
import re
|
||||
import ctypes
|
||||
from typing import Optional, Any
|
||||
|
||||
from urllib.parse import urlparse
|
||||
|
||||
@@ -50,6 +47,12 @@ except ImportError:
|
||||
|
||||
import addonmanager_freecad_interface as fci
|
||||
|
||||
try:
|
||||
from freecad.utils import get_python_exe
|
||||
except ImportError:
|
||||
def get_python_exe():
|
||||
return shutil.which("python")
|
||||
|
||||
if fci.FreeCADGui:
|
||||
|
||||
# If the GUI is up, we can use the NetworkManager to handle our downloads. If there is no event
|
||||
@@ -495,3 +498,20 @@ def get_main_am_window():
|
||||
return widget.centralWidget()
|
||||
# Why is this code even getting called?
|
||||
return None
|
||||
|
||||
|
||||
def create_pip_call(args: List[str]) -> List[str]:
|
||||
"""Choose the correct mechanism for calling pip on each platform. It currently supports
|
||||
either `python -m pip` (most environments) or `freecad.pip` (Snap packages). Returns a list
|
||||
of arguments suitable for passing directly to subprocess.Popen and related functions."""
|
||||
snap_package = os.getenv("SNAP_REVISION")
|
||||
if snap_package:
|
||||
call_args = ["freecad.pip", "--disable-pip-version-check"]
|
||||
call_args.extend(args)
|
||||
else:
|
||||
python_exe = get_python_exe()
|
||||
if not python_exe:
|
||||
raise (RuntimeError("Could not locate Python executable on this system"))
|
||||
call_args = [python_exe, "-m", "pip", "--disable-pip-version-check"]
|
||||
call_args.extend(args)
|
||||
return call_args
|
||||
|
||||
Reference in New Issue
Block a user