1 # A debhelper build system class for building Python Distutils based
2 # projects. It prefers out of source tree building.
4 # Copyright: © 2008 Joey Hess
5 # © 2008-2009 Modestas Vainius
8 package Debian::Debhelper::Buildsystem::python_distutils;
12 use Debian::Debhelper::Dh_Lib qw(error);
13 use base 'Debian::Debhelper::Buildsystem';
16 "Python Distutils (setup.py)"
19 sub DEFAULT_BUILD_DIRECTORY {
21 return $this->canonpath($this->get_sourcepath("build"));
26 my $this=$class->SUPER::new(@_);
27 # Out of source tree building is prefered.
28 $this->prefer_out_of_source_building(@_);
32 sub check_auto_buildable {
34 return -e $this->get_sourcepath("setup.py");
40 if (open(my $cfg, $this->get_buildpath(".pydistutils.cfg"))) {
41 $ret = not "# Created by dh_auto\n" eq <$cfg>;
49 if (open(my $cfg, ">", $this->get_buildpath(".pydistutils.cfg"))) {
50 print $cfg "# Created by dh_auto", "\n";
51 print $cfg "[build]\nbuild-base=", $this->get_build_rel2sourcedir(), "\n";
58 sub pre_building_step {
62 return unless grep /$step/, qw(build install clean);
64 # --build-base can only be passed to the build command. However,
65 # it is always read from the config file (really weird design).
66 # Therefore create such a cfg config file.
67 if ($this->get_buildpath() ne $this->DEFAULT_BUILD_DIRECTORY()) {
68 not $this->not_our_cfg() or
69 error("cannot set custom build directory: .pydistutils.cfg is in use");
70 $this->mkdir_builddir();
71 $this->create_cfg() or
72 error("cannot set custom build directory: unwritable .pydistutils.cfg");
73 # Distutils reads $HOME/.pydistutils.cfg
74 $ENV{HOME} = Cwd::abs_path($this->get_buildpath());
77 $this->SUPER::pre_building_step($step);
83 $this->doit_in_sourcedir("python", "setup.py", $act, @_);
88 $this->setup_py("build", @_);
94 $this->setup_py("install",
98 "--install-layout=deb",
104 $this->setup_py("clean", "-a", @_);
106 # Config file will remain if it was created by us
107 if (!$this->not_our_cfg()) {
108 unlink($this->get_buildpath(".pydistutils.cfg"));
109 $this->rmdir_builddir(1); # only if empty
111 # The setup.py might import files, leading to python creating pyc
113 $this->doit_in_sourcedir('find', '.', '-name', '*.pyc', '-exec', 'rm', '{}', ';');