From 3be637d6a5d6d9338a45d09e0cec10965fb63306 Mon Sep 17 00:00:00 2001 From: Ashino Date: Mon, 13 Mar 2023 09:12:05 +0100 Subject: [PATCH] Add condaEnv variable that allow to use a conda environment for commands --- packages/mookme/src/executor/package-executor.ts | 1 + packages/mookme/src/executor/step-executor.ts | 10 ++++++++-- packages/mookme/src/loaders/hooks-resolver.ts | 1 + packages/mookme/src/types/hook.types.ts | 4 ++++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/mookme/src/executor/package-executor.ts b/packages/mookme/src/executor/package-executor.ts index 9cfdb4c..d646efc 100644 --- a/packages/mookme/src/executor/package-executor.ts +++ b/packages/mookme/src/executor/package-executor.ts @@ -36,6 +36,7 @@ export class PackageExecutor { packagePath: pkg.cwd, type: pkg.type, venvActivate: pkg.venvActivate, + condaEnv: pkg.condaEnv, rootDir: options.rootDir, }), ); diff --git a/packages/mookme/src/executor/step-executor.ts b/packages/mookme/src/executor/step-executor.ts index a929fa6..948161d 100644 --- a/packages/mookme/src/executor/step-executor.ts +++ b/packages/mookme/src/executor/step-executor.ts @@ -27,6 +27,10 @@ export interface ExecuteStepOptions { * An optional path to a virtualenv to use (only used if type is {@link PackageType.PYTHON}) */ venvActivate?: string; + /** + * An optional conda env to use + */ + condaEnv?: string; } /** @@ -89,9 +93,11 @@ export class StepExecutor { */ computeExecutedCommand(): string { // Add eventual virtual env to activate before the command - const { type, venvActivate } = this.options; + const { type, venvActivate, condaEnv } = this.options; const { command } = this.step; - const execute = type === 'python' && venvActivate ? `source ${venvActivate} && ${command} && deactivate` : command; + const env_execute = + type === 'python' && venvActivate ? `source ${venvActivate} && ${command} && deactivate` : command; + const execute = condaEnv ? `conda run -n ${condaEnv} ""${env_execute}""` : env_execute; return execute; } diff --git a/packages/mookme/src/loaders/hooks-resolver.ts b/packages/mookme/src/loaders/hooks-resolver.ts index 4ce28a4..ee1c00f 100644 --- a/packages/mookme/src/loaders/hooks-resolver.ts +++ b/packages/mookme/src/loaders/hooks-resolver.ts @@ -135,6 +135,7 @@ export class HooksResolver { cwd: packagePath, type: hooksDefinition.type, venvActivate: hooksDefinition.venvActivate, + condaEnv: hooksDefinition.condaEnv, steps: hooksDefinition.steps, }; diff --git a/packages/mookme/src/types/hook.types.ts b/packages/mookme/src/types/hook.types.ts index 909d4d7..9a9bb25 100644 --- a/packages/mookme/src/types/hook.types.ts +++ b/packages/mookme/src/types/hook.types.ts @@ -58,6 +58,10 @@ export interface UnprocessedPackageHook { * A boolean denoting whether a virtualenv is started of not for this hook (eg for Python) */ venvActivate?: string; + /** + * The conda environment we want to use to start this hook. Optional + */ + condaEnv?: string; } export interface PackageHook extends UnprocessedPackageHook {