-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathvirtualenv.pl
executable file
·64 lines (50 loc) · 1.18 KB
/
virtualenv.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env perl
use strict;
use warnings;
use Config;
use File::Path qw(make_path);
use File::Basename qw(dirname);
use File::Spec::Functions qw(file_name_is_absolute);
use Cwd qw(abs_path);
my $perl = $Config{perlpath};
my $venv = shift || 'venv';
if (!file_name_is_absolute($venv)) {
$venv = abs_path . "/$venv";
}
if (! -d "$venv/bin") {
make_path "$venv/bin" or die "Unable to create directory '$venv/bin'.\n"
}
print "perl: $perl\n";
print "venv: $venv\n";
sub spit {
open my $fd, '>', shift;
print $fd shift;
close $fd;
}
spit "$venv/bin/perl", <<EOS;
#!/bin/sh
exec $perl -Mlocal::lib="$venv" "\$@"
EOS
chmod 0755, "$venv/bin/perl";
my $cpanm = dirname($perl) . "/cpanm";
spit "$venv/bin/cpanm", <<EOS;
#!/bin/sh
exec $cpanm --local-lib="$venv" "\$@"
EOS
chmod 0755, "$venv/bin/cpanm";
spit "$venv/bin/activate", <<EOS;
eval \$($perl -Mlocal::lib="$venv")
export _PV_OLD_PS1=\$PS1
export PS1="(`basename $venv`)\$PS1"
deactivate() {
. $venv/bin/deactivate
}
EOS
spit "$venv/bin/deactivate", <<EOS;
eval \$($perl -Mlocal::lib="--deactivate-all,$venv")
if [ -n "\$_PV_OLD_PS1" ]; then
export PS1=\$_PV_OLD_PS1
unset _PV_OLD_PS1
unset deactivate
fi
EOS