Skip to content

Commit

Permalink
Merge pull request airspeed-velocity#1373 from HaoZeke/ctxMamba
Browse files Browse the repository at this point in the history
BUG: Add `MAMBARC` support to `mamba`
  • Loading branch information
mattip authored Feb 4, 2024
2 parents 4f7c092 + 54eea89 commit cc29be7
Show file tree
Hide file tree
Showing 12 changed files with 305 additions and 56 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/build_wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
message: ${{ steps.commit_message.outputs.message }}
steps:
- name: Checkout asv
uses: actions/checkout@v3
uses: actions/checkout@v4
# Gets the correct commit message for pull request
with:
ref: ${{ github.event.pull_request.head.sha }}
Expand All @@ -34,7 +34,7 @@ jobs:
echo "message=$COMMIT_MSG" >> $GITHUB_OUTPUT
echo github.ref ${{ github.ref }}
build_wheels:
name: Build wheel for ${{ matrix.python-version }}-${{ matrix.buildplat[1] }}
name: Build wheels
needs: get_commit_message
if: >-
contains(needs.get_commit_message.outputs.message, '[wheel build]') ||
Expand All @@ -58,8 +58,9 @@ jobs:
python-version: ['3.8', '3.9', '3.10', '3.11', 'pypy3.8', 'pypy3.9']

steps:
- uses: actions/checkout@v3

- uses: actions/checkout@v4
- name: Echo Python version and build platform
run: echo Building wheel for ${{ matrix.python-version }}-${{ matrix.buildplat[1] }}
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
Expand All @@ -79,7 +80,7 @@ jobs:
(github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') && ( ! endsWith(github.ref, 'dev0')))
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Build sdist
shell: bash -l {0}
Expand Down
12 changes: 7 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Linux CI
name: Linux and MacOS CI

on: [push, pull_request]

Expand All @@ -18,7 +18,7 @@ jobs:
r-version: ['release']
timeout-minutes: 30
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0

Expand Down Expand Up @@ -60,12 +60,14 @@ jobs:

test_env:
name: test_environments
runs-on: "ubuntu-latest"
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ["ubuntu-latest", "macos-latest"]
fail-fast: false
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0

Expand Down Expand Up @@ -96,7 +98,7 @@ jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: actions/setup-python@v4
with:
Expand Down
72 changes: 72 additions & 0 deletions .github/workflows/ci_win.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Windows CI

on: [push, pull_request]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
name: test
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: ["windows-latest"]
python-version: ["3.7"]
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python version ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: pip
cache-dependency-path: pyproject.toml

- name: Install and test
shell: pwsh
run: |
python.exe -m pip install .[test]
python.exe -m pip install packaging virtualenv
python.exe -m pytest -v -l -x --timeout=300 --durations=100 test --environment-type=virtualenv
test_env:
name: test_environments
runs-on: "ubuntu-latest"
strategy:
fail-fast: false
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: mamba-org/setup-micromamba@v1
with:
init-shell: >-
powershell
environment-name: test-env
cache-environment: true
create-args: >-
python
pip
libmambapy
conda-build
- name: Install dependencies
run: python -m pip install ".[test,hg]" --pre
shell: micromamba-shell {0}

- name: Install asv
run: pip install .
shell: micromamba-shell {0}

- name: Run tests
run: pytest -k environment_bench -vvvvv
shell: micromamba-shell {0}
4 changes: 2 additions & 2 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: '3.9'
- uses: pre-commit/[email protected]
4 changes: 2 additions & 2 deletions .github/workflows/triggered.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
r-version: ['release']
timeout-minutes: 30
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0

Expand Down Expand Up @@ -53,7 +53,7 @@ jobs:
run: python -m pip install ".[test,hg]"

- name: Get asv_runner to be tested
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: airspeed-velocity/asv_runner
ref: refs/pull/${{ github.event.inputs.pr_number }}/head
Expand Down
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ API Changes
Bug Fixes
^^^^^^^^^
- The ``mamba`` plugin works correctly for newer versions (>=1.5) of ``libmambapy`` (#1372)
- The ``mamba`` plugin respects the ``MAMBARC`` environment if set, taking
channels and channel priority from the file in the environment variable. (#1373)
- ``conda-forge`` is no longer a default channel for ``mamba``. (#1373)
- Fixed a bug where ``matrix`` requirements were dropped if an environment file was specified. (#1373)

Other Changes and Additions
^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
31 changes: 28 additions & 3 deletions asv/plugins/mamba.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import re
from pathlib import Path

import yaml
from yaml import load

try:
Expand Down Expand Up @@ -54,8 +55,6 @@ def __init__(self, conf, python, requirements, tagged_env_vars):
self._requirements = requirements
self._mamba_channels = conf.conda_channels
self._mamba_environment_file = None
if "conda-forge" not in conf.conda_channels:
self._mamba_channels += ["conda-forge"]

if conf.conda_environment_file == "IGNORE":
log.debug("Skipping environment file due to conda_environment_file set to IGNORE")
Expand All @@ -74,6 +73,31 @@ def __init__(self, conf, python, requirements, tagged_env_vars):
super(Mamba, self).__init__(conf, python, requirements, tagged_env_vars)
self.context = libmambapy.Context()
self.context.target_prefix = self._path
# Handle MAMBARC environment variable
mambarc_path = Path(os.getenv("MAMBARC", ""))
if mambarc_path.is_file():
with mambarc_path.open() as f:
condarc_data = yaml.safe_load(f)
self._apply_condarc_settings(condarc_data)

def _apply_condarc_settings(self, condarc_data):
# Apply channel settings
if 'channels' in condarc_data:
self.context.channels = condarc_data['channels']
self._mamba_channels.extend(condarc_data['channels'])

# Apply channel priority settings
channel_priority_map = {
'strict': libmambapy.ChannelPriority.kStrict,
'flexible': libmambapy.ChannelPriority.kFlexible,
'disabled': libmambapy.ChannelPriority.kDisabled
}
if 'channel_priority' in condarc_data:
priority_str = condarc_data['channel_priority']
if priority_str in channel_priority_map:
self.context.channel_priority = channel_priority_map[priority_str]
else:
log.debug(f"Unknown channel priority: {priority_str}")

@classmethod
def matches(cls, python):
Expand Down Expand Up @@ -107,7 +131,7 @@ def _setup(self):
Path(f"{self._path}/conda-meta").mkdir(parents=True, exist_ok=True)
if not self._mamba_environment_file:
# Construct payload, env file sets python version
mamba_pkgs = [f"python={self._python}", "wheel", "pip"] + mamba_args
mamba_pkgs = [f"python={self._python}", "wheel", "pip"]
else:
# For named environments
env_file_name = self._mamba_environment_file
Expand All @@ -122,6 +146,7 @@ def _setup(self):
pip_args += pip_maybe[0]["pip"]
except KeyError:
raise KeyError("Only pip is supported as a secondary key")
mamba_pkgs += mamba_args
solver = MambaSolver(
self._mamba_channels, None, self.context # or target_platform
)
Expand Down
6 changes: 6 additions & 0 deletions docs/source/asv.conf.json.rst
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,12 @@ the project being benchmarked may specify in its ``setup.py`` file.
These specifications in ``environment.yml`` or another (user-defined)
file will be overridden by the environment matrix.
.. versionadded::0.6.2
The ``mamba`` plugin will now take channels and channel priority from the
``MAMBARC`` environment variable if it is provided. e.g.
``MAMBARC=$HOME/.condarc asv run``. By default user ``.rc`` files are not
read to enforce isolation.
The ``env`` and ``env_nobuild`` dictionaries can be used to set also
environment variables::
Expand Down
2 changes: 2 additions & 0 deletions test/test_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from asv.repo import get_repo
from asv.util import shlex_quote as quote

from . import tools
from .tools import (PYTHON_VER1, PYTHON_VER2, DUMMY1_VERSION, DUMMY2_VERSIONS, WIN, HAS_PYPY,
HAS_CONDA, HAS_VIRTUALENV, HAS_PYTHON_VER2, generate_test_repo)

Expand Down Expand Up @@ -682,6 +683,7 @@ def test_build_isolation(tmpdir):
env.install_project(conf, repo, commit_hash)


@pytest.mark.skipif(tools.HAS_PYPY, reason="Flaky on pypy")
def test_custom_commands(tmpdir):
# check custom install/uninstall/build commands work
tmpdir = str(tmpdir)
Expand Down
Loading

0 comments on commit cc29be7

Please sign in to comment.