Permalink
Browse files

Merge pull request #157 from rbuccigrossi/bf-dont_crash_on_old_conda

BF: Detect and gracefully handle old conda versions
  • Loading branch information...
yarikoptic committed Jan 14, 2018
2 parents 3b58bf2 + 5c46feb commit 63f53949bf57293754eb09bafa12dfa2e4718e8d
Showing with 44 additions and 4 deletions.
  1. +10 −4 niceman/distributions/conda.py
  2. +34 −0 niceman/distributions/tests/test_conda.py
@@ -185,7 +185,7 @@ def _parse_pip_show(out):
def _get_conda_pip_package_details(self, env_export, conda_path):
packages = {}
file_to_package_map = {}
dependencies = env_export.get("dependencies")
dependencies = env_export.get("dependencies", [])
pip_deps = []
for dep in dependencies:
@@ -244,9 +244,15 @@ def _get_conda_env_export(self, root_prefix, conda_path):
)
export = yaml.load(out)
except Exception as exc:
lgr.warning("Could not retrieve conda environment "
"export from path %s: %s", conda_path,
exc_str(exc))
if "unrecognized arguments: -p" in exc_str(exc):
lgr.warning("Could not retrieve conda environment "
"export from path %s: "
"Please use Conda 4.3.19 or greater",
conda_path)
else:
lgr.warning("Could not retrieve conda environment "
"export from path %s: %s", conda_path,
exc_str(exc))
return export
def _get_conda_info(self, conda_path):
@@ -7,11 +7,14 @@
#
# ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
import collections
import io
import logging
import os
import pytest
import sys
from appdirs import AppDirs
from mock import mock
from subprocess import call
from unittest import SkipTest
@@ -96,3 +99,34 @@ def test_parse_conda_export_pip_package_entry():
assert CondaTracer.parse_pip_package_entry(
"niceman (/test/repronim)==0.0.2") == (
"niceman", "/test/repronim")
def test_get_conda_env_export_exceptions():
# Mock to capture logs
def log_warning(msg, *args):
log_warning.val = msg % args if args else msg
# Mock to throw unrecognized argument exception
def raise_unrec_args(_):
raise Exception("conda-env: error: unrecognized arguments: -p"
"/home/butch/old_conda/")
# Mock to raise some other exception
def raise_other(_):
raise Exception("unknown")
from niceman.distributions.conda import lgr
tracer = CondaTracer()
with mock.patch.object(tracer._session, "execute_command",
raise_unrec_args), \
mock.patch.object(lgr, "warning", log_warning):
tracer._get_conda_env_export("", "/conda")
assert "Please use Conda 4.3.19" in log_warning.val
with mock.patch.object(tracer._session, "execute_command",
raise_other), \
mock.patch.object(lgr, "warning", log_warning):
tracer._get_conda_env_export("", "/conda")
assert "unknown" in log_warning.val

0 comments on commit 63f5394

Please sign in to comment.