Skip to content

Commit

Permalink
Add tests for micromamba, transmuation and miniforge
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisburr committed Mar 13, 2022
1 parent e3cfcd3 commit 343f98d
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 13 deletions.
16 changes: 16 additions & 0 deletions examples/miniforge/construct.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Miniforge3
version: 4.10.1-0
company: conda-forge

channels:
- conda-forge

write_condarc: True
keep_pkgs: True
transmute_file_type: .conda

specs:
- python 3.9.*
- conda 4.10.1
- pip
- miniforge_console_shortcut 1.* # [win]
48 changes: 35 additions & 13 deletions scripts/run_examples.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Run examples bundled with this repo."""

# Standard library imports
import os
import subprocess
import sys
import tempfile
import platform
import shutil
from itertools import product
from subprocess import PIPE, Popen

from constructor.utils import rm_rf
from ruamel_yaml import round_trip_load, round_trip_dump

try:
import coverage # noqa
Expand All @@ -29,15 +28,14 @@

def _execute(cmd):
print(' '.join(cmd))
p = subprocess.Popen(cmd, stderr=subprocess.PIPE)
p = Popen(cmd, stdout=PIPE, stderr=PIPE, universal_newlines=True)
print('--- STDOUT ---')
_, stderr = p.communicate()
stdout, stderr = p.communicate()
print(stdout.strip())
if stderr:
print('--- STDERR ---')
if PY3:
stderr = stderr.decode()
print(stderr.strip())
return p.returncode != 0
return p.returncode != 0, stdout.strip()


def run_examples(keep_artifacts=None):
Expand All @@ -54,6 +52,16 @@ def run_examples(keep_artifacts=None):
int
Number of failed examples
"""
env_name = "constructor-testing-micromamba"
which_cmd = ["conda", "run", "--name", env_name, "which", "micromamba"]
errored, micromamba_path = _execute(which_cmd)
if errored:
_execute(["conda", "create", "--name", env_name, "--yes", "-c", "conda-forge", "micromamba"])
errored, micromamba_path = _execute(which_cmd)
if errored:
raise NotImplementedError("Failed to find micromamba")
print("Found micromamba at:", micromamba_path)

example_paths = []
errored = 0

Expand All @@ -71,12 +79,26 @@ def run_examples(keep_artifacts=None):

parent_output = tempfile.mkdtemp()
tested_files = set()
for example_path in sorted(example_paths):
for example_path, conda_exe in product(sorted(example_paths), [None, micromamba_path]):
print(example_path)
print('-' * len(example_path))
output_dir = tempfile.mkdtemp(dir=parent_output)
cmd = COV_CMD + ['constructor', example_path, '--output-dir', output_dir]
errored += _execute(cmd)
input_dir = tempfile.mkdtemp(dir=parent_output, suffix="_input")
cmd = COV_CMD + ['constructor', input_dir, '--output-dir', output_dir]

# Copy the input to a temporary directory so we can modify it if needed
shutil.copytree(example_path, input_dir, dirs_exist_ok=True)
if conda_exe:
with open(os.path.join(input_dir, "construct.yaml")) as fp:
data = round_trip_load(fp)
data["name"] = f"{data['name']}-{os.path.basename(conda_exe)}"
with open(os.path.join(input_dir, "construct.yaml"), "wt") as fp:
round_trip_dump(data, fp)
print("Setting conda.exe to:", conda_exe)
cmd += ['--conda-exe', conda_exe]

# Create the installer
errored += _execute(cmd)[0]
for fpath in os.listdir(output_dir):
ext = fpath.rsplit('.', 1)[-1]
if fpath in tested_files or ext not in ('sh', 'exe', 'pkg'):
Expand All @@ -95,7 +117,7 @@ def run_examples(keep_artifacts=None):
cmd = ['pkgutil', '--expand', fpath, env_dir]
elif ext == 'exe':
cmd = ['cmd.exe', '/c', 'start', '/wait', fpath, '/S', '/D=%s' % env_dir]
errored += _execute(cmd)
errored += _execute(cmd)[0]
if keep_artifacts:
shutil.move(fpath, keep_artifacts)
print('')
Expand Down

0 comments on commit 343f98d

Please sign in to comment.