Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor build_with_mambabuild bool with conda_build_tool choice #1732

Merged
merged 10 commits into from
Sep 6, 2023
24 changes: 23 additions & 1 deletion conda_smithy/configure_feedstock.py
Original file line number Diff line number Diff line change
Expand Up @@ -1816,7 +1816,7 @@ def _load_forge_config(forge_dir, exclusive_config_file, forge_yml=None):
"conda_forge_output_validation": False,
"private_upload": False,
"secrets": [],
"build_with_mambabuild": True,
"conda_build_tool": "mambabuild",
# feedstock checkout git clone depth, None means keep default, 0 means no limit
"clone_depth": None,
# Specific channel for package can be given with
Expand Down Expand Up @@ -1902,6 +1902,28 @@ def _load_forge_config(forge_dir, exclusive_config_file, forge_yml=None):
f"{target_platforms}"
)

if (
"build_with_mambabuild" in file_config
and "conda_build_tool" not in file_config
):
warnings.warn(
"build_with_mambabuild is deprecated, use conda_build_tool instead",
DeprecationWarning,
)
config["conda_build_tool"] = (
"mambabuild" if config["build_with_mambabuild"] else "conda-build"
)
valid_build_tools = (
"mambabuild", # will run 'conda mambabuild', as provided by boa
"conda-build", # will run vanilla conda-build, with system configured / default solver
"conda-build+conda-libmamba-solver", # will run vanilla conda-build, with libmamba solver
"conda-build+classic", # will run vanilla conda-build, with the classic solver
)
assert config["conda_build_tool"] in valid_build_tools, (
f"Invalid conda_build_tool: {config['conda_build_tool']}. "
f"Valid values are: {valid_build_tools}."
)

config["secrets"] = sorted(set(config["secrets"] + ["BINSTAR_TOKEN"]))

if config["test_on_native_only"]:
Expand Down
18 changes: 13 additions & 5 deletions conda_smithy/templates/azure-pipelines-win.yml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ jobs:
displayName: "Install Chocolatey Package: {{ choco_pkg }}"
{% endfor %}

{%- if build_with_mambabuild %}
{%- set BOA="boa " %}
{%- if conda_build_tool == "mambabuild" %}
{%- set conda_build_tool_deps="boa " %}
{%- elif conda_build_tool == "conda-build+conda-libmamba-solver" %}
{%- set conda_build_tool_deps="conda-libmamba-solver " %}
{%- else %}
{%- set BOA="" %}
{%- set conda_build_tool_deps="" %}
{%- endif %}
- task: PythonScript@0
displayName: 'Download Miniforge'
Expand All @@ -40,7 +42,7 @@ jobs:

- script: |
call activate base
mamba.exe install "python=3.10" conda-build conda pip {{ BOA }}{{ " ".join(remote_ci_setup) }} -c conda-forge --strict-channel-priority --yes
mamba.exe install "python=3.10" conda-build conda pip {{ conda_build_tool_deps }}{{ " ".join(remote_ci_setup) }} -c conda-forge --strict-channel-priority --yes
displayName: Install conda-build

- script: set PYTHONUNBUFFERED=1
Expand Down Expand Up @@ -70,8 +72,14 @@ jobs:
if EXIST LICENSE.txt (
copy LICENSE.txt "{{ recipe_dir }}\\recipe-scripts-license.txt"
)
{%- if build_with_mambabuild %}
{%- if conda_build_tool == "mambabuild" %}
conda.exe mambabuild "{{ recipe_dir }}" -m .ci_support\%CONFIG%.yaml --suppress-variables
{%- elif conda_build_tool == "conda-build+conda-libmamba-solver" %}
set "CONDA_SOLVER=libmamba"
conda.exe build "{{ recipe_dir }}" -m .ci_support\%CONFIG%.yaml --suppress-variables
{%- elif conda_build_tool == "conda-build+classic" %}
set "CONDA_SOLVER=classic"
conda.exe build "{{ recipe_dir }}" -m .ci_support\%CONFIG%.yaml --suppress-variables
{%- else %}
conda.exe build "{{ recipe_dir }}" -m .ci_support\%CONFIG%.yaml --suppress-variables
{%- endif %}
Expand Down
26 changes: 17 additions & 9 deletions conda_smithy/templates/build_steps.sh.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,29 @@ pkgs_dirs:
- /opt/conda/pkgs

CONDARC
{% if build_with_mambabuild %}
{% if conda_build_tool == "mambabuild" %}
{%- set CONDA_INSTALL_CMD="mamba" %}
{%- set BOA="boa " %}
{%- set BUILD_CMD="mambabuild" %}
{%- set conda_build_tool_deps="boa " %}
{%- set BUILD_CMD="conda mambabuild" %}
{% elif conda_build_tool == "conda-build+conda-libmamba-solver" %}
{%- set CONDA_INSTALL_CMD="mamba" %}
beckermr marked this conversation as resolved.
Show resolved Hide resolved
{%- set conda_build_tool_deps="conda-libmamba-solver " %}
{%- set BUILD_CMD="CONDA_SOLVER=libmamba conda build" %}
{% elif conda_build_tool == "conda-build+classic" %}
{%- set CONDA_INSTALL_CMD="mamba" %}
{%- set conda_build_tool_deps="" %}
{%- set BUILD_CMD="CONDA_SOLVER=classic conda build" %}
{%- else %}
{%- set CONDA_INSTALL_CMD="mamba" %}
{%- set BOA="" %}
{%- set BUILD_CMD="build" %}
{%- set conda_build_tool_deps="" %}
{%- set BUILD_CMD="conda build" %}
{%- endif %}

{{ CONDA_INSTALL_CMD }} install --update-specs --yes --quiet --channel conda-forge \
conda-build pip {{ BOA }}{{ " ".join(remote_ci_setup) }}
{%- if build_with_mambabuild %}
conda-build pip {{ conda_build_tool_deps }}{{ " ".join(remote_ci_setup) }}
{%- if conda_build_tool_deps != "" %}
{{ CONDA_INSTALL_CMD }} update --update-specs --yes --quiet --channel conda-forge \
conda-build pip {{ BOA }}{{ " ".join(remote_ci_setup) }}
conda-build pip {{ conda_build_tool_deps }}{{ " ".join(remote_ci_setup) }}
{%- endif %}
{% if local_ci_setup %}
conda uninstall --quiet --yes --force {{ " ".join(remote_ci_setup) }}
Expand Down Expand Up @@ -88,7 +96,7 @@ if [[ "${BUILD_WITH_CONDA_DEBUG:-0}" == 1 ]]; then
# Drop into an interactive shell
/bin/bash
else
conda {{ BUILD_CMD }} "${RECIPE_ROOT}" -m "${CI_SUPPORT}/${CONFIG}.yaml" \
{{ BUILD_CMD }} "${RECIPE_ROOT}" -m "${CI_SUPPORT}/${CONFIG}.yaml" \
--suppress-variables ${EXTRA_CB_OPTIONS:-} \
--clobber-file "${CI_SUPPORT}/clobber_${CONFIG}.yaml"

Expand Down
18 changes: 13 additions & 5 deletions conda_smithy/templates/github-actions.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,18 @@ jobs:
miniforge-variant: Mambaforge
if: matrix.os == 'windows'

{%- if build_with_mambabuild %}
{%- set BOA="boa " %}
{%- if conda_build_tool == "mambabuild" %}
{%- set conda_build_tool_deps="boa " %}
jaimergp marked this conversation as resolved.
Show resolved Hide resolved
{%- elif conda_build_tool == "conda-build+conda-libmamba-solver" %}
{%- set conda_build_tool_deps="conda-libmamba-solver " %}
{%- else %}
{%- set BOA="" %}
{%- set conda_build_tool_deps="" %}
{%- endif %}
- name: Build on windows
shell: cmd
run: |
call activate base
mamba.exe install -c conda-forge 'python=3.9' conda-build conda pip {{ BOA }}{{ " ".join(remote_ci_setup) }}
mamba.exe install -c conda-forge 'python=3.9' conda-build conda pip {{ conda_build_tool_deps }}{{ " ".join(remote_ci_setup) }}
if errorlevel 1 exit 1
{%- if local_ci_setup %}
conda.exe uninstall --quiet --yes --force {{ " ".join(remote_ci_setup) }}"
Expand All @@ -168,8 +170,14 @@ jobs:
if EXIST LICENSE.txt (
copy LICENSE.txt "{{ recipe_dir }}\\recipe-scripts-license.txt"
)
{%- if build_with_mambabuild %}
{%- if conda_build_tool == "mambabuild" %}
conda.exe mambabuild "{{ recipe_dir }}" -m .ci_support\%CONFIG%.yaml
{%- elif conda_build_tool == "conda-build+conda-libmamba-solver" %}
set "CONDA_SOLVER=libmamba"
conda.exe build "{{ recipe_dir }}" -m .ci_support\%CONFIG%.yaml
{%- elif conda_build_tool == "conda-build+classic" %}
set "CONDA_SOLVER=classic"
conda.exe build "{{ recipe_dir }}" -m .ci_support\%CONFIG%.yaml
beckermr marked this conversation as resolved.
Show resolved Hide resolved
{%- else %}
conda.exe build "{{ recipe_dir }}" -m .ci_support\%CONFIG%.yaml
{%- endif %}
Expand Down
26 changes: 17 additions & 9 deletions conda_smithy/templates/run_osx_build.sh.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,31 @@ bash $MINIFORGE_FILE -b -p ${MINIFORGE_HOME}
( endgroup "Installing a fresh version of Miniforge" ) 2> /dev/null

( startgroup "Configuring conda" ) 2> /dev/null
{% if build_with_mambabuild %}
{% if conda_build_tool == "mambabuild" %}
{%- set CONDA_INSTALL_CMD="mamba" %}
{%- set BOA="boa " %}
{%- set BUILD_CMD="mambabuild" %}
{%- set conda_build_tool_deps="boa " %}
{%- set BUILD_CMD="conda mambabuild" %}
{% elif conda_build_tool == "conda-build+conda-libmamba-solver" %}
{%- set CONDA_INSTALL_CMD="mamba" %}
{%- set conda_build_tool_deps="conda-libmamba-solver " %}
{%- set BUILD_CMD="CONDA_SOLVER=libmamba conda build" %}
{% elif conda_build_tool == "conda-build+classic" %}
{%- set CONDA_INSTALL_CMD="mamba" %}
{%- set conda_build_tool_deps="" %}
{%- set BUILD_CMD="CONDA_SOLVER=classic conda build" %}
{%- else %}
{%- set CONDA_INSTALL_CMD="mamba" %}
{%- set BOA="" %}
{%- set BUILD_CMD="build" %}
{%- set conda_build_tool_deps="" %}
{%- set BUILD_CMD="conda build" %}
{%- endif %}
source ${MINIFORGE_HOME}/etc/profile.d/conda.sh
conda activate base

{{ CONDA_INSTALL_CMD }} install --update-specs --quiet --yes --channel conda-forge \
conda-build pip {{ BOA }}{{ " ".join(remote_ci_setup) }}
{%- if build_with_mambabuild %}
conda-build pip {{ conda_build_tool_deps }}{{ " ".join(remote_ci_setup) }}
{%- if conda_build_tool_deps != "" %}
{{ CONDA_INSTALL_CMD }} update --update-specs --yes --quiet --channel conda-forge \
conda-build pip {{ BOA }}{{ " ".join(remote_ci_setup) }}
conda-build pip {{ conda_build_tool_deps }}{{ " ".join(remote_ci_setup) }}
{%- endif %}

{% if local_ci_setup %}
Expand Down Expand Up @@ -88,7 +96,7 @@ else
EXTRA_CB_OPTIONS="${EXTRA_CB_OPTIONS:-} --no-test"
fi
{% endif %}
conda {{ BUILD_CMD }} ./{{ recipe_dir }} -m ./.ci_support/${CONFIG}.yaml \
{{ BUILD_CMD }} ./{{ recipe_dir }} -m ./.ci_support/${CONFIG}.yaml \
--suppress-variables ${EXTRA_CB_OPTIONS:-} \
--clobber-file ./.ci_support/clobber_${CONFIG}.yaml

Expand Down
37 changes: 37 additions & 0 deletions tests/test_configure_feedstock.py
Original file line number Diff line number Diff line change
Expand Up @@ -863,3 +863,40 @@ def test_cuda_enabled_render(cuda_enabled_recipe, jinja_env):
else:
if "CF_CUDA_ENABLED" in os.environ:
del os.environ["CF_CUDA_ENABLED"]


def test_conda_build_tools(config_yaml):
load_forge_config = lambda: cnfgr_fdstk._load_forge_config( # noqa
config_yaml,
exclusive_config_file=os.path.join(
config_yaml, "recipe", "default_config.yaml"
),
)

cfg = load_forge_config()
assert (
"build_with_mambabuild" not in cfg
) # superseded by conda_build_tool=mambabuild
assert cfg["conda_build_tool"] == "mambabuild" # current default

# legacy compatibility config
with open(os.path.join(config_yaml, "conda-forge.yml")) as fp:
unmodified = fp.read()
with open(os.path.join(config_yaml, "conda-forge.yml"), "a+") as fp:
fp.write("build_with_mambabuild: true")
with pytest.deprecated_call(match="build_with_mambabuild is deprecated"):
assert load_forge_config()["conda_build_tool"] == "mambabuild"

with open(os.path.join(config_yaml, "conda-forge.yml"), "w") as fp:
fp.write(unmodified)
fp.write("build_with_mambabuild: false")

with pytest.deprecated_call(match="build_with_mambabuild is deprecated"):
assert load_forge_config()["conda_build_tool"] == "conda-build"

with open(os.path.join(config_yaml, "conda-forge.yml"), "w") as fp:
fp.write(unmodified)
fp.write("conda_build_tool: does-not-exist")

with pytest.raises(AssertionError):
assert load_forge_config()