✨ Support central local pip command in server.pip

Plugin Manager, Software Update and Backup will use that if set.
Otherwise the old default of using LocalPipCaller is used.

Not exposed via the UI as this REALLY should only be used by people who
know what they are doing and the majority of users out there will never
ever have to use it.

Implements #3700
This commit is contained in:
Gina Häußge committed 2020-11-04 11:41:19 +01:00
1 parent a5e18300ea
commit 4110287349
7 files changed
+58 -19

No files matched your search

+6
View File
@@ -945,6 +945,12 @@ Use the following settings to configure the server:
# Command to shut down the system OctoPrint is running on, defaults to being unset
systemShutdownCommand: sudo shutdown -h now
# pip command associated with OctoPrint, used for installing plugins and updates,
# if unset (default) the command will be autodetected based on the current python
# executable - unless you have a really special setup this is the right way to do
# it and there should be no need to ever even touch this setting
localPipCommand: None
# Configuration of the regular online connectivity check
onlineCheck:
# whether the online check is enabled, defaults to false due to valid privacy concerns
+21 -5
View File
@@ -13,7 +13,7 @@ from octoprint.server import NO_CONTENT
from octoprint.server.util.flask import no_firstrun_access
from octoprint.settings import default_settings
from octoprint.util import is_hidden_path, to_bytes
from octoprint.util.pip import LocalPipCaller
from octoprint.util.pip import create_pip_caller
from octoprint.util.platform import is_os_compatible
from octoprint.util.version import (
get_comparable_version,
@@ -344,7 +344,13 @@ class BackupPlugin(
self._logger.info("Installing plugin {}".format(plugin["id"]))
self._send_client_message("installing_plugin", {"plugin": plugin["id"]})
self.__class__._install_plugin(
plugin, force_user=force_user, pip_args=pip_args, on_log=on_log
plugin,
force_user=force_user,
pip_command=self._settings.global_get(
["server", "commands", "localPipCommand"]
),
pip_args=pip_args,
on_log=on_log,
)
def on_report_unknown_plugins(plugins):
@@ -585,7 +591,13 @@ class BackupPlugin(
click.echo("Installing plugin {}".format(plugin["id"]))
self.__class__._install_plugin(
plugin, force_user=force_user, pip_args=pip_args, on_log=log
plugin,
force_user=force_user,
pip_command=settings.global_get(
["server", "commands", "localPipCommand"]
),
pip_args=pip_args,
on_log=log,
)
def on_report_unknown_plugins(plugins):
@@ -768,7 +780,9 @@ class BackupPlugin(
)
@classmethod
def _install_plugin(cls, plugin, force_user=False, pip_args=None, on_log=None):
def _install_plugin(
cls, plugin, force_user=False, pip_command=None, pip_args=None, on_log=None
):
if pip_args is None:
pip_args = []
@@ -790,7 +804,9 @@ class BackupPlugin(
log("!", *lines)
if cls._pip_caller is None:
cls._pip_caller = LocalPipCaller(force_user=force_user)
cls._pip_caller = create_pip_caller(
command=pip_command, force_user=force_user
)
cls._pip_caller.on_log_call = log_call
cls._pip_caller.on_log_stdout = log_stdout
@@ -38,7 +38,7 @@ from octoprint.server.util.flask import (
from octoprint.settings import valid_boolean_trues
from octoprint.util import TemporaryDirectory, to_bytes, to_native_str
from octoprint.util.net import download_file
from octoprint.util.pip import LocalPipCaller
from octoprint.util.pip import create_pip_caller
from octoprint.util.platform import get_os, is_os_compatible
from octoprint.util.version import (
get_octoprint_version,
@@ -201,8 +201,9 @@ class PluginManagerPlugin(
self._notices_cache_ttl = self._settings.get_int(["notices_ttl"]) * 60
self._confirm_disable = self._settings.global_get_boolean(["confirm_disable"])
self._pip_caller = LocalPipCaller(
force_user=self._settings.get_boolean(["pip_force_user"])
self._pip_caller = create_pip_caller(
command=self._settings.global_get(["server", "commands", "localPipCommand"]),
force_user=self._settings.get_boolean(["pip_force_user"]),
)
self._pip_caller.on_log_call = self._log_call
self._pip_caller.on_log_stdout = self._log_stdout
@@ -33,7 +33,7 @@ from octoprint.server.util.flask import (
with_revalidation_checking,
)
from octoprint.util import dict_merge, get_formatted_size, to_unicode
from octoprint.util.pip import LocalPipCaller
from octoprint.util.pip import create_pip_caller
from octoprint.util.version import get_comparable_version, get_python_version_string
from . import cli, exceptions, updaters, util, version_checks
@@ -292,7 +292,9 @@ class SoftwareUpdatePlugin(
def _check_environment(self):
import pkg_resources
local_pip = LocalPipCaller()
local_pip = create_pip_caller(
command=self._settings.global_get(["server", "commands", "localPipCommand"])
)
# check python and setuptools version
versions = {
@@ -1970,6 +1972,12 @@ class SoftwareUpdatePlugin(
elif check.get("pip", None):
# we force python unequality check for pip installs, to be able to downgrade
result["release_compare"] = "python_unequal"
result["pip_command"] = check.get(
"pip_command",
self._settings.global_get(
["server", "commands", "localPipCommand"]
),
)
elif target == "pip":
import pkg_resources
@@ -1988,6 +1996,11 @@ class SoftwareUpdatePlugin(
displayVersion = distribution.version
result["displayVersion"] = to_unicode(displayVersion, errors="replace")
result["pip_command"] = check.get(
"pip_command",
self._settings.global_get(["server", "commands", "localPipCommand"]),
)
else:
result["displayName"] = to_unicode(check.get("displayName"), errors="replace")
if result["displayName"] is None:
@@ -10,7 +10,7 @@ import logging
import pkg_resources
from octoprint.util.pip import PipCaller, UnknownPip
from octoprint.util.pip import UnknownPip, create_pip_caller
from octoprint.util.version import get_comparable_version
from .. import exceptions
@@ -50,7 +50,7 @@ def _get_pip_caller(command=None):
if key not in _pip_callers:
try:
_pip_callers[key] = PipCaller(configured=command)
_pip_callers[key] = create_pip_caller(command=command)
except UnknownPip:
_pip_callers[key] = None
@@ -58,13 +58,8 @@ def _get_pip_caller(command=None):
def perform_update(target, check, target_version, log_cb=None, online=True, force=False):
pip_command = None
if "pip_command" in check:
pip_command = check["pip_command"]
pip_working_directory = None
if "pip_cwd" in check:
pip_working_directory = check["pip_cwd"]
pip_command = check.get("pip_command")
pip_working_directory = check.get("pip_cwd")
if not online and not check.get("offline", False):
raise exceptions.CannotUpdateOffline()
+1
View File
@@ -204,6 +204,7 @@ default_settings = {
"systemShutdownCommand": None,
"systemRestartCommand": None,
"serverRestartCommand": None,
"localPipCommand": None,
},
"onlineCheck": {
"enabled": None,
+7
View File
@@ -567,3 +567,10 @@ class LocalPipCaller(PipCaller):
self._logger.info("==> pip ok -> {}".format("yes" if ok else "NO!"))
return ok, user_flag, virtual_env, install_dir
def create_pip_caller(command=None, **kwargs):
if command is None:
return LocalPipCaller(**kwargs)
else:
return PipCaller(configured=command, **kwargs)