Skip to content

Commit

Permalink
Merge pull request #14 from orkunkaraduman/dev
Browse files Browse the repository at this point in the history
v1.07
  • Loading branch information
orkunkaraduman authored Dec 4, 2016
2 parents 203f5e5 + 685de1f commit 9d7bed2
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 75 deletions.
7 changes: 7 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
1.07 2016-12-04
- Minimum Perl version setted v5.14
- Added piv install -t
- Added piv install -s
- Module.pm checking installed module is fixed
- Module.pm $Config{sitearch} fix

1.06 2016-12-04
- Added piv remove -f
- Added piv virtualenv -e
Expand Down
2 changes: 1 addition & 1 deletion Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use ExtUtils::MakeMaker;
WriteMakefile(
NAME => 'App::Virtualenv',
VERSION_FROM => 'lib/App/Virtualenv.pm',
MIN_PERL_VERSION => 'v5.10',
MIN_PERL_VERSION => '5.014',
PREREQ_PM => { 'local::lib' => 0, 'Switch' => 0, 'FindBin' => 0, 'Cwd' => 0, 'File::Basename' => 0, 'ExtUtils::Installed' => 0, 'CPAN' => 0, 'CPANPLUS' => 0, },
EXE_FILES => [ qw(
lib/App/Virtualenv/virtualenv.pl
Expand Down
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,28 @@ list installed packages under Perl virtual environment

> [*environment_path*/bin/]piv list [-1]
**-1** One column list

#### piv install

install or upgrade packages under Perl virtual environment

> [*environment_path*/bin/]piv install [-f] *package*...
> [*environment_path*/bin/]piv install [-f] [-t] [-s] *package*...
**-f** Force

**-t** Run tests

**-s** Soft install without installing prerequisites

#### piv remove

remove packages under Perl virtual environment

> [*environment_path*/bin/]piv remove [-f] *package*...
**-f** Force

## INSTALLATION

To install this module type the following
Expand Down
8 changes: 6 additions & 2 deletions bin/test.pl
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ =head1 SYNOPSIS
use App::Virtualenv::Piv;


my $inst = ExtUtils::Installed->new;
my @a = $inst->directory_tree("Net::Twitter", "all");
say Dumper(\@a);
exit;
#exit App::Virtualenv::Module::install(force => 1, modules => ['ExtUtils::Installed']);
exit App::Virtualenv::Piv::main(@ARGV);
exit App::Virtualenv::perl("-I${FindBin::Bin}/../lib", "-MApp::Virtualenv::Module", "-e exit App::Virtualenv::Module::${ARGV[0]}('${ARGV[1]}');");
#exit App::Virtualenv::Piv::main(@ARGV);
#exit App::Virtualenv::perl("-I${FindBin::Bin}/../lib", "-MApp::Virtualenv::Module", "-e exit App::Virtualenv::Module::${ARGV[0]}('${ARGV[1]}');");
=head1 AUTHOR
Orkun Karaduman <orkunkaraduman@gmail.com>
Expand Down
10 changes: 5 additions & 5 deletions lib/App/Virtualenv.pm
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package App::Virtualenv;
=head1 NAME
App::Virtualenv - Perl virtual environment core
App::Virtualenv - Perl virtual environment
=head1 VERSION
version 1.06
version 1.07
=head1 SYNOPSIS
Perl virtual environment core
Perl virtual environment
=cut
use strict;
Expand All @@ -29,7 +29,7 @@ BEGIN
{
require Exporter;
# set the version for version checking
our $VERSION = '1.06';
our $VERSION = '1.07';
# Inherit from Exporter to export functions and variables
our @ISA = qw(Exporter);
# Functions and variables which are exported by default
Expand Down Expand Up @@ -134,7 +134,7 @@ sub create

activate($virtualenvPath);

perl("-MApp::Virtualenv::Module", "-e exit not App::Virtualenv::Module::install(force => 1, modules => ['LWP', 'CPAN', 'CPANPLUS']);") unless $empty;
perl("-MApp::Virtualenv::Module", "-e exit not App::Virtualenv::Module::install(force => 1, test => 0, modules => ['LWP', 'CPAN', 'CPANPLUS']);") unless $empty;

my $pkgPath = dirname(__FILE__);
_system("cp -v $pkgPath/Virtualenv/activate $virtualenvPath/bin/activate && chmod 644 $virtualenvPath/bin/activate");
Expand Down
152 changes: 90 additions & 62 deletions lib/App/Virtualenv/Module.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ App::Virtualenv::Module - Module management for Perl virtual environment
=head1 VERSION
version 1.06
version 1.07
=head1 SYNOPSIS
Expand Down Expand Up @@ -33,7 +33,7 @@ BEGIN
{
require Exporter;
# set the version for version checking
our $VERSION = '1.06';
our $VERSION = '1.07';
# Inherit from Exporter to export functions and variables
our @ISA = qw(Exporter);
# Functions and variables which are exported by default
Expand All @@ -49,46 +49,82 @@ $sitelib{$perl5lib[0]} = "perl5lib" if $perl5lib[0];
unless (keys %sitelib)
{
$sitelib{$Config{sitelib}} = "sitelib";
$sitelib{$Config{archlib}} = "archlib";
$sitelib{$Config{sitearch}} = "sitearch";
}
my $inst = ExtUtils::Installed->new;
my $installed;
App::Virtualenv::Module::reloadInstalled();
my $cb = CPANPLUS::Backend->new;


sub reloadInstalled
{
$installed = ExtUtils::Installed->new(inc_override => [sort keys %sitelib]);
return;
}

sub moduleFiles
{
my ($module) = @_;
my ($moduleName) = @_;
return unless grep($_ eq $moduleName, $installed->modules());
my %files;
for my $path (sort keys %sitelib)
{
for my $file ($inst->files($module, "all", $path))
for my $file ($installed->files($moduleName, "all", $path))
{
$files{$file} = $sitelib{$path};
}
}
return keys %files;
}

sub moduleDirectories
{
my ($moduleName) = @_;
return unless grep($_ eq $moduleName, $installed->modules());
my %directories;
for my $path (sort keys %sitelib)
{
for my $directory ($installed->directories($moduleName, "all", $path))
{
$directories{$directory} = $sitelib{$path};
}
}
return keys %directories;
}

sub isInstalled
{
my ($moduleName) = @_;
reloadInstalled();
return 0 unless grep($_ eq $moduleName, $installed->modules());
for my $path (sort keys %sitelib)
{
return 1 if $installed->files($moduleName, "all", $path);
}
return 0;
}

sub list
{
my %params = @_;
my @modules = $inst->modules();
for my $module (sort {lc($a) cmp lc($b)} @modules)
reloadInstalled();
my @modules = $installed->modules();
for my $moduleName (sort {lc($a) cmp lc($b)} @modules)
{
my @files = moduleFiles($module);
my @files = moduleFiles($moduleName);
next unless @files;
if ($params{1})
{
say $module;
say $moduleName;
next;
}
my $space = " ";
my $len = length($space)-length($module);
my $len = length($space)-length($moduleName);
my $spaces = substr($space, -$len);
$spaces = "" if $len <= 0;
my $version = $inst->version($module);
my $version = $installed->version($moduleName);
$version = "0" if not $version;
say "$module$spaces $version";
say "$moduleName$spaces $version";
}
return 1;
}
Expand All @@ -97,6 +133,8 @@ sub install
{
my %params = @_;
my $force = $params{force}? 1: 0;
my $test = $params{test}? 1: 0;
my $soft = $params{soft}? 1: 0;
my $result = 1;
for my $moduleName (@{$params{modules}})
{
Expand All @@ -115,16 +153,13 @@ sub install
next;
}

my $instpath = $mod->installed_dir();
$instpath = $mod->installed_file() unless defined $instpath;
my $installed = (defined $instpath and grep($instpath =~ /^\Q$_\E/, keys %sitelib));
if (not $force and
($instpath =~ /^\Q$Config{privlib}\E|\Q$Config{archlib}\E/ or
grep({ my $inc = $_; $inc =~ /^\Q$Config{privlib}\E|\Q$Config{archlib}\E/ and -e $inc."/".($moduleName =~ s/\:\:/\//r).".pm"; } @INC)))
if (not $force and grep({ my $inc = $_; $inc =~ /^\Q$Config{privlib}\E|\Q$Config{archlib}\E/ and -e $inc."/".($moduleName =~ s/\:\:/\//r).".pm"; } @INC))
{
cp_msg("Module $moduleName is in Perl library", 1);
next;
}

my $installed = isInstalled($moduleName);
if (not $force and $installed and $mod->is_uptodate())
{
cp_msg("Module $moduleName is up to date", 1);
Expand Down Expand Up @@ -158,58 +193,53 @@ sub install
}
#cp_msg("Succeed to prepare module $moduleName", 1);

cp_msg("Looking for prerequisites of module $moduleName", 1);
state @install;
push @install, $moduleName;
my $res = 1;
for my $ps (@{$mod->{_status}->{prereqs}})
unless ($soft)
{
delete $ps->{'perl'};
delete $ps->{'Config'};
delete $ps->{'Errno'};
for my $p (keys %$ps)
cp_msg("Looking for prerequisites of module $moduleName", 1);
state @install;
push @install, $moduleName;
my $res = 1;
for my $ps (@{$mod->{_status}->{prereqs}})
{
next if (grep($_ eq $p, @install));
unless (install(modules => [$p]))
delete $ps->{'perl'};
delete $ps->{'Config'};
delete $ps->{'Errno'};
for my $p (keys %$ps)
{
$res = 0;
last;
next if (grep($_ eq $p, @install));
unless (install(modules => [$p], test => $test))
{
$res = 0;
last;
}
}
last unless $res;
}
last unless $res;
}
pop @install;
unless ($res)
{
cp_error("Failed to install prerequisites of module $moduleName", 1);
$result = 0;
next;
}
cp_msg("Succeed to install prerequisites of module $moduleName", 1);

=pod
cp_msg("Creating module $moduleName", 1);
unless ($mod->create(verbose => 1))
{
cp_error("Failed to create module $moduleName", 1);
$result = 0;
next;
pop @install;
unless ($res)
{
cp_error("Failed to install prerequisites of module $moduleName", 1);
$result = 0;
next;
}
cp_msg("Succeed to install prerequisites of module $moduleName", 1);
}
#cp_msg("Succeed to create module $moduleName", 1);

cp_msg("Testing module $moduleName", 1);
unless ($mod->test(verbose => 1))
if ($test)
{
cp_error("Failed to test module $moduleName", 1);
$result = 0;
next;
cp_msg("Testing module $moduleName", 1);
unless ($mod->test(verbose => 1))
{
cp_error("Failed to test module $moduleName", 1);
$result = 0;
next;
}
#cp_msg("Succeed to test module $moduleName", 1);
}
#cp_msg("Succeed to test module $moduleName", 1);
=cut

cp_msg("Installing module $moduleName", 1);
my $willBeStatus = (not $installed)? "installed": "upgraded";
unless ($mod->install(verbose => 1, force => 1))
unless ($mod->install(verbose => 1, force => 1, skiptest => 1))
{
cp_error("Module $moduleName could not be $willBeStatus", 1);
$result = 0;
Expand All @@ -236,9 +266,7 @@ sub remove
next;
}

my $instpath = $mod->installed_dir();
$instpath = $mod->installed_file() unless defined $instpath;
my $installed = (defined $instpath and grep($instpath =~ /^\Q$_\E/, keys %sitelib));
my $installed = isInstalled($moduleName);
unless ($installed)
{
cp_msg("Module $moduleName is not installed", 1);
Expand Down
11 changes: 7 additions & 4 deletions lib/App/Virtualenv/Piv.pm
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ sub main
{
case "virtualenv"
{
return not App::Virtualenv::create($args->{params}->[0], defined($args->{-e}));
my $empty = defined($args->{-e})? 1: 0;
return not App::Virtualenv::create($args->{params}->[0], $empty);
}
case "sh"
{
Expand All @@ -77,19 +78,21 @@ sub main
case "install"
{
activate;
my $force = defined($args->{-f})? 1: 0;
my $test = defined($args->{-t})? 1: 0;
my $soft = defined($args->{"-s"})? 1: 0;
my @modules = @{$args->{params}};
@modules = map(s/(.*)/\"\Q$1\E\"/r, @modules);
my $modules = join(", ", @modules);
my $force = defined($args->{-f})? 1: 0;
return App::Virtualenv::perl("-MApp::Virtualenv::Module", "-e exit not App::Virtualenv::Module::install(force => $force, modules => [$modules]);");
return App::Virtualenv::perl("-MApp::Virtualenv::Module", "-e exit not App::Virtualenv::Module::install(force => $force, test=> $test, soft => $soft, modules => [$modules]);");
}
case "remove"
{
activate;
my $force = defined($args->{-f})? 1: 0;
my @modules = @{$args->{params}};
@modules = map(s/(.*)/\"\Q$1\E\"/r, @modules);
my $modules = join(", ", @modules);
my $force = defined($args->{-f})? 1: 0;
return App::Virtualenv::perl("-MApp::Virtualenv::Module", "-e exit not App::Virtualenv::Module::remove(force => $force, modules => [$modules]);");
}
else
Expand Down

0 comments on commit 9d7bed2

Please sign in to comment.