Skip to content

Commit

Permalink
Address mamba v2 incompatibilities (#368)
Browse files Browse the repository at this point in the history
* look for mamba in more places and guarantee existence

* parameterize mamba versions

* debug locations

* pass options

* Pass MAMBA_ROOT_PREFIX for mamba v2

* mamba v2 doesn't create env with update

* copy to condabin?

* use basename

* fix extension

* fix path under Windows

* extra verbose

* is it pip?

* it wasn't pip

* do not compile pyc on win

* temporarily remove pip section

* bash wrapper goes in condabin

* compile

* debug a bit

* fix workflow

* amend paths

* mark as executable?

* remove which?

* debug and disablew a few workflows

* activate before forward?

* slashes?

* refactor forwarders

* bash forwarder only on 1.x

* fwd via cmd?

* which

* move to the bottom

* this one too

* fix executable names

* revert

* clean up a bit

* mark as generated

* restore bash forwarder

* hide from local diff too

* do we still need MAMBA_COMPILE_PYC?
  • Loading branch information
jaimergp authored Oct 3, 2024
1 parent 8f65dda commit 899c78d
Show file tree
Hide file tree
Showing 8 changed files with 228 additions and 64 deletions.
3 changes: 2 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.js -diff
dist/setup/index.js linguist-generated=true -diff
dist/delete/index.js linguist-generated=true -diff
11 changes: 7 additions & 4 deletions .github/workflows/example-6.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,22 @@ jobs:
if:
(github.event_name == 'schedule' && github.repository ==
'conda-incubator/setup-miniconda') || (github.event_name != 'schedule')
name: Ex6 (${{ matrix.os }})
name:
Ex6 (${{ matrix.os }}, mamba ${{ matrix.mamba-version }}, ${{
matrix.activate-environment }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest", "macos-latest", "windows-latest"]
mamba-version: ["1.5.10", "2"]
include:
- os: ubuntu-latest
activate-environment: anaconda-client-env
- os: macos-latest
activate-environment: /tmp/anaconda-client-env
- os: windows-latest
activate-environment: c:\ace
activate-environment: C:\ace
defaults:
run:
shell: bash -el {0}
Expand All @@ -47,7 +50,7 @@ jobs:
with:
miniforge-variant: Miniforge3
python-version: "3.11"
mamba-version: "*"
mamba-version: ${{ matrix.mamba-version }}
channels: conda-forge,nodefaults
channel-priority: true
activate-environment: ${{ matrix.activate-environment }}
Expand All @@ -69,7 +72,7 @@ jobs:
- name: Windows, .bat, from Cmd
shell: cmd /C call {0}
if: matrix.os == 'windows-latest'
run: mamba --version
run: mamba.bat --version
- name: Windows, no .bat, from Cmd
shell: cmd /C call {0}
if: matrix.os == 'windows-latest'
Expand Down
3 changes: 2 additions & 1 deletion dist/delete/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

130 changes: 102 additions & 28 deletions dist/setup/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 54 additions & 10 deletions src/base-tools/update-mamba.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as fs from "fs";
import * as path from "path";

import * as core from "@actions/core";

Expand All @@ -23,16 +24,59 @@ export const updateMamba: types.IToolProvider = {
};
},
postInstall: async (inputs, options) => {
if (!constants.IS_WINDOWS) {
core.info("`mamba` is already executable");
return;
}
core.info("Creating bash wrapper for `mamba`...");
// Add bat-less forwarder for bash users on Windows
const mambaBat = conda.condaExecutable(options).replace(/\\/g, "/");
const mambaExec = conda.condaExecutable(options);
const condabinLocation = path.join(
conda.condaBasePath(options),
"condabin",
path.basename(mambaExec),
);
if (constants.IS_UNIX) {
if (!fs.existsSync(condabinLocation)) {
// This is mamba 2.x with only $PREFIX/bin/mamba,
// we just need a symlink in condabin
core.info(`Symlinking ${mambaExec} to ${condabinLocation}...`);
fs.symlinkSync(mambaExec, condabinLocation);
}
} else {
core.info(`Creating bash wrapper for 'mamba'...`);
const mambaBat = condabinLocation.slice(0, -4) + ".bat";
// Add bat-less forwarder for bash users on Windows
const forwarderContents = `cmd.exe /C CALL "${mambaBat}" $* || exit 1`;
fs.writeFileSync(condabinLocation.slice(0, -4), forwarderContents);
core.info(`... wrote ${mambaExec.slice(0, -4)}:\n${forwarderContents}`);
if (!fs.existsSync(mambaBat)) {
// This is Windows and mamba 2.x, we need a mamba.bat like 1.x used to have
const contents = `
@REM Copyright (C) 2012 Anaconda, Inc
@REM SPDX-License-Identifier: BSD-3-Clause
@REM echo _CE_CONDA is %_CE_CONDA%
@REM echo _CE_M is %_CE_M%
@REM echo CONDA_EXE is %CONDA_EXE%
@IF NOT DEFINED _CE_CONDA (
@SET _CE_M=
@SET "CONDA_EXE=%~dp0..\\Scripts\\conda.exe"
)
@IF [%1]==[activate] "%~dp0_conda_activate" %*
@IF [%1]==[deactivate] "%~dp0_conda_activate" %*
@SET MAMBA_EXES="%~dp0..\\Library\\bin\\mamba.exe"
@CALL %MAMBA_EXES% %*
const contents = `bash.exe -c "exec '${mambaBat}' $*" || exit 1`;
fs.writeFileSync(mambaBat.slice(0, -4), contents);
core.info(`... wrote ${mambaBat}:\n${contents}`);
@IF %errorlevel% NEQ 0 EXIT /B %errorlevel%
@IF [%1]==[install] "%~dp0_conda_activate" reactivate
@IF [%1]==[update] "%~dp0_conda_activate" reactivate
@IF [%1]==[upgrade] "%~dp0_conda_activate" reactivate
@IF [%1]==[remove] "%~dp0_conda_activate" reactivate
@IF [%1]==[uninstall] "%~dp0_conda_activate" reactivate
@EXIT /B %errorlevel%`;
core.info(`Creating .bat wrapper for 'mamba 2.x'...`);
fs.writeFileSync(mambaBat, contents);
core.info(`... wrote ${mambaBat}`);
}
}
},
};
Loading

0 comments on commit 899c78d

Please sign in to comment.