sub install()

in lib/Debian/Debhelper/Buildsystem/dh_virtualenv.pm [119:169]


sub install {
    my $this = shift;
    my $destdir = shift;
    my @pip = $this->get_pip();
    my $python = $this->get_python();
    my $sourcepackage = $this->sourcepackage();
    my $venv = $this->get_venv_builddir();
    my $prefix = $this->get_install_root();

    $this->doit_in_sourcedir(
        @pip, 'install', '.');

    # Before we copy files, let's make the symlinks in the 'usr/local'
    # relative to the build path.
    my @files_in_local = <"$venv/local/*">;
    foreach (@files_in_local) {
        if ( -l $_ ) {
            my $target = readlink;
            my $relpath = File::Spec->abs2rel($target, "$venv/local");
            my $basename = Debian::Debhelper::Dh_Lib->basename($_);
            unlink;
            symlink($relpath, $_);
       }
    }

    $this->doit_in_builddir('mkdir', '-p', $destdir);
    $this->doit_in_builddir('cp', '-r', '-T', '.', $destdir);

    my $new_python = undef;
    my @binaries = undef;

    if (defined $ENV{DH_VIRTUALENV_INSTALL_SUFFIX}) {
        $new_python = "$prefix/" . $ENV{DH_VIRTUALENV_INSTALL_SUFFIX} . "/bin/python";
        my $curdir = "$destdir$prefix/" . $ENV{DH_VIRTUALENV_INSTALL_SUFFIX} . "/bin/*";
        @binaries = glob($curdir);
    } else {
        $new_python = "$prefix/$sourcepackage/bin/python";
        @binaries = <"$destdir$prefix/$sourcepackage/bin/*">;
    }

    # Fix shebangs so that we use the Python in the final location
    # instead of the Python in the build directory
    {
        local $^I = q{};
        local @ARGV = grep { -T } @binaries;
        while ( <> ) {
            s|^#!.*bin/(env )?python|#!$new_python|;
            print;
        }
    }
}