2018-06-26 04:36:20 -07:00
|
|
|
"""
|
|
|
|
|
Test conda commandline wrappers
|
|
|
|
|
"""
|
|
|
|
|
from tljh import conda
|
|
|
|
|
import os
|
|
|
|
|
import pytest
|
|
|
|
|
import subprocess
|
|
|
|
|
import tempfile
|
|
|
|
|
|
|
|
|
|
|
2018-07-20 11:30:11 -07:00
|
|
|
@pytest.fixture(scope='module')
|
2018-06-26 04:36:20 -07:00
|
|
|
def prefix():
|
|
|
|
|
"""
|
2021-11-03 22:47:57 +01:00
|
|
|
Provide a temporary directory with a mambaforge conda environment
|
2018-06-26 04:36:20 -07:00
|
|
|
"""
|
2021-11-03 22:47:57 +01:00
|
|
|
# see https://github.com/conda-forge/miniforge/releases
|
2021-10-18 22:33:06 +01:00
|
|
|
mambaforge_version = '4.10.3-7'
|
2021-11-03 22:47:57 +01:00
|
|
|
if os.uname().machine == 'aarch64':
|
2021-11-01 09:42:45 +01:00
|
|
|
installer_sha256 = (
|
|
|
|
|
"ac95f137b287b3408e4f67f07a284357b1119ee157373b788b34e770ef2392b2"
|
|
|
|
|
)
|
2021-11-03 22:47:57 +01:00
|
|
|
elif os.uname().machine == 'x86_64':
|
2021-11-01 09:42:45 +01:00
|
|
|
installer_sha256 = (
|
|
|
|
|
"fc872522ec427fcab10167a93e802efaf251024b58cc27b084b915a9a73c4474"
|
|
|
|
|
)
|
|
|
|
|
installer_url = "https://github.com/conda-forge/miniforge/releases/download/{v}/Mambaforge-{v}-Linux-{arch}.sh".format(
|
|
|
|
|
v=mambaforge_version, arch=os.uname().machine
|
|
|
|
|
)
|
2018-06-26 04:36:20 -07:00
|
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
2021-11-01 09:42:45 +01:00
|
|
|
with conda.download_miniconda_installer(
|
|
|
|
|
installer_url, installer_sha256
|
|
|
|
|
) as installer_path:
|
2018-07-20 11:30:11 -07:00
|
|
|
conda.install_miniconda(installer_path, tmpdir)
|
2021-11-01 09:42:45 +01:00
|
|
|
conda.ensure_conda_packages(tmpdir, ['conda==4.10.3'])
|
2018-06-26 04:36:20 -07:00
|
|
|
yield tmpdir
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_ensure_packages(prefix):
|
|
|
|
|
"""
|
|
|
|
|
Test installing packages in conda environment
|
|
|
|
|
"""
|
|
|
|
|
conda.ensure_conda_packages(prefix, ['numpy'])
|
|
|
|
|
# Throws an error if this fails
|
2021-11-01 09:42:45 +01:00
|
|
|
subprocess.check_call([os.path.join(prefix, 'bin', 'python'), '-c', 'import numpy'])
|
2018-06-26 17:38:56 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_ensure_pip_packages(prefix):
|
|
|
|
|
"""
|
|
|
|
|
Test installing pip packages in conda environment
|
|
|
|
|
"""
|
|
|
|
|
conda.ensure_conda_packages(prefix, ['pip'])
|
|
|
|
|
conda.ensure_pip_packages(prefix, ['numpy'])
|
|
|
|
|
# Throws an error if this fails
|
2021-11-01 09:42:45 +01:00
|
|
|
subprocess.check_call([os.path.join(prefix, 'bin', 'python'), '-c', 'import numpy'])
|
2018-07-18 01:00:48 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_ensure_pip_requirements(prefix):
|
|
|
|
|
"""
|
|
|
|
|
Test installing pip packages with requirements.txt in conda environment
|
|
|
|
|
"""
|
|
|
|
|
conda.ensure_conda_packages(prefix, ['pip'])
|
|
|
|
|
with tempfile.NamedTemporaryFile() as f:
|
|
|
|
|
# Sample small package to test
|
2021-10-31 11:26:40 +01:00
|
|
|
f.write(b'there')
|
2018-07-18 01:00:48 -07:00
|
|
|
f.flush()
|
|
|
|
|
conda.ensure_pip_requirements(prefix, f.name)
|
2021-11-01 09:42:45 +01:00
|
|
|
subprocess.check_call([os.path.join(prefix, 'bin', 'python'), '-c', 'import there'])
|