Skip to content

Commit

Permalink
initiate conda
Browse files Browse the repository at this point in the history
  • Loading branch information
jemten committed Nov 21, 2022
1 parent e94cd8a commit 13cf1b9
Show file tree
Hide file tree
Showing 13 changed files with 83 additions and 47 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [11.0.3]

- Initiate conda prior to activation

## [11.0.2]

Updates chromograph
Expand Down
21 changes: 10 additions & 11 deletions lib/MIP/Active_parameter.pm
Expand Up @@ -656,14 +656,12 @@ sub check_sample_id_in_hash_parameter_path {
## Check sample_id are unique
next SAMPLE_ID if ( $seen{$sample_id} < 2 );

$log->fatal(
q{Sample_id: }
$log->fatal( q{Sample_id: }
. $sample_id
. q{ is not uniqe in '--}
. $parameter_name . q{': }
. $path . q{=}
. $sample_ids_str,
);
. $sample_ids_str, );
exit 1;
}
}
Expand All @@ -677,14 +675,12 @@ sub check_sample_id_in_hash_parameter_path {

my $seen_sample_ids = join $COMMA . $SPACE, ( keys %seen );

$log->fatal(
q{Could not detect }
$log->fatal( q{Could not detect }
. $sample_id
. q{ for '--}
. $parameter_name
. q{'. Provided sample_ids are: }
. $seen_sample_ids,
);
. $seen_sample_ids, );
exit 1;
}
}
Expand Down Expand Up @@ -1042,11 +1038,14 @@ sub get_package_env_cmds {
}

## Get env load command
my $conda_init_path =
catfile( $active_parameter_href->{conda_path}, qw{ etc profile.d conda.sh } );
my @env_method_cmds = get_env_method_cmds(
{
action => q{load},
env_name => $env_name,
env_method => $env_method,
action => q{load},
conda_init_path => $conda_init_path,
env_name => $env_name,
env_method => $env_method,
}
);
return @env_method_cmds;
Expand Down
2 changes: 1 addition & 1 deletion lib/MIP/Constants.pm
Expand Up @@ -81,7 +81,7 @@ Readonly our %ANALYSIS => (
);

## Set MIP version
Readonly our $MIP_VERSION => q{11.0.2};
Readonly our $MIP_VERSION => q{11.0.3};

## Cli
Readonly our $MOOSEX_APP_SCEEN_WIDTH => 160;
Expand Down
20 changes: 16 additions & 4 deletions lib/MIP/Environment/Manager.pm
Expand Up @@ -28,14 +28,16 @@ sub get_env_method_cmds {

## Function : Get the standard load and unload env command for environment method
## Returns : @env_method_cmds
## Arguments: $action => What to do with the environment
## : $env_method => Method used to load environment
## : $env_name => Name of environment
## Arguments: $action => What to do with the environment
## : $conda_init path => path to initialize conda
## : $env_method => Method used to load environment
## : $env_name => Name of environment

my ($arg_href) = @_;

## Flatten argument(s)
my $action;
my $conda_init_path;
my $env_method;
my $env_name;

Expand All @@ -47,6 +49,10 @@ sub get_env_method_cmds {
store => \$action,
strict_type => 1,
},
conda_init_path => {
store => \$conda_init_path,
strict_type => 1,
},
env_method => {
allow => [qw{ conda }],
defined => 1,
Expand All @@ -67,7 +73,13 @@ sub get_env_method_cmds {

my %method_cmd = (
conda => {
load => [ ( conda_activate( { env_name => $env_name, } ), ) ],
load => [
(
conda_activate(
{ conda_init_path => $conda_init_path, env_name => $env_name, }
),
)
],
unload => [ ( conda_deactivate( {} ), ) ],
},
);
Expand Down
22 changes: 16 additions & 6 deletions lib/MIP/Program/Conda.pm
Expand Up @@ -14,7 +14,7 @@ use warnings qw{ FATAL utf8 };
use warnings;

## MIPs lib/
use MIP::Constants qw{ $LOG_NAME $NEWLINE $SPACE };
use MIP::Constants qw{ $LOG_NAME $NEWLINE $SEMICOLON $SPACE };
use MIP::Unix::Write_to_file qw{ unix_write_to_file };

BEGIN {
Expand All @@ -30,16 +30,22 @@ sub conda_activate {

##Function : Activate conda environment
##Returns : @commands
##Arguments: $env_name => Name of conda environment
## : $filehandle => Filehandle to write to
##Arguments: $conda_init path => path to initialize conda
## : $env_name => Name of conda environment
## : $filehandle => Filehandle to write to

my ($arg_href) = @_;

## Flatten argument(s)
my $conda_init_path;
my $env_name;
my $filehandle;

my $tmpl = {
conda_init_path => {
store => \$conda_init_path,
strict_type => 1,
},
env_name => {
required => 1,
store => \$env_name,
Expand All @@ -52,10 +58,14 @@ sub conda_activate {

check( $tmpl, $arg_href, 1 ) or croak q{Could not parse arguments!};

## Stores commands depending on input parameters
my @commands;

if ($conda_init_path) {

push @commands, ( q{source}, $conda_init_path, $SEMICOLON );
}

# Basic command
my @commands = qw{ conda activate };
push @commands, qw{ conda activate };

# Activates env, default base
push @commands, $env_name;
Expand Down
2 changes: 1 addition & 1 deletion lib/MIP/Script/Setup_script.pm
Expand Up @@ -663,7 +663,7 @@ sub setup_script {
{
bash_bin_path => catfile( rootdir(), qw{ bin bash } ),
filehandle => $filehandle,
invoke_login_shell => 1,
invoke_login_shell => 0,
}
);
print {$filehandle} $NEWLINE;
Expand Down
26 changes: 16 additions & 10 deletions t/conda_activate.t
Expand Up @@ -5,7 +5,7 @@ use Carp;
use charnames qw{ :full :short };
use English qw{ -no_match_vars };
use File::Basename qw{ dirname };
use File::Spec::Functions qw{ catdir };
use File::Spec::Functions qw{ catdir catfile };
use FindBin qw{ $Bin };
use open qw{ :encoding(UTF-8) :std };
use Params::Check qw{ allow check last_error };
Expand All @@ -19,19 +19,16 @@ use Modern::Perl qw{ 2018 };

## MIPs lib/
use lib catdir( dirname($Bin), q{lib} );
use MIP::Constants qw{ $COMMA $SPACE };
use MIP::Constants qw{ $COMMA $SEMICOLON $SPACE };
use MIP::Test::Commands qw{ test_function };


BEGIN {

use MIP::Test::Fixtures qw{ test_import };

### Check all internal dependency modules and imports
## Modules with import
my %perl_module = (
q{MIP::Program::Conda} => [qw{ conda_activate }],
);
my %perl_module = ( q{MIP::Program::Conda} => [qw{ conda_activate }], );

test_import( { perl_module_href => \%perl_module, } );
}
Expand All @@ -48,7 +45,8 @@ diag( q{Test conda_activate from Conda.pm}
. $EXECUTABLE_NAME );

## Base arguments
my @function_base_commands = qw{ conda activate };
my @source_commands = ( q{source}, catfile(qw{path to conda etc profile.d conda.sh}), $SEMICOLON );
my @function_base_commands = ( @source_commands, qw{ conda activate } );

my %base_argument = (
filehandle => {
Expand All @@ -59,14 +57,22 @@ my %base_argument = (

## Can be duplicated with %base and/or %specific to enable testing of each individual argument
my %required_argument = (
filehandle => {
input => undef,
expected_output => \@function_base_commands,
conda_init_path => {
input => catfile(qw{path to conda etc profile.d conda.sh}),
expected_output => q{source}
. $SPACE
. catfile(qw{path to conda etc profile.d conda.sh})
. $SPACE
. $SEMICOLON,
},
env_name => {
input => q{test_env},
expected_output => q{test_env},
},
filehandle => {
input => undef,
expected_output => \@function_base_commands,
},
);

## Coderef - enables generalized use of generate call
Expand Down
20 changes: 11 additions & 9 deletions t/get_env_method_cmds.t
Expand Up @@ -5,7 +5,7 @@ use Carp;
use charnames qw{ :full :short };
use English qw{ -no_match_vars };
use File::Basename qw{ dirname };
use File::Spec::Functions qw{ catdir };
use File::Spec::Functions qw{ catdir catfile };
use FindBin qw{ $Bin };
use open qw{ :encoding(UTF-8) :std };
use Params::Check qw{ allow check last_error };
Expand All @@ -21,16 +21,13 @@ use Modern::Perl qw{ 2018 };
use lib catdir( dirname($Bin), q{lib} );
use MIP::Constants qw{ $COMMA $SPACE };


BEGIN {

use MIP::Test::Fixtures qw{ test_import };

### Check all internal dependency modules and imports
## Modules with import
my %perl_module = (
q{MIP::Environment::Manager} => [qw{ get_env_method_cmds }],
);
my %perl_module = ( q{MIP::Environment::Manager} => [qw{ get_env_method_cmds }], );

test_import( { perl_module_href => \%perl_module, } );
}
Expand All @@ -51,12 +48,17 @@ my $env_name = q{test_env};

my @env_cmds = get_env_method_cmds(
{
action => q{load},
env_name => $env_name,
env_method => $env_method,
action => q{load},
conda_init_path => catfile(qw{path to conda etc profile.d conda.sh}),
env_name => $env_name,
env_method => $env_method,
}
);
my @expected_load_cmds = ( qw{ conda activate }, $env_name );
my @expected_load_cmds = (
q{source},
catfile(qw{path to conda etc profile.d conda.sh}),
qw{ ; conda activate }, $env_name,
);

## Then return load env commands
is_deeply( \@expected_load_cmds, \@env_cmds, q{Got env load cmds} );
Expand Down
3 changes: 2 additions & 1 deletion t/get_package_env_cmds.t
Expand Up @@ -54,6 +54,7 @@ my %active_parameter = (
$program_name => undef,
},
},
conda_path => catdir(qw{ path to conda }),
);

## When no prior to load cmd
Expand All @@ -67,7 +68,7 @@ my @program_environment_cmds = get_package_env_cmds(
## Then return command to activate environment for package
is_deeply(
\@program_environment_cmds,
[qw{ conda activate mip_pyv3.6 }],
[qw{ source path/to/conda/etc/profile.d/conda.sh ; conda activate mip_pyv3.6 }],
q{Got package environment command}
);

Expand Down
3 changes: 2 additions & 1 deletion t/get_recipe_resources.t
Expand Up @@ -57,6 +57,7 @@ test_log( { no_screen => 1, } );
## Given a recipe name and active parameter hash
my %active_parameter =
test_mip_hashes( { mip_hash_name => q{active_parameter}, recipe_name => q{deepvariant}, } );
$active_parameter{conda_path} = catdir(qw{path to conda});
my $recipe_name = q{deepvariant};

my %recipe_resource = get_recipe_resources(
Expand All @@ -70,7 +71,7 @@ my %recipe_resource = get_recipe_resources(
my %expected = (
core_number => 35,
gpu_number => 1,
load_env_ref => [qw{ conda activate test }],
load_env_ref => [qw{ source path/to/conda/etc/profile.d/conda.sh ; conda activate test }],
memory => 175,
mode => 2,
time => 10,
Expand Down
2 changes: 1 addition & 1 deletion t/mip_analyse_rd_dna.test
Expand Up @@ -163,7 +163,7 @@ while ( my ( $pedigree, $pedigree_path ) = each %pedigree ) {
}

## Clean-up
#remove_tree( catfile( $cluster_constant_path, qw{ 643594-miptest analysis } ) );
remove_tree( catfile( $cluster_constant_path, qw{ 643594-miptest analysis } ) );

GENOME_BUILD:
foreach my $genome_build (@genome_builds) {
Expand Down
3 changes: 2 additions & 1 deletion t/parse_recipe_prerequisites.t
Expand Up @@ -52,6 +52,7 @@ test_log( { no_screen => 1, } );
my $recipe_name = q{deepvariant};
my %active_parameter =
test_mip_hashes( { mip_hash_name => q{active_parameter}, recipe_name => $recipe_name, } );
$active_parameter{conda_path} = catdir(qw{path to conda});

## Given a parameter hash
my %parameter =
Expand All @@ -77,7 +78,7 @@ my %expected_recipe = (
file_tag => q{_deepvar},
gpu_number => 1,
job_id_chain => q{TEST},
load_env_ref => [qw{ conda activate test }],
load_env_ref => [qw{ source path/to/conda/etc/profile.d/conda.sh ; conda activate test }],
memory => 175,
mode => 2,
outfile_suffix => q{.g.vcf.gz},
Expand Down
2 changes: 1 addition & 1 deletion templates/mip_install_config.yaml
Expand Up @@ -121,7 +121,7 @@ container:
mip:
executable:
mip:
uri: docker.io/clinicalgenomics/mip:v11.0.2
uri: docker.io/clinicalgenomics/mip:v11.0.3
multiqc:
executable:
multiqc:
Expand Down

0 comments on commit 13cf1b9

Please sign in to comment.