Skip to content

Commit 6a0d6ac

Browse files
author
Jyrki Pulliainen
committed
Experimental buildsystem support
1 parent 9555c96 commit 6a0d6ac

File tree

2 files changed

+129
-2
lines changed

2 files changed

+129
-2
lines changed

.gitignore

-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ doc/_build
1919
doc/dh_virtualenv.1
2020

2121
# virtualenv
22-
bin/
23-
lib/
2422
local/
2523
include/
2624
man/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
package Debian::Debhelper::Buildsystem::dh_virtualenv;
2+
3+
use strict;
4+
use base 'Debian::Debhelper::Buildsystem';
5+
use Debian::Debhelper::Dh_Lib;
6+
use File::Spec;
7+
use Cwd;
8+
9+
sub DESCRIPTION {
10+
'Python Virtualenv';
11+
}
12+
13+
sub DEFAULT_BUILD_DIRECTORY {
14+
my $this=shift;
15+
return $this->canonpath($this->get_sourcepath("build"));
16+
}
17+
18+
sub check_auto_buildable {
19+
my $this=shift;
20+
return -e $this->get_sourcepath("setup.py") ? 1 : 0;
21+
}
22+
23+
sub new {
24+
my $class = shift;
25+
my $this = $class->SUPER::new(@_);
26+
$this->prefer_out_of_source_building();
27+
return $this;
28+
}
29+
30+
sub get_venv_builddir {
31+
my $this = shift;
32+
my $builddir = $this->get_builddir();
33+
my $sourcepackage = $this->sourcepackage();
34+
return "$builddir/usr/share/python/$sourcepackage";
35+
}
36+
37+
sub get_exec {
38+
my $this = shift;
39+
my $executable = shift;
40+
my $builddir = $this->get_venv_builddir();
41+
return Cwd::abs_path("$builddir/bin/$executable");
42+
}
43+
44+
sub get_python {
45+
my $this = shift;
46+
return $this->get_exec("python");
47+
}
48+
49+
sub get_pip {
50+
my $this = shift;
51+
return $this->get_exec("pip");
52+
}
53+
54+
sub configure {
55+
my $this = shift;
56+
doit('mkdir', '-p', $this->get_venv_builddir());
57+
}
58+
59+
sub build {
60+
my $this = shift;
61+
my $sourcedir = $this->get_sourcedir();
62+
my $builddir = $this->get_venv_builddir();
63+
64+
$this->doit_in_builddir(
65+
'virtualenv', '--no-site-packages', Cwd::abs_path($builddir));
66+
67+
my $python = $this->get_python();
68+
my $pip = $this->get_pip();
69+
70+
$this->doit_in_sourcedir(
71+
$python, $pip, 'install', '-r', 'requirements.txt');
72+
73+
$this->doit_in_sourcedir(
74+
$python, $pip, 'install', '.');
75+
76+
}
77+
78+
sub test {
79+
my $this = shift;
80+
my $python = $this->get_python();
81+
$this->doit_in_sourcedir(
82+
$python, 'setup.py', 'test');
83+
}
84+
85+
sub install {
86+
my $this = shift;
87+
my $destdir = shift;
88+
my $pip = $this->get_pip();
89+
my $python = $this->get_python();
90+
my $sourcepackage = $this->sourcepackage();
91+
my $venv = $this->get_venv_builddir();
92+
93+
# Before we copy files, let's make the symlinks in the 'usr/local'
94+
# relative to the build path.
95+
my @files_in_local = <"$venv/local/*">;
96+
foreach (@files_in_local) {
97+
if ( -l $_ ) {
98+
my $target = readlink;
99+
my $relpath = File::Spec->abs2rel($target, "$venv/local");
100+
my $basename = Debian::Debhelper::Dh_Lib->basename($_);
101+
unlink;
102+
symlink($relpath, $_);
103+
}
104+
}
105+
106+
$this->doit_in_builddir('mkdir', '-p', $destdir);
107+
$this->doit_in_builddir('cp', '-r', '-T', '.', $destdir);
108+
109+
my $new_python = "/usr/share/python/$sourcepackage/bin/python";
110+
111+
# Fix shebangs so that we use the Python in the final localtion
112+
# instead of the Python in the build directory
113+
my @binaries = <"$destdir/usr/share/python/$sourcepackage/bin/*">;
114+
{
115+
local $^I = q{};
116+
local @ARGV = grep { -T } @binaries;
117+
while ( <> ) {
118+
s|^#!.*bin/(env )?python|#!$new_python|;
119+
print;
120+
}
121+
}
122+
}
123+
124+
sub clean {
125+
my $this = shift;
126+
$this->rmdir_builddir();
127+
}
128+
129+
1

0 commit comments

Comments
 (0)