From 348ebadb8252222b64facf94b76ea2d6531a33e8 Mon Sep 17 00:00:00 2001 From: astaric Date: Fri, 20 Oct 2017 16:09:00 +0200 Subject: [PATCH] add-ons: Fix conda commands As some commands are case sensitive and other not, always normalize package names to lowercase. When uninstalling, run pip uninstall only when that package could not be uninstalled with conda. --- Orange/canvas/application/addons.py | 43 +++++++++++++++++++---------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/Orange/canvas/application/addons.py b/Orange/canvas/application/addons.py index 2c15bd7dfd1..940eef4cb60 100644 --- a/Orange/canvas/application/addons.py +++ b/Orange/canvas/application/addons.py @@ -776,20 +776,24 @@ def _next(self): self.setStatusMessage( "Installing {}".format(pkg.installable.name)) if self.conda: - self.conda.install(pkg.installable) + self.conda.install(pkg.installable, raise_on_fail=False) self.pip.install(pkg.installable) elif command == Upgrade: self.setStatusMessage( "Upgrading {}".format(pkg.installable.name)) if self.conda: - self.conda.upgrade(pkg.installable) + self.conda.upgrade(pkg.installable, raise_on_fail=False) self.pip.upgrade(pkg.installable) elif command == Uninstall: self.setStatusMessage( "Uninstalling {}".format(pkg.local.project_name)) if self.conda: - self.conda.uninstall(pkg.local) - self.pip.uninstall(pkg.local) + try: + self.conda.uninstall(pkg.local, raise_on_fail=True) + except CommandFailed: + self.pip.uninstall(pkg.local) + else: + self.pip.uninstall(pkg.local) except CommandFailed as ex: self.error.emit( "Command failed: python {}".format(ex.cmd), @@ -885,17 +889,26 @@ def _find_conda(self): os.environ["CONDA_DEFAULT_ENV"] = bin return conda - def install(self, pkg): - cmd = ["conda", "install", "--yes", "--quiet", pkg.name] - run_command(cmd, raise_on_fail=False) - - def upgrade(self, pkg): - cmd = ["conda", "upgrade", "--yes", "--quiet", pkg.name] - run_command(cmd, raise_on_fail=False) - - def uninstall(self, dist): - cmd = ["conda", "uninstall", "--yes", dist.project_name] - run_command(cmd, raise_on_fail=False) + def install(self, pkg, raise_on_fail=False): + cmd = ["conda", "install", "--yes", "--quiet", + self._normalize(pkg.name)] + run_command(cmd, raise_on_fail=raise_on_fail) + + def upgrade(self, pkg, raise_on_fail=False): + cmd = ["conda", "upgrade", "--yes", "--quiet", + self._normalize(pkg.name)] + run_command(cmd, raise_on_fail=raise_on_fail) + + def uninstall(self, dist, raise_on_fail=False): + cmd = ["conda", "uninstall", "--yes", + self._normalize(dist.project_name)] + run_command(cmd, raise_on_fail=raise_on_fail) + + def _normalize(self, name): + # Conda 4.3.30 is inconsistent, upgrade command is case sensitive + # while install and uninstall are not. We assume that all conda + # package names are lowercase which fixes the problems (for now) + return name.lowercase() def __bool__(self): return bool(self.conda)