Skip to content

Commit

Permalink
add-ons: Fix conda commands
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
astaric committed Oct 20, 2017
1 parent 0ed37c2 commit 348ebad
Showing 1 changed file with 28 additions and 15 deletions.
43 changes: 28 additions & 15 deletions Orange/canvas/application/addons.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 348ebad

Please sign in to comment.