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(@_);
28 # Out of source tree building is prefered.
29 $this->enforce_out_of_source_building($args{builddir});
33 sub check_auto_buildable {
35 return -e $this->get_sourcepath("setup.py");
41 if (open(my $cfg, $this->get_buildpath(".pydistutils.cfg"))) {
42 $ret = not "# Created by dh_auto\n" eq <$cfg>;
50 if (open(my $cfg, ">", $this->get_buildpath(".pydistutils.cfg"))) {
51 print $cfg "# Created by dh_auto", "\n";
52 print $cfg "[build]\nbuild-base=", $this->get_build_rel2sourcedir(), "\n";
59 sub pre_building_step {
63 return unless grep /$step/, qw(build install clean);
65 # --build-base can only be passed to the build command. However,
66 # it is always read from the config file (really weird design).
67 # Therefore create such a cfg config file.
68 if ($this->get_buildpath() ne $this->DEFAULT_BUILD_DIRECTORY()) {
69 not $this->not_our_cfg() or
70 error("cannot set custom build directory: .pydistutils.cfg is in use");
71 $this->mkdir_builddir();
72 $this->create_cfg() or
73 error("cannot set custom build directory: unwritable .pydistutils.cfg");
74 # Distutils reads $HOME/.pydistutils.cfg
75 $ENV{HOME} = Cwd::abs_path($this->get_buildpath());
82 $this->doit_in_sourcedir("python", "setup.py", $act, @_);
87 $this->setup_py("build", @_);
93 $this->setup_py("install", "--root=$destdir", "--no-compile", "-O0", @_);
98 $this->setup_py("clean", "-a", @_);
100 # Config file will remain if it was created by us
101 if (!$this->not_our_cfg()) {
102 unlink($this->get_buildpath(".pydistutils.cfg"));
103 $this->rmdir_builddir(1); # only if empty
105 # The setup.py might import files, leading to python creating pyc
107 $this->doit_in_sourcedir('find', '.', '-name', '*.pyc', '-exec', 'rm', '{}', ';');