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

PR: Allow activate-environment to be a path #137

Merged
merged 1 commit into from
Dec 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions .github/workflows/example-6.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ jobs:
fail-fast: false
matrix:
os: ["ubuntu-latest", "macos-latest", "windows-latest"]
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
defaults:
run:
shell: bash -l {0}
Expand All @@ -32,9 +39,9 @@ jobs:
with:
python-version: "3.7"
mamba-version: "*"
channels: conda-forge,defaults
channels: conda-forge,nodefaults
channel-priority: true
activate-environment: anaconda-client-env
activate-environment: ${{ matrix.activate-environment }}
environment-file: etc/example-environment.yml
- run: |
conda info
Expand Down
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,28 @@ This action will by default will not activate the `base`environment and activate
This enforces the idea of not using the `base` environment to install packages used for the action and
leave the `base` environment untouched, with only `conda` (or `mamba`) in it.

### Use a different environment name
### Use a different environment name or path

You can change the default `test` environment to have a different name bu setting the
`activate-environment` input option.
You can change the default `test` environment to have a different name or path by
setting the `activate-environment` input option.

```yaml
- uses: conda-incubator/setup-miniconda@v2
with:
activate-environment: whatever
```

This will be create a _named_ env in `$CONDA/envs/whatever`, where `$CONDA` is the
path to the infrequently-updated, but **very fast** to start, "bundled" Miniconda
installation.

> - If `activate-environment` contains either POSIX or Windows slashes, it will be
> interpreted as a path, or "prefix" in `conda` terminology. Use this to avoid
> "path too long"-style errors, especially on windows.
> - Self-hosted runners can emulate the "bundled" Miniconda approach by pre-installing
> _a_ Miniconda-like installer and ensuring `$CONDA` is set prior to starting
> `setup-miniconda`

### Activate `base` environment

If your specific workflow still needs to activate and use `base` you will need to set the
Expand Down
11 changes: 6 additions & 5 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,13 @@ inputs:
default: ""
activate-environment:
description:
'Environment to activate by default on all shells. Default is "test". If
an empty string is used, no environment is activated by default (For
"base" activation see the "auto-activate-base" option). If the environment
does not exist, it will be created and activated. If "environment-file" is
'Environment name (or path) to activate on all shells. Default is
`test` which will be created in `$CONDA/envs/test`. If an empty string is used,
no environment is activated by default (For `base` activation see the
`auto-activate-base` option). If the environment
does not exist, it will be created and activated. If `environment-file` is
used and you want that to be the environment used, you need to explicitely
provide the name of that environment on "activate-environment". If using
provide the name of that environment on `activate-environment`. If using
sh/bash/cmd.exe shells please read the IMPORTANT! section on the
README.md! to properly activate conda environments on these shells.'
required: false
Expand Down
90 changes: 55 additions & 35 deletions dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.ensureSimple = void 0;
const core = __importStar(__webpack_require__(470));
const utils = __importStar(__webpack_require__(163));
const conda = __importStar(__webpack_require__(259));
/**
* Install an environment with `conda create` when no `envSpec` is detected
*
Expand All @@ -1167,7 +1168,7 @@ exports.ensureSimple = {
Object.keys(((_c = options.envSpec) === null || _c === void 0 ? void 0 : _c.yaml) || {}).length);
}),
condaArgs: (inputs, options) => __awaiter(void 0, void 0, void 0, function* () {
const args = ["create", "--name", inputs.activateEnvironment];
const args = ["create", ...conda.envCommandFlag(inputs)];
if (inputs.pythonVersion) {
const spec = utils.makeSpec("python", inputs.pythonVersion);
core.info(`Adding spec: ${spec}`);
Expand Down Expand Up @@ -2126,16 +2127,13 @@ function installBaseTools(inputs, options) {
tools.push(...toolUpdates.tools);
postInstallOptions = Object.assign(Object.assign({}, postInstallOptions), toolUpdates.options);
if (provider.postInstall) {
core.info(`... we will perform post-intall steps after we ${provider.label}.`);
core.info(`... we will perform post-install steps after we ${provider.label}.`);
postInstallActions.push(provider.postInstall);
}
}
}
if (tools.length) {
yield conda.condaCommand(["install", "--name", "base", ...tools],
// Use the original `options`, as we can't guarantee `mamba` is available
// TODO: allow declaring that the installer already has `mamba`
options);
yield conda.condaCommand(["install", "--name", "base", ...tools], options);
// *Now* use the new options, as we may have a new conda/mamba with more supported
// options that previously failed
yield conda.applyCondaConfiguration(inputs, postInstallOptions);
Expand Down Expand Up @@ -7086,7 +7084,7 @@ var attributeRules = {
if(len === 0){
return falseFunc;
}

if(data.ignoreCase){
value = value.toLowerCase();

Expand Down Expand Up @@ -7254,7 +7252,7 @@ exports.prepend = function(elem, prev){
if(elem.prev){
elem.prev.next = prev;
}

prev.parent = parent;
prev.prev = elem.prev;
prev.next = elem;
Expand Down Expand Up @@ -8525,7 +8523,7 @@ Parser.prototype.onclosetag = function(name) {
if (this._lowerCaseTagNames) {
name = name.toLowerCase();
}

if (name in foreignContextElements || name in htmlIntegrationElements) {
this._foreignContext.pop();
}
Expand Down Expand Up @@ -8574,7 +8572,7 @@ Parser.prototype._closeCurrentTag = function() {
this._cbs.onclosetag(name);
}
this._stack.pop();

}
};

Expand Down Expand Up @@ -13019,7 +13017,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.condaInit = exports.applyCondaConfiguration = exports.copyConfig = exports.bootstrapConfig = exports.condaCommand = exports.isMambaInstalled = exports.condaExecutable = exports.condaBasePath = void 0;
exports.condaInit = exports.applyCondaConfiguration = exports.copyConfig = exports.bootstrapConfig = exports.condaCommand = exports.isMambaInstalled = exports.condaExecutable = exports.envCommandFlag = exports.condaBasePath = void 0;
const fs = __importStar(__webpack_require__(747));
const path = __importStar(__webpack_require__(622));
const os = __importStar(__webpack_require__(87));
Expand All @@ -13043,6 +13041,19 @@ function condaBasePath(options) {
return condaPath;
}
exports.condaBasePath = condaBasePath;
/**
* Provide conda CLI arguments for identifying an env by name or prefix/path
*
* ### Note
* Only really detects by presence of a path separator, as the path may not yet exist
*/
function envCommandFlag(inputs) {
return [
inputs.activateEnvironment.match(/(\\|\/)/) ? "--prefix" : "--name",
inputs.activateEnvironment,
];
}
exports.envCommandFlag = envCommandFlag;
/**
* Provide cross platform location of conda/mamba executable
*/
Expand Down Expand Up @@ -13142,9 +13153,7 @@ exports.applyCondaConfiguration = applyCondaConfiguration;
function condaInit(inputs, options) {
return __awaiter(this, void 0, void 0, function* () {
let ownPath;
const isValidActivate = inputs.activateEnvironment !== "base" &&
inputs.activateEnvironment !== "root" &&
inputs.activateEnvironment !== "";
const isValidActivate = !utils.isBaseEnv(inputs.activateEnvironment);
const autoActivateBase = options.condaConfig["auto_activate_base"] === "true";
// Fix ownership of folders
if (options.useBundled) {
Expand Down Expand Up @@ -13207,7 +13216,7 @@ function condaInit(inputs, options) {
if (isValidActivate) {
powerExtraText += `
# Conda Setup Action: Custom activation
conda activate ${inputs.activateEnvironment}`;
conda activate "${inputs.activateEnvironment}"`;
}
powerExtraText += `
# ----------------------------------------------------------------------------`;
Expand All @@ -13219,7 +13228,7 @@ function condaInit(inputs, options) {
if (isValidActivate) {
bashExtraText += `
# Conda Setup Action: Custom activation
conda activate ${inputs.activateEnvironment}`;
conda activate "${inputs.activateEnvironment}"`;
bashExtraText += `
# ----------------------------------------------------------------------------`;
}
Expand All @@ -13234,7 +13243,7 @@ function condaInit(inputs, options) {
if (isValidActivate) {
batchExtraText += `
:: Conda Setup Action: Custom activation
@CALL "%CONDA_BAT%" activate ${inputs.activateEnvironment}`;
@CALL "%CONDA_BAT%" activate "${inputs.activateEnvironment}"`;
}
batchExtraText += `
:: Conda Setup Action: Basic configuration
Expand Down Expand Up @@ -15654,7 +15663,7 @@ DomHandler.prototype.onerror = function(error){

DomHandler.prototype.onclosetag = function(){
//if(this._tagStack.pop().name !== name) this._handleCallback(Error("Tagname didn't match!"));

var elem = this._tagStack.pop();

if(this._options.withEndIndices && elem){
Expand Down Expand Up @@ -15819,10 +15828,29 @@ module.exports = DomHandler;
/* 283 */,
/* 284 */,
/* 285 */
/***/ (function(__unusedmodule, exports) {
/***/ (function(__unusedmodule, exports, __webpack_require__) {

"use strict";

var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
Expand All @@ -15834,6 +15862,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ensureExplicit = void 0;
const conda = __importStar(__webpack_require__(259));
/**
* Install an environment from an explicit file generated `conda list --explicit`
* or `conda-lock`
Expand All @@ -15847,8 +15876,7 @@ exports.ensureExplicit = {
}
return [
"create",
"--name",
inputs.activateEnvironment,
...conda.envCommandFlag(inputs),
"--file",
inputs.environmentFile,
];
Expand Down Expand Up @@ -20585,6 +20613,7 @@ const path = __importStar(__webpack_require__(622));
const yaml = __importStar(__webpack_require__(414));
const core = __importStar(__webpack_require__(470));
const constants = __importStar(__webpack_require__(211));
const conda = __importStar(__webpack_require__(259));
const utils = __importStar(__webpack_require__(163));
/**
* The current known providers of patches to `environment.yml`
Expand Down Expand Up @@ -20663,8 +20692,7 @@ exports.ensureYaml = {
return [
"env",
"update",
"--name",
inputs.activateEnvironment,
...conda.envCommandFlag(inputs),
"--file",
envFile,
];
Expand Down Expand Up @@ -35395,7 +35423,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getEnvSpec = exports.environmentExists = exports.ensureEnvironment = void 0;
exports.getEnvSpec = exports.ensureEnvironment = void 0;
const path = __importStar(__webpack_require__(622));
const fs = __importStar(__webpack_require__(747));
const yaml = __importStar(__webpack_require__(414));
Expand Down Expand Up @@ -35436,14 +35464,6 @@ function ensureEnvironment(inputs, options) {
});
}
exports.ensureEnvironment = ensureEnvironment;
/**
* Check if a given conda environment exists
*/
function environmentExists(inputs, options) {
const condaMetaPath = path.join(conda.condaBasePath(options), "envs", inputs.activateEnvironment, "conda-meta");
return fs.existsSync(condaMetaPath);
}
exports.environmentExists = environmentExists;
/**
* Read and potentially parse the `environment-file`
*
Expand Down Expand Up @@ -38321,7 +38341,7 @@ LocationInfoTokenizerMixin.prototype._getOverriddenMethods = function (mxn, orig
/******/ ],
/******/ function(__webpack_require__) { // webpackRuntimeModules
/******/ "use strict";
/******/
/******/
/******/ /* webpack/runtime/node module decorator */
/******/ !function() {
/******/ __webpack_require__.nmd = function(module) {
Expand All @@ -38338,6 +38358,6 @@ LocationInfoTokenizerMixin.prototype._getOverriddenMethods = function (mxn, orig
/******/ return module;
/******/ };
/******/ }();
/******/
/******/
/******/ }
);
);
9 changes: 2 additions & 7 deletions src/base-tools/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,15 @@ export async function installBaseTools(
postInstallOptions = { ...postInstallOptions, ...toolUpdates.options };
if (provider.postInstall) {
core.info(
`... we will perform post-intall steps after we ${provider.label}.`
`... we will perform post-install steps after we ${provider.label}.`
);
postInstallActions.push(provider.postInstall);
}
}
}

if (tools.length) {
await conda.condaCommand(
["install", "--name", "base", ...tools],
// Use the original `options`, as we can't guarantee `mamba` is available
// TODO: allow declaring that the installer already has `mamba`
options
);
await conda.condaCommand(["install", "--name", "base", ...tools], options);

// *Now* use the new options, as we may have a new conda/mamba with more supported
// options that previously failed
Expand Down
Loading