Skip to content

Commit

Permalink
Merge c41b625 into b29329f
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikstranneheim committed Jan 7, 2021
2 parents b29329f + c41b625 commit 1478804
Show file tree
Hide file tree
Showing 11 changed files with 197 additions and 80 deletions.
47 changes: 46 additions & 1 deletion lib/MIP/Active_parameter.pm
Expand Up @@ -5,7 +5,7 @@ use Carp;
use charnames qw{ :full :short };
use Cwd;
use English qw{ -no_match_vars };
use File::Spec::Functions qw{ catfile splitpath };
use File::Spec::Functions qw{ catdir catfile splitpath };
use FindBin qw{ $Bin };
use open qw{ :encoding(UTF-8) :std };
use Params::Check qw{ allow check last_error };
Expand Down Expand Up @@ -46,6 +46,7 @@ BEGIN {
parse_recipe_resources
parse_vep_plugin
remove_sample_id_from_gender
set_conda_path
set_default_analysis_type
set_default_human_genome
set_default_infile_dirs
Expand Down Expand Up @@ -1300,6 +1301,50 @@ sub remove_sample_id_from_gender {
return;
}

sub set_conda_path {

## Function : Set path to root conda dir and the conda_environment_path based on the root path
## Returns :
## Arguments: $active_parameter_href => Active parameters for this analysis hash {REF}
## : $environment_name => MIP conda environment name

my ($arg_href) = @_;

## Flatten argument(s)
my $active_parameter_href;
my $environment_name;

my $tmpl = {
active_parameter_href => {
default => {},
defined => 1,
required => 1,
store => \$active_parameter_href,
strict_type => 1,
},
environment_name => {
defined => 1,
required => 1,
store => \$environment_name,
strict_type => 1,
},
};

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

use MIP::Environment::Path qw{ get_conda_path };

## Get path to conda
$active_parameter_href->{conda_path} = $active_parameter_href->{conda_path}
// get_conda_path( {} );

## Set path to conda env
$active_parameter_href->{conda_environment_path} =
catdir( $active_parameter_href->{conda_path}, q{envs}, $environment_name );

return;
}

sub set_default_analysis_type {

## Function : Set default analysis type to active parameters
Expand Down
15 changes: 10 additions & 5 deletions lib/MIP/Install.pm
Expand Up @@ -29,31 +29,36 @@ sub check_mip_executable {

## Function : Check if mip installation exists and is executable
## Returns :
## : $conda_prefix_path => Conda prefix path
## : $conda_environment_path => Conda environment name path

my ($arg_href) = @_;

## Flatten argument(s)
my $conda_prefix_path;
my $conda_environment_path;

my $tmpl = {
conda_prefix_path => {
conda_environment_path => {
defined => 1,
required => 1,
store => \$conda_prefix_path,
store => \$conda_environment_path,
strict_type => 1,
},
};

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

use MIP::Validate::Data qw{ %constraint };

my $log = Log::Log4perl->get_logger($LOG_NAME);

return 1 if ( not -x catfile( $conda_prefix_path, qw{ bin mip } ) );
my $mip_executable = catfile( $conda_environment_path, qw{ bin mip } );

return 1 if ( not $constraint{file_is_executable}->($mip_executable) );

$log->info(q{MIP is already installed in the specified conda environment.});

$log->warn(q{This will overwrite the current installation of MIP});

return;
}

Expand Down
18 changes: 7 additions & 11 deletions lib/MIP/Main/Install.pm
Expand Up @@ -12,15 +12,14 @@ use warnings qw{ FATAL utf8 };
use warnings;

## MIPs lib/
use MIP::Active_parameter qw{ update_to_absolute_path };
use MIP::Active_parameter qw{ set_conda_path update_to_absolute_path };
use MIP::Config qw{ check_cmd_config_vs_definition_file set_config_to_active_parameters };
use MIP::Constants qw{ $COLON $MIP_VERSION $SPACE };
use MIP::Environment::Container qw{ parse_containers };
use MIP::Io::Read qw{ read_from_file };
use MIP::Log::MIP_log4perl qw{ get_log };
use MIP::Parameter qw{ set_default };
use MIP::Pipeline qw{ run_install_pipeline };
use MIP::Set::Parameter qw{ set_conda_path };

BEGIN {
use base qw{ Exporter };
Expand Down Expand Up @@ -112,25 +111,22 @@ sub mip_install {
}
);
$log->info( q{MIP Version: } . $MIP_VERSION );
$log->info( q{Writing log messages to}
. $COLON
. $SPACE
. $active_parameter_href->{log_file} );
$log->info( q{Writing log messages to} . $COLON . $SPACE . $active_parameter_href->{log_file} );

## Set default from parameter hash to active_parameter for uninitilized parameters
set_default(
{
active_parameter_href => $active_parameter_href,
custom_default_parameters_ref =>
$parameter_href->{custom_default_parameters}{default},
parameter_href => $parameter_href,
active_parameter_href => $active_parameter_href,
custom_default_parameters_ref => $parameter_href->{custom_default_parameters}{default},
parameter_href => $parameter_href,
}
);

## Set path to conda
## Set path to conda and conda env path
set_conda_path(
{
active_parameter_href => $active_parameter_href,
environment_name => $active_parameter_href->{environment_name},
}
);

Expand Down
16 changes: 8 additions & 8 deletions lib/MIP/Recipes/Install/Mip_scripts.pm
Expand Up @@ -58,8 +58,8 @@ sub install_mip_scripts {

Readonly my $MOVE_DIRS_UP => 5;

my $conda_prefix_path = $active_parameter_href->{conda_prefix_path};
my @select_programs = @{ $active_parameter_href->{select_programs} };
my $conda_environment_path = $active_parameter_href->{conda_environment_path};
my @select_programs = @{ $active_parameter_href->{select_programs} };

return if ( none { $_ eq q{mip_scripts} } @select_programs );

Expand Down Expand Up @@ -104,15 +104,15 @@ sub install_mip_scripts {
# mip is proxy for all mip scripts
check_mip_executable(
{
conda_prefix_path => $conda_prefix_path,
conda_environment_path => $conda_environment_path,
}
);

## Create directories
DIRECTORY:
foreach my $directory ( keys %mip_sub_script ) {

path( catdir( $conda_prefix_path, q{bin}, $directory ) )->mkpath();
path( catdir( $conda_environment_path, q{bin}, $directory ) )->mkpath();
}

DIRECTORY:
Expand All @@ -121,8 +121,8 @@ sub install_mip_scripts {
my @cp_cmds = gnu_cp(
{
force => 1,
infile_path => catdir( $mip_dir_path, $directory ),
outfile_path => catdir( $conda_prefix_path, q{bin} ),
infile_path => catdir( $mip_dir_path, $directory ),
outfile_path => catdir( $conda_environment_path, q{bin} ),
recursive => 1,
}
);
Expand All @@ -146,7 +146,7 @@ sub install_mip_scripts {
foreach my $script (@mip_scripts) {

my $src_path = catfile( $mip_dir_path, $script );
my $dst_path = catfile( $conda_prefix_path, q{bin}, $script );
my $dst_path = catfile( $conda_environment_path, q{bin}, $script );
path($src_path)->copy($dst_path);
path($dst_path)->chmod(q{a+x});
}
Expand All @@ -158,7 +158,7 @@ sub install_mip_scripts {
foreach my $script ( @{ $mip_sub_script{$directory} } ) {

my $src_path = catfile( $mip_dir_path, $directory, $script );
my $dst_path = catfile( $conda_prefix_path, q{bin}, $directory, $script );
my $dst_path = catfile( $conda_environment_path, q{bin}, $directory, $script );

path($src_path)->copy($dst_path);
path($dst_path)->chmod(q{a+x});
Expand Down
38 changes: 0 additions & 38 deletions lib/MIP/Set/Parameter.pm
Expand Up @@ -20,49 +20,11 @@ BEGIN {

# Functions and variables which can be optionally exported
our @EXPORT_OK = qw{
set_conda_path
set_container_bind_paths
set_programs_for_installation
};
}

sub set_conda_path {

## Function : Set path to conda
## Returns :
## Arguments: $active_parameter_href => Active parameters for this analysis hash {REF}

my ($arg_href) = @_;

## Flatten argument(s)
my $active_parameter_href;

my $tmpl = {
active_parameter_href => {
default => {},
defined => 1,
required => 1,
store => \$active_parameter_href,
strict_type => 1,
},
};

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

use MIP::Environment::Path qw{ get_conda_path };

## Get path to conda
$active_parameter_href->{conda_path} = $active_parameter_href->{conda_path}
// get_conda_path( {} );

## Set path to conda env
my $environment_name = $active_parameter_href->{environment_name};
$active_parameter_href->{conda_prefix_path} =
catdir( $active_parameter_href->{conda_path}, q{envs}, $environment_name );

return;
}

sub set_programs_for_installation {

## Function : Process the lists of programs that has been selected for installation
Expand Down
11 changes: 6 additions & 5 deletions lib/MIP/Validate/Data.pm
Expand Up @@ -23,11 +23,12 @@ BEGIN {
}

our %constraint = (
file_exists => sub { return 1 if ( -e $_[0] ); return; },
dir_exists => sub { return 1 if ( -d $_[0] ); return; },
is_digit => sub { return 1 if ( $_[0] =~ / \A \d+ \z /sxm ); return; },
is_gzipped => sub { return 1 if ( $_[0] =~ / [.]gz$ /xms ); return 0; },
plain_file_exists => sub { return 1 if ( -f $_[0] ); return; },
file_exists => sub { return 1 if ( -e $_[0] ); return; },
file_is_executable => sub { return 1 if ( -x $_[0] ); return; },
dir_exists => sub { return 1 if ( -d $_[0] ); return; },
is_digit => sub { return 1 if ( $_[0] =~ / \A \d+ \z /sxm ); return; },
is_gzipped => sub { return 1 if ( $_[0] =~ / [.]gz$ /xms ); return 0; },
plain_file_exists => sub { return 1 if ( -f $_[0] ); return; },
);

1;
Expand Down
8 changes: 4 additions & 4 deletions t/check_mip_executable.t
Expand Up @@ -50,26 +50,26 @@ diag( q{Test check_mip_executable from Install.pm}
test_log( {} );

## Given no existing mip binary
my $conda_prefix_path = q{does_not_exists};
my $conda_environment_path = q{does_not_exists};

## When checking for executable
my $is_not_found = check_mip_executable(
{
conda_prefix_path => $conda_prefix_path,
conda_environment_path => $conda_environment_path,
}
);

## Then return true
ok( $is_not_found, q{Found no existing executable} );

## Given an existing mip binary
$conda_prefix_path = catfile( $Bin, qw{ data modules miniconda envs mip_ci } );
$conda_environment_path = catfile( $Bin, qw{ data modules miniconda envs mip_ci } );

## When checking for executable
trap {
check_mip_executable(
{
conda_prefix_path => $conda_prefix_path,
conda_environment_path => $conda_environment_path,
}
)
};
Expand Down
14 changes: 14 additions & 0 deletions t/constraint.t
Expand Up @@ -66,6 +66,20 @@ my $file_exist = catfile( $Bin, qw{ constraint.t } );
## Then return true
is( $constraint{file_exists}->($file_exist), 1, q{File exists - file exist} );

## Given a not executable file
my $file_is_not_executable = catfile( $Bin, qw{ constraint.t } );

## Then return false
is( $constraint{file_is_executable}->($file_is_not_executable),
undef, q{File is executable - file is not executable} );

## Given an executable file
my $file_is_executable = catfile( $Bin, qw{ data modules miniconda envs mip_ci bin mip} );

## Then return true
is( $constraint{file_is_executable}->($file_is_executable),
1, q{File is executable - file is executable} );

## Given a not gzipped file
my $filename = catfile(q{text.txt});

Expand Down
2 changes: 1 addition & 1 deletion t/data/test_data/install_active_parameters.yaml
Expand Up @@ -3,7 +3,7 @@ bash_set_errexit: '1'
bash_set_nounset: '0'
bash_set_pipefail: '1'
conda_path: <user_path>/miniconda3
conda_prefix_path: <user_path>/miniconda3/envs/mip_ci
conda_environment_path: <user_path>/miniconda3/envs/mip_ci
config_file: <user_path>/MIP/templates/mip_install_config.yaml
container:
arriba:
Expand Down
12 changes: 5 additions & 7 deletions t/install_mip_scripts.t
Expand Up @@ -33,8 +33,7 @@ BEGIN {
## Modules with import
my %perl_module = (
q{MIP::Recipes::Install::Mip_scripts} => [qw{ install_mip_scripts }],
q{MIP::Test::Fixtures} =>
[qw{ test_constants test_log test_mip_hashes }],
q{MIP::Test::Fixtures} => [qw{ test_constants test_log test_mip_hashes }],
);

test_import( { perl_module_href => \%perl_module, } );
Expand All @@ -54,11 +53,10 @@ test_log( { no_screen => 1, } );
test_constants( {} );

## Given install parameters
my %active_parameter =
test_mip_hashes( { mip_hash_name => q{install_active_parameter}, } );
my $conda_prefix_path = catdir( $Bin, qw{data modules miniconda envs install_test} );
my %active_parameter = test_mip_hashes( { mip_hash_name => q{install_active_parameter}, } );
my $conda_environment_path = catdir( $Bin, qw{data modules miniconda envs install_test} );

$active_parameter{conda_prefix_path} = $conda_prefix_path;
$active_parameter{conda_environment_path} = $conda_environment_path;

my $is_ok = install_mip_scripts(
{
Expand Down Expand Up @@ -90,6 +88,6 @@ trap {
is( $trap->leaveby, q{die}, q{Error in case of install failure} );
like( $trap->die, qr/Error \s+ message /xms, q{Print error} );

path($conda_prefix_path)->remove_tree;
path($conda_environment_path)->remove_tree;

done_testing();

0 comments on commit 1478804

Please sign in to comment.