diff --git a/docs/bundledplugins/softwareupdate.rst b/docs/bundledplugins/softwareupdate.rst index 574770f2b..bb675ff86 100644 --- a/docs/bundledplugins/softwareupdate.rst +++ b/docs/bundledplugins/softwareupdate.rst @@ -338,6 +338,15 @@ supported: Additional config parameters: * ``pip``: The URL to use for installing. Presence implies ``method: pip``. + * ``pip_command``: The command to use for installing. Defaults to the ``pip`` instance belong to OctoPrint's environment. + * ``pip_cwd``: The working directory to use for installing. Defaults to the current working directory. + * ``force_reinstall``: Whether to force reinstallation of the package. Defaults to ``false``. Helpful + for development and version checks that don't guarantee a Python package version change (e.g. commit based + version checks like ``git_commit``, ``github_commit``, ``bitbucket_commit``). + + .. versionchanged:: 1.8.0 + + Added ``force_reinstall`` parameter. * ``single_file_plugin``: Update a single file plugin by re-downloading it from a configured URL. Additional config parameters: diff --git a/src/octoprint/plugins/softwareupdate/__init__.py b/src/octoprint/plugins/softwareupdate/__init__.py index 679ff90a9..8a9b7db8d 100644 --- a/src/octoprint/plugins/softwareupdate/__init__.py +++ b/src/octoprint/plugins/softwareupdate/__init__.py @@ -2074,7 +2074,12 @@ class SoftwareUpdatePlugin( raise exceptions.UnknownUpdateType() update_result = updater.perform_update( - target, populated_check, target_version, log_cb=self._log, online=online + target, + populated_check, + target_version, + log_cb=self._log, + online=online, + force=force, ) target_result = ("success", update_result) self._logger.info( diff --git a/src/octoprint/plugins/softwareupdate/updaters/pip.py b/src/octoprint/plugins/softwareupdate/updaters/pip.py index 61923ac5b..b344d789c 100644 --- a/src/octoprint/plugins/softwareupdate/updaters/pip.py +++ b/src/octoprint/plugins/softwareupdate/updaters/pip.py @@ -71,6 +71,8 @@ def perform_update(target, check, target_version, log_cb=None, online=True, forc if not online and not check.get("offline", False): raise exceptions.CannotUpdateOffline() + force = force or check.get("force_reinstall", False) + pip_caller = _get_pip_caller(command=pip_command) if pip_caller is None: raise exceptions.UpdateError("Can't run pip", None) diff --git a/src/octoprint/plugins/softwareupdate/updaters/python_updater.py b/src/octoprint/plugins/softwareupdate/updaters/python_updater.py index f78bdbb1d..f552ee2ef 100644 --- a/src/octoprint/plugins/softwareupdate/updaters/python_updater.py +++ b/src/octoprint/plugins/softwareupdate/updaters/python_updater.py @@ -15,24 +15,26 @@ def can_perform_update(target, check, online=True): ) -def perform_update(target, check, target_version, log_cb=None, online=True): +def perform_update(target, check, target_version, log_cb=None, online=True, force=False): from ..exceptions import CannotUpdateOffline if not online and not check("offline", False): raise CannotUpdateOffline() + kwargs = {"log_cb": log_cb, "online": online, "force": force} try: return check["python_updater"].perform_update( - target, check, target_version, log_cb=log_cb, online=online + target, check, target_version, **kwargs ) except Exception: import inspect args, _, _, _ = inspect.getargspec(check["python_updater"].perform_update) - if "online" not in args: - # old python_updater footprint, simply leave out the online parameter + if not all(k in args for k in kwargs): + # old python_updater footprint, leave out what it doesn't understand + old_kwargs = {k: v for k, v in kwargs.items() if k in args} return check["python_updater"].perform_update( - target, check, target_version, log_cb=log_cb + target, check, target_version, **old_kwargs ) # some other error, raise again diff --git a/src/octoprint/plugins/softwareupdate/updaters/sleep_a_bit.py b/src/octoprint/plugins/softwareupdate/updaters/sleep_a_bit.py index 6d3b74c7c..7ea45cc6a 100644 --- a/src/octoprint/plugins/softwareupdate/updaters/sleep_a_bit.py +++ b/src/octoprint/plugins/softwareupdate/updaters/sleep_a_bit.py @@ -14,7 +14,7 @@ def can_perform_update(target, check, online=True): return True -def perform_update(target, check, target_version, log_cb=None, online=True): +def perform_update(target, check, target_version, log_cb=None, online=True, force=False): duration = check.get("duration", 30) now = monotonic_time() diff --git a/src/octoprint/plugins/softwareupdate/updaters/update_script.py b/src/octoprint/plugins/softwareupdate/updaters/update_script.py index e2a3465a6..b7e115c6f 100644 --- a/src/octoprint/plugins/softwareupdate/updaters/update_script.py +++ b/src/octoprint/plugins/softwareupdate/updaters/update_script.py @@ -55,7 +55,7 @@ def can_perform_update(target, check, online=True): ) -def perform_update(target, check, target_version, log_cb=None, online=True): +def perform_update(target, check, target_version, log_cb=None, online=True, force=False): logger = logging.getLogger("octoprint.plugins.softwareupdate.updaters.update_script") if not online and not check("offline", False):