Skip to content

Commit 899c78d

Browse files
authored
Address mamba v2 incompatibilities (#368)
* 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?
1 parent 8f65dda commit 899c78d

File tree

8 files changed

+228
-64
lines changed

8 files changed

+228
-64
lines changed

.gitattributes

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
*.js -diff
1+
dist/setup/index.js linguist-generated=true -diff
2+
dist/delete/index.js linguist-generated=true -diff

.github/workflows/example-6.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,22 @@ jobs:
2424
if:
2525
(github.event_name == 'schedule' && github.repository ==
2626
'conda-incubator/setup-miniconda') || (github.event_name != 'schedule')
27-
name: Ex6 (${{ matrix.os }})
27+
name:
28+
Ex6 (${{ matrix.os }}, mamba ${{ matrix.mamba-version }}, ${{
29+
matrix.activate-environment }})
2830
runs-on: ${{ matrix.os }}
2931
strategy:
3032
fail-fast: false
3133
matrix:
3234
os: ["ubuntu-latest", "macos-latest", "windows-latest"]
35+
mamba-version: ["1.5.10", "2"]
3336
include:
3437
- os: ubuntu-latest
3538
activate-environment: anaconda-client-env
3639
- os: macos-latest
3740
activate-environment: /tmp/anaconda-client-env
3841
- os: windows-latest
39-
activate-environment: c:\ace
42+
activate-environment: C:\ace
4043
defaults:
4144
run:
4245
shell: bash -el {0}
@@ -47,7 +50,7 @@ jobs:
4750
with:
4851
miniforge-variant: Miniforge3
4952
python-version: "3.11"
50-
mamba-version: "*"
53+
mamba-version: ${{ matrix.mamba-version }}
5154
channels: conda-forge,nodefaults
5255
channel-priority: true
5356
activate-environment: ${{ matrix.activate-environment }}
@@ -69,7 +72,7 @@ jobs:
6972
- name: Windows, .bat, from Cmd
7073
shell: cmd /C call {0}
7174
if: matrix.os == 'windows-latest'
72-
run: mamba --version
75+
run: mamba.bat --version
7376
- name: Windows, no .bat, from Cmd
7477
shell: cmd /C call {0}
7578
if: matrix.os == 'windows-latest'

dist/delete/index.js

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/setup/index.js

Lines changed: 102 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/base-tools/update-mamba.ts

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as fs from "fs";
2+
import * as path from "path";
23

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

@@ -23,16 +24,59 @@ export const updateMamba: types.IToolProvider = {
2324
};
2425
},
2526
postInstall: async (inputs, options) => {
26-
if (!constants.IS_WINDOWS) {
27-
core.info("`mamba` is already executable");
28-
return;
29-
}
30-
core.info("Creating bash wrapper for `mamba`...");
31-
// Add bat-less forwarder for bash users on Windows
32-
const mambaBat = conda.condaExecutable(options).replace(/\\/g, "/");
27+
const mambaExec = conda.condaExecutable(options);
28+
const condabinLocation = path.join(
29+
conda.condaBasePath(options),
30+
"condabin",
31+
path.basename(mambaExec),
32+
);
33+
if (constants.IS_UNIX) {
34+
if (!fs.existsSync(condabinLocation)) {
35+
// This is mamba 2.x with only $PREFIX/bin/mamba,
36+
// we just need a symlink in condabin
37+
core.info(`Symlinking ${mambaExec} to ${condabinLocation}...`);
38+
fs.symlinkSync(mambaExec, condabinLocation);
39+
}
40+
} else {
41+
core.info(`Creating bash wrapper for 'mamba'...`);
42+
const mambaBat = condabinLocation.slice(0, -4) + ".bat";
43+
// Add bat-less forwarder for bash users on Windows
44+
const forwarderContents = `cmd.exe /C CALL "${mambaBat}" $* || exit 1`;
45+
fs.writeFileSync(condabinLocation.slice(0, -4), forwarderContents);
46+
core.info(`... wrote ${mambaExec.slice(0, -4)}:\n${forwarderContents}`);
47+
if (!fs.existsSync(mambaBat)) {
48+
// This is Windows and mamba 2.x, we need a mamba.bat like 1.x used to have
49+
const contents = `
50+
@REM Copyright (C) 2012 Anaconda, Inc
51+
@REM SPDX-License-Identifier: BSD-3-Clause
52+
53+
@REM echo _CE_CONDA is %_CE_CONDA%
54+
@REM echo _CE_M is %_CE_M%
55+
@REM echo CONDA_EXE is %CONDA_EXE%
56+
57+
@IF NOT DEFINED _CE_CONDA (
58+
@SET _CE_M=
59+
@SET "CONDA_EXE=%~dp0..\\Scripts\\conda.exe"
60+
)
61+
@IF [%1]==[activate] "%~dp0_conda_activate" %*
62+
@IF [%1]==[deactivate] "%~dp0_conda_activate" %*
63+
64+
@SET MAMBA_EXES="%~dp0..\\Library\\bin\\mamba.exe"
65+
@CALL %MAMBA_EXES% %*
3366
34-
const contents = `bash.exe -c "exec '${mambaBat}' $*" || exit 1`;
35-
fs.writeFileSync(mambaBat.slice(0, -4), contents);
36-
core.info(`... wrote ${mambaBat}:\n${contents}`);
67+
@IF %errorlevel% NEQ 0 EXIT /B %errorlevel%
68+
69+
@IF [%1]==[install] "%~dp0_conda_activate" reactivate
70+
@IF [%1]==[update] "%~dp0_conda_activate" reactivate
71+
@IF [%1]==[upgrade] "%~dp0_conda_activate" reactivate
72+
@IF [%1]==[remove] "%~dp0_conda_activate" reactivate
73+
@IF [%1]==[uninstall] "%~dp0_conda_activate" reactivate
74+
75+
@EXIT /B %errorlevel%`;
76+
core.info(`Creating .bat wrapper for 'mamba 2.x'...`);
77+
fs.writeFileSync(mambaBat, contents);
78+
core.info(`... wrote ${mambaBat}`);
79+
}
80+
}
3781
},
3882
};

0 commit comments

Comments
 (0)