Skip to content

Commit 348ebad

Browse files
committed
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.
1 parent 0ed37c2 commit 348ebad

File tree

1 file changed

+28
-15
lines changed

1 file changed

+28
-15
lines changed

Orange/canvas/application/addons.py

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -776,20 +776,24 @@ def _next(self):
776776
self.setStatusMessage(
777777
"Installing {}".format(pkg.installable.name))
778778
if self.conda:
779-
self.conda.install(pkg.installable)
779+
self.conda.install(pkg.installable, raise_on_fail=False)
780780
self.pip.install(pkg.installable)
781781
elif command == Upgrade:
782782
self.setStatusMessage(
783783
"Upgrading {}".format(pkg.installable.name))
784784
if self.conda:
785-
self.conda.upgrade(pkg.installable)
785+
self.conda.upgrade(pkg.installable, raise_on_fail=False)
786786
self.pip.upgrade(pkg.installable)
787787
elif command == Uninstall:
788788
self.setStatusMessage(
789789
"Uninstalling {}".format(pkg.local.project_name))
790790
if self.conda:
791-
self.conda.uninstall(pkg.local)
792-
self.pip.uninstall(pkg.local)
791+
try:
792+
self.conda.uninstall(pkg.local, raise_on_fail=True)
793+
except CommandFailed:
794+
self.pip.uninstall(pkg.local)
795+
else:
796+
self.pip.uninstall(pkg.local)
793797
except CommandFailed as ex:
794798
self.error.emit(
795799
"Command failed: python {}".format(ex.cmd),
@@ -885,17 +889,26 @@ def _find_conda(self):
885889
os.environ["CONDA_DEFAULT_ENV"] = bin
886890
return conda
887891

888-
def install(self, pkg):
889-
cmd = ["conda", "install", "--yes", "--quiet", pkg.name]
890-
run_command(cmd, raise_on_fail=False)
891-
892-
def upgrade(self, pkg):
893-
cmd = ["conda", "upgrade", "--yes", "--quiet", pkg.name]
894-
run_command(cmd, raise_on_fail=False)
895-
896-
def uninstall(self, dist):
897-
cmd = ["conda", "uninstall", "--yes", dist.project_name]
898-
run_command(cmd, raise_on_fail=False)
892+
def install(self, pkg, raise_on_fail=False):
893+
cmd = ["conda", "install", "--yes", "--quiet",
894+
self._normalize(pkg.name)]
895+
run_command(cmd, raise_on_fail=raise_on_fail)
896+
897+
def upgrade(self, pkg, raise_on_fail=False):
898+
cmd = ["conda", "upgrade", "--yes", "--quiet",
899+
self._normalize(pkg.name)]
900+
run_command(cmd, raise_on_fail=raise_on_fail)
901+
902+
def uninstall(self, dist, raise_on_fail=False):
903+
cmd = ["conda", "uninstall", "--yes",
904+
self._normalize(dist.project_name)]
905+
run_command(cmd, raise_on_fail=raise_on_fail)
906+
907+
def _normalize(self, name):
908+
# Conda 4.3.30 is inconsistent, upgrade command is case sensitive
909+
# while install and uninstall are not. We assume that all conda
910+
# package names are lowercase which fixes the problems (for now)
911+
return name.lowercase()
899912

900913
def __bool__(self):
901914
return bool(self.conda)

0 commit comments

Comments
 (0)