2018-06-26 04:36:20 -07:00
|
|
|
"""
|
|
|
|
|
Test conda commandline wrappers
|
|
|
|
|
"""
|
2024-02-05 20:29:32 +00:00
|
|
|
|
2018-06-26 04:36:20 -07:00
|
|
|
import os
|
|
|
|
|
import subprocess
|
|
|
|
|
import tempfile
|
|
|
|
|
|
2023-05-15 08:51:35 +00:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
from tljh import conda, installer
|
|
|
|
|
|
2018-06-26 04:36:20 -07:00
|
|
|
|
2021-11-03 23:55:34 +01:00
|
|
|
@pytest.fixture(scope="module")
|
2018-06-26 04:36:20 -07:00
|
|
|
def prefix():
|
|
|
|
|
"""
|
2024-08-23 10:00:57 +02:00
|
|
|
Provide a temporary directory with a conda environment
|
2018-06-26 04:36:20 -07:00
|
|
|
"""
|
2024-08-23 10:00:57 +02:00
|
|
|
installer_url, checksum = installer._miniforge_url()
|
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(
|
2023-03-21 14:21:00 +01:00
|
|
|
installer_url, checksum
|
2021-11-01 09:42:45 +01:00
|
|
|
) as installer_path:
|
2018-07-20 11:30:11 -07:00
|
|
|
conda.install_miniconda(installer_path, tmpdir)
|
2018-06-26 04:36:20 -07:00
|
|
|
yield tmpdir
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_ensure_packages(prefix):
|
|
|
|
|
"""
|
|
|
|
|
Test installing packages in conda environment
|
|
|
|
|
"""
|
2021-11-03 23:55:34 +01:00
|
|
|
conda.ensure_conda_packages(prefix, ["numpy"])
|
2018-06-26 04:36:20 -07:00
|
|
|
# Throws an error if this fails
|
2021-11-03 23:55:34 +01:00
|
|
|
subprocess.check_call([os.path.join(prefix, "bin", "python"), "-c", "import numpy"])
|
2018-06-26 17:38:56 -07:00
|
|
|
|
2023-09-29 21:35:50 +00:00
|
|
|
|
2022-09-02 14:10:43 -04:00
|
|
|
def test_ensure_channel_packages(prefix):
|
|
|
|
|
"""
|
|
|
|
|
Test installing packages in conda environment
|
|
|
|
|
"""
|
2023-09-29 21:35:50 +00:00
|
|
|
conda.ensure_conda_packages(prefix, ["csvtk"], channels=("conda-forge", "bioconda"))
|
2022-09-02 14:10:43 -04:00
|
|
|
# Throws an error if this fails
|
|
|
|
|
subprocess.check_call([os.path.join(prefix, "bin", "csvtk"), "cat", "--help"])
|
2023-09-29 21:35:50 +00:00
|
|
|
|
2018-06-26 17:38:56 -07:00
|
|
|
|
|
|
|
|
def test_ensure_pip_packages(prefix):
|
|
|
|
|
"""
|
|
|
|
|
Test installing pip packages in conda environment
|
|
|
|
|
"""
|
2021-11-03 23:55:34 +01:00
|
|
|
conda.ensure_conda_packages(prefix, ["pip"])
|
|
|
|
|
conda.ensure_pip_packages(prefix, ["numpy"])
|
2018-06-26 17:38:56 -07:00
|
|
|
# Throws an error if this fails
|
2021-11-03 23:55:34 +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
|
|
|
|
|
"""
|
2021-11-03 23:55:34 +01:00
|
|
|
conda.ensure_conda_packages(prefix, ["pip"])
|
2018-07-18 01:00:48 -07:00
|
|
|
with tempfile.NamedTemporaryFile() as f:
|
|
|
|
|
# Sample small package to test
|
2021-11-03 23:55:34 +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-03 23:55:34 +01:00
|
|
|
subprocess.check_call([os.path.join(prefix, "bin", "python"), "-c", "import there"])
|