From e97b81fe7ac6fb40bac6ab2c1850dd7ba296a9ba Mon Sep 17 00:00:00 2001 From: yuvipanda Date: Fri, 20 Jul 2018 11:30:11 -0700 Subject: [PATCH] Require miniconda to be installed for conda. to work We can no longer assume that sys.executable has conda installed. Instead, we require that prefix has conda installed. This requires miniconda to be installed into prefix. --- tests/test_conda.py | 33 ++++++--------------------------- tljh/conda.py | 19 ------------------- 2 files changed, 6 insertions(+), 46 deletions(-) diff --git a/tests/test_conda.py b/tests/test_conda.py index 7b372e5..4f3f608 100644 --- a/tests/test_conda.py +++ b/tests/test_conda.py @@ -8,42 +8,23 @@ import subprocess import tempfile -@pytest.fixture +@pytest.fixture(scope='module') def prefix(): """ - Provide a temporary directory to make environments in. + Provide a temporary directory with a conda environment """ + miniconda_version = '4.5.4' + miniconda_installer_md5 = "a946ea1d0c4a642ddf0c3a26a18bb16d" with tempfile.TemporaryDirectory() as tmpdir: + with conda.download_miniconda_installer(miniconda_version, miniconda_installer_md5) as installer_path: + conda.install_miniconda(installer_path, tmpdir) yield tmpdir -def test_create_environment(prefix): - """ - Test conda environment creation - - An empty conda environment doesn't seem to have anything in it, - so we just check for directory existence. - """ - conda.ensure_conda_env(prefix) - assert os.path.exists(prefix) - - -def test_ensure_environment(prefix): - """ - Test second call to ensure_conda_env works as expected - - A conda environment already exists, so we it should just do nothing - """ - conda.ensure_conda_env(prefix) - assert os.path.exists(prefix) - conda.ensure_conda_env(prefix) - - def test_ensure_packages(prefix): """ Test installing packages in conda environment """ - conda.ensure_conda_env(prefix) conda.ensure_conda_packages(prefix, ['numpy']) # Throws an error if this fails subprocess.check_call([ @@ -57,7 +38,6 @@ def test_ensure_pip_packages(prefix): """ Test installing pip packages in conda environment """ - conda.ensure_conda_env(prefix) conda.ensure_conda_packages(prefix, ['pip']) conda.ensure_pip_packages(prefix, ['numpy']) # Throws an error if this fails @@ -72,7 +52,6 @@ def test_ensure_pip_requirements(prefix): """ Test installing pip packages with requirements.txt in conda environment """ - conda.ensure_conda_env(prefix) conda.ensure_conda_packages(prefix, ['pip']) with tempfile.NamedTemporaryFile() as f: # Sample small package to test diff --git a/tljh/conda.py b/tljh/conda.py index 96ef324..d79de1e 100644 --- a/tljh/conda.py +++ b/tljh/conda.py @@ -77,25 +77,6 @@ def install_miniconda(installer_path, prefix): subprocess.check_call(["chmod", "-R", "o-w", prefix]) -def ensure_conda_env(prefix): - """ - Ensure a conda environment in the prefix - """ - conda_executable = [os.path.join(prefix, 'bin', 'python'), '-m', 'conda'] - abspath = os.path.abspath(prefix) - try: - output = json.loads( - subprocess.check_output(conda_executable + ['create', '--json', '--prefix', abspath]).decode() - ) - except subprocess.CalledProcessError as e: - output = json.loads(e.output.decode()) - if 'error' in output and output['error'] == f'CondaValueError: prefix already exists: {abspath}': - return - raise - if 'success' in output and output['success'] == True: - return - - def ensure_conda_packages(prefix, packages): """ Ensure packages (from conda-forge) are installed in the conda prefix.