From 98b512b32e376b1f6422f0664cc421e02b1545c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Thu, 11 Feb 2016 09:38:09 +0100 Subject: [PATCH 1/4] Correctly handle pip 1.1 --- src/octoprint/util/pip.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/octoprint/util/pip.py b/src/octoprint/util/pip.py index 083741d1a..46b667da2 100644 --- a/src/octoprint/util/pip.py +++ b/src/octoprint/util/pip.py @@ -161,13 +161,9 @@ class PipCaller(CommandlineCaller): if pip_command is None: return - pip_command_str = pip_command - if isinstance(pip_command_str, list): - pip_command_str = " ".join(pip_command_str) - # Determine the pip version - self._logger.debug("Found pip at {}, going to figure out its version".format(pip_command_str)) + self._logger.debug("Going to figure out pip's version") pip_version, version_segment = self._get_pip_version(pip_command) if pip_version is None: @@ -177,7 +173,7 @@ class PipCaller(CommandlineCaller): self._logger.error("This version of pip is known to have bugs that make it incompatible with how it needs to be used by OctoPrint. Please upgrade your pip version.") return - self._logger.info("Version of pip \"{}\" is {}".format(pip_command_str, version_segment)) + self._logger.info("Version of pip is {}".format(version_segment)) # Now figure out if pip belongs to a virtual environment and if the # default installation directory is writable. @@ -195,13 +191,12 @@ class PipCaller(CommandlineCaller): ok, pip_user, pip_virtual_env, pip_install_dir = self._check_pip_setup(pip_command) if not ok: - self._logger.error("Cannot use pip \"{}\"".format(pip_command_str)) + self._logger.error("Cannot use pip") return - self._logger.info("pip \"{}\" installs to {}, --user flag needed => {}, virtual env => {}".format(pip_command_str, - pip_install_dir, - "yes" if pip_user else "no", - "yes" if pip_virtual_env else "no")) + self._logger.info("pip installs to {}, --user flag needed => {}, virtual env => {}".format(pip_install_dir, + "yes" if pip_user else "no", + "yes" if pip_virtual_env else "no")) self._command = pip_command self._version = pip_version @@ -227,7 +222,16 @@ class PipCaller(CommandlineCaller): @classmethod def autodetect_pip(cls): - return [sys.executable, "-m", "pip"] + commands = [[sys.executable, "-m", "pip"], + [sys.executable, "-c", "import sys; sys.argv = ['pip'] + sys.argv[1:]; import pip; pip.main()"]] + + for command in commands: + p = sarge.run(command + ["--version"], stdout=sarge.Capture(), stderr=sarge.Capture()) + if p.returncode == 0: + logging.getLogger(__name__).info("Using \"{}\" as command to invoke pip".format(" ".join(command))) + return command + + return None @classmethod def to_sarge_command(cls, pip_command, *args): From b2391322d4db6b36be7814f49d8e3e105f3082a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Thu, 11 Feb 2016 09:38:35 +0100 Subject: [PATCH 2/4] Removed sudo stuff from plugin manager, don't display full pip command --- src/octoprint/plugins/pluginmanager/__init__.py | 5 ++--- .../pluginmanager/static/js/pluginmanager.js | 11 ++--------- .../templates/pluginmanager_settings.jinja2 | 16 ++-------------- 3 files changed, 6 insertions(+), 26 deletions(-) diff --git a/src/octoprint/plugins/pluginmanager/__init__.py b/src/octoprint/plugins/pluginmanager/__init__.py index 7f51f74f1..3bdffeb56 100644 --- a/src/octoprint/plugins/pluginmanager/__init__.py +++ b/src/octoprint/plugins/pluginmanager/__init__.py @@ -188,13 +188,12 @@ class PluginManagerPlugin(octoprint.plugin.SimpleApiPlugin, octoprint=self._get_octoprint_version_string(), pip=dict( available=self._pip_caller.available, - command=self._pip_caller.command, version=self._pip_caller.version_string, install_dir=self._pip_caller.install_dir, - use_sudo=self._pip_caller.use_sudo, use_user=self._pip_caller.use_user, virtual_env=self._pip_caller.virtual_env, - additional_args=self._settings.get(["pip_args"]) + additional_args=self._settings.get(["pip_args"]), + python=sys.executable )) def on_api_command(self, command, data): diff --git a/src/octoprint/plugins/pluginmanager/static/js/pluginmanager.js b/src/octoprint/plugins/pluginmanager/static/js/pluginmanager.js index ae574e997..7b6ac5202 100644 --- a/src/octoprint/plugins/pluginmanager/static/js/pluginmanager.js +++ b/src/octoprint/plugins/pluginmanager/static/js/pluginmanager.js @@ -148,17 +148,13 @@ $(function() { self.followDependencyLinks = ko.observable(false); self.pipAvailable = ko.observable(false); - self.pipCommand = ko.observable(); self.pipVersion = ko.observable(); self.pipInstallDir = ko.observable(); self.pipUseUser = ko.observable(); - self.pipUseSudo = ko.observable(); self.pipVirtualEnv = ko.observable(); self.pipAdditionalArgs = ko.observable(); + self.pipPython = ko.observable(); - self.pipUseSudoString = ko.pureComputed(function() { - return self.pipUseSudo() ? "yes" : "no"; - }); self.pipUseUserString = ko.pureComputed(function() { return self.pipUseUser() ? "yes" : "no"; }); @@ -305,19 +301,16 @@ $(function() { self._fromPipResponse = function(data) { self.pipAvailable(data.available); if (data.available) { - self.pipCommand(data.command); self.pipVersion(data.version); self.pipInstallDir(data.install_dir); self.pipUseUser(data.use_user); - self.pipUseSudo(data.use_sudo); self.pipVirtualEnv(data.virtual_env); self.pipAdditionalArgs(data.additional_args); + self.pipPython(data.python); } else { - self.pipCommand(undefined); self.pipVersion(undefined); self.pipInstallDir(undefined); self.pipUseUser(undefined); - self.pipUseSudo(undefined); self.pipVirtualEnv(undefined); self.pipAdditionalArgs(undefined); } diff --git a/src/octoprint/plugins/pluginmanager/templates/pluginmanager_settings.jinja2 b/src/octoprint/plugins/pluginmanager/templates/pluginmanager_settings.jinja2 index 926847a5f..0358cf3a8 100644 --- a/src/octoprint/plugins/pluginmanager/templates/pluginmanager_settings.jinja2 +++ b/src/octoprint/plugins/pluginmanager/templates/pluginmanager_settings.jinja2 @@ -13,19 +13,8 @@ {% endtrans %} {% endmacro %} -{% macro pluginmanager_sudopip() %} -
{% trans %} - The pip command is configured to use sudo. This - is not recommended due to security reasons. It is strongly - suggested you install OctoPrint under a - user-owned virtual environment - so that the use of sudo is not needed for plugin management. -{% endtrans %}
-{% endmacro %} - {{ pluginmanager_printing() }} {{ pluginmanager_nopip() }} -{{ pluginmanager_sudopip() }}
@@ -76,13 +65,13 @@
- Using pip at "", Version + Using pip of "", Version
- Installation directory: ("--user" flag: , sudo: )
+ Installation directory: ("--user" flag: )
Virtual environment:
Additional Arguments:
@@ -110,7 +99,6 @@