Skip to content

Commit

Permalink
Add condaEnv variable that allow to use a conda environment for commands
Browse files Browse the repository at this point in the history
  • Loading branch information
AthAshino authored and LMaxence committed Mar 13, 2023
1 parent 5accabb commit 3be637d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/mookme/src/executor/package-executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class PackageExecutor {
packagePath: pkg.cwd,
type: pkg.type,
venvActivate: pkg.venvActivate,
condaEnv: pkg.condaEnv,
rootDir: options.rootDir,
}),
);
Expand Down
10 changes: 8 additions & 2 deletions packages/mookme/src/executor/step-executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions packages/mookme/src/loaders/hooks-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export class HooksResolver {
cwd: packagePath,
type: hooksDefinition.type,
venvActivate: hooksDefinition.venvActivate,
condaEnv: hooksDefinition.condaEnv,
steps: hooksDefinition.steps,
};

Expand Down
4 changes: 4 additions & 0 deletions packages/mookme/src/types/hook.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 3be637d

Please sign in to comment.