Skip to content

Commit

Permalink
Merge b1f8760 into e6f856e
Browse files Browse the repository at this point in the history
  • Loading branch information
jemten committed Jun 13, 2018
2 parents e6f856e + b1f8760 commit 18d8a94
Show file tree
Hide file tree
Showing 6 changed files with 378 additions and 155 deletions.
7 changes: 7 additions & 0 deletions definitions/install_rare_disease_parameters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,13 @@ noupdate: 0
# only applicaple for shell programs that overlap with existing conda packages
prefer_shell: 0

# Programs that needs to be installed together with pyhton 3, only tuch if you know what you're doing
python3_programs:
- chanjo
- genmod
- variant_integrity
- multiqc

# Supress output, both when generating the install script and running it
quiet: 0

Expand Down
3 changes: 3 additions & 0 deletions definitions/install_rna_parameters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ noupdate: 0
# only applicaple for shell programs that overlap with existing conda packages
prefer_shell: 0

# Programs that needs to be installed with pyhton 3, only tuch if you know what you're doing
python3_programs: []

# Supress output, both when generating the install script and running it
quiet: 0

Expand Down
110 changes: 109 additions & 1 deletion lib/MIP/Check/Installation.pm
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@ BEGIN {
our $VERSION = 1.01;

# Functions and variables which can be optionally exported
our @EXPORT_OK = qw{ check_existing_installation };
our @EXPORT_OK = qw{
check_existing_installation
check_python_compability
};
}

## Constants
Readonly my $NEWLINE => qq{\n};
Readonly my $SPACE => q{ };
Readonly my $TAB => qq{\t};

sub check_existing_installation {

Expand Down Expand Up @@ -155,4 +159,108 @@ sub check_existing_installation {
return 0;
}

sub check_python_compability {

## Function : Test if specified programs are to be installed in a python 3 environment
## Returns :
## Arguments: $installation_set_href => The environment specific installation hash {REF}
## : $log => Log
## : $python3_programs_ref => Programs requiring python 3
## : $python_version => The python version that are to be used for the environment
## : $select_programs_ref => Programs selected for installation by the user {REF}

my ($arg_href) = @_;

## Flatten argument(s)
my $installation_set_href;
my $log;
my $python3_programs_ref;
my $python_version;
my $select_programs_ref;

my $tmpl = {
installation_set_href => {
default => {},
defined => 1,
required => 1,
store => \$installation_set_href,
strict_type => 1,
},
log => {
defined => 1,
required => 1,
store => \$log,
},
python3_programs_ref => {
default => [],
defined => 1,
required => 1,
store => \$python3_programs_ref,
strict_type => 1,
},
python_version => {
required => 1,
store => \$python_version,
},
select_programs_ref => {
default => [],
required => 1,
store => \$select_programs_ref,
},
};

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

use Array::Utils qw{ intersect unique };

## Display warning if python isn't part of the installation
if ( not $python_version ) {
$log->warn(
q{Python is not part of the installation. Skipping python compability check.}
);
return;
}

## Check format of python version
if (
$python_version !~ m{
^(?: [23] ) # Assert that the python major version starts with 2 or 3
[.] # Major version separator
(?: \d+$ # Assert that the minor version is a digit
| \d+ [.] \d+$ ) # Case when minor and patch version has been supplied, allow only digits
}xms
)
{
$log->fatal( q{Please specify a python 2 or 3 version, given: }
. $python_version );
exit 1;
}

## Cover the case where no program has been actively chosen for installation
my @programs_to_check;
if ( not defined $select_programs_ref ) {
@programs_to_check = unique(
keys %{ $installation_set_href->{conda} },
keys %{ $installation_set_href->{shell} },
keys %{ $installation_set_href->{bioconda} },
keys %{ $installation_set_href->{pip} },
);
}
else {
@programs_to_check = @{$select_programs_ref};
}

my @conflicts = intersect( @programs_to_check, @{$python3_programs_ref} );

## Check if a python 2 environment has been specified and a python 3
## program has been specified for installation in that environment
if ( ( $python_version =~ m/^2/xms ) and ( scalar @conflicts > 0 ) ) {
$log->fatal(
q{Please use a python 3 environment for:} . $NEWLINE . join $TAB,
@conflicts );
exit 1;
}
return;
}

1;
53 changes: 0 additions & 53 deletions lib/MIP/Check/Modules_v5_10.pm

This file was deleted.

106 changes: 5 additions & 101 deletions lib/MIP/Main/Install.pm
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ BEGIN {
use base qw{ Exporter };

# Set the version for version checking
our $VERSION = q{1.2.3};
our $VERSION = q{1.2.4};

# Functions and variables that can be optionally exported
our @EXPORT_OK = qw{ mip_install };
Expand Down Expand Up @@ -360,6 +360,7 @@ sub get_programs_for_installation {
check( $tmpl, $arg_href, 1 ) or croak q{Could not parse arguments!};

use MIP::Get::Parameter qw{ get_programs_for_shell_installation };
use MIP::Check::Installation qw{ check_python_compability };

## Set install modes to loop over
my @install_modes = qw{ bioconda conda pip shell };
Expand All @@ -376,12 +377,13 @@ sub get_programs_for_installation {
@programs = uniq @programs;

## Exit if a python 2 env has ben specified for a python 3 program
_assure_python_compability(
check_python_compability(
{
installation_set_href => $parameter_href->{$installation},
python3_programs_ref => $parameter_href->{python3_programs},
python_version => $parameter_href->{$installation}{conda}{python},
select_programs_ref => $parameter_href->{select_programs},
sublog => $log,
log => $log,
}
);

Expand Down Expand Up @@ -464,104 +466,6 @@ q{Please select a single installation environment when using the option select_p
return;
}

sub _assure_python_compability {

## Function : Test if specified programs are to be installed in a python 3 environment
## Returns :
## Arguments: $installation_set_href => The environment specific installation hash {REF}
## : $python_version => The python version that are to be used for the environment
## : $select_programs_ref => Programs selected for installation by the user {REF}
## : $sub_log => Log

my ($arg_href) = @_;

## Flatten argument(s)
my $installation_set_href;
my $python_version;
my $select_programs_ref;
my $sub_log;

my $tmpl = {
sublog => {
defined => 1,
required => 1,
store => \$sub_log,
},
installation_set_href => {
default => {},
defined => 1,
required => 1,
store => \$installation_set_href,
strict_type => 1,
},
python_version => {
required => 1,
store => \$python_version,
},
select_programs_ref => {
default => [],
required => 1,
store => \$select_programs_ref,
},
};

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

use Array::Utils qw{ intersect unique };

## Display warning if python isn't part of the installation
if ( not $python_version ) {
$sub_log->warn(
q{Python is not part of the installation. Skipping python compability check.}
);
return;
}

## Check format of python version
if (
$python_version !~ m{
^(?: [23] ) # Assert that the python major version starts with 2 or 3
[.] # Major version separator
(?: \d+$ # Assert that the minor version is a digit
| \d+ [.] \d+$ ) # Case when minor and patch version has been supplied, allow only digits
}xms
)
{
$sub_log->fatal( q{Please specify a python 2 or 3 version, given: }
. $python_version );
exit 1;
}

## Define python 3 programs
my @py3_programs = qw{ chanoj genmod variant_integrity multiqc };

## Cover the case where no program has ben actively chosen for installation
my @programs_to_check;
if ( not defined $select_programs_ref ) {
@programs_to_check = unique(
keys %{ $installation_set_href->{conda} },
keys %{ $installation_set_href->{shell} },
keys %{ $installation_set_href->{bioconda} },
keys %{ $installation_set_href->{pip} },
);
}
else {
@programs_to_check = @{$select_programs_ref};
}

my @conflicts = intersect( @programs_to_check, @py3_programs );

## Check if a python 2 environment has been specified and a python 3
## program has been specified for installation in that environment
if ( ( $python_version =~ m/^2/xms ) and ( scalar @conflicts > 0 ) ) {
$sub_log->fatal(
q{Please use a python 3 environment for:} . $NEWLINE . join $TAB,
@conflicts );
exit 1;
}
return;
}

sub display_final_message {

## Function : Displays a final message to the user at the end of the installation process
Expand Down

0 comments on commit 18d8a94

Please sign in to comment.