]> git.donarmstrong.com Git - debhelper.git/blobdiff - dh_python
Fix build system auto-selection breakage.
[debhelper.git] / dh_python
index 8b248ff6590015d3471369b76c421c1f5492471a..8f8c378850a6308c927106c200221a7b5183da74 100755 (executable)
--- a/dh_python
+++ b/dh_python
@@ -2,7 +2,7 @@
 
 =head1 NAME
 
-dh_python - calculates python dependencies and adds postinst and prerm python scripts
+dh_python - calculates python dependencies and adds postinst and prerm python scripts (deprecated)
 
 =cut
 
@@ -16,6 +16,10 @@ B<dh_python> [S<I<debhelper options>>] [B<-n>] [B<-V> I<version>] [S<I<module di
 
 =head1 DESCRIPTION
 
+Note: This program is deprecated. You should use dh_pysupport or
+dh_pycentral instead. This program will do nothing if debian/pycompat
+or a Python-Version control file field exists.
+
 dh_python is a debhelper program that is responsible for generating the
 ${python:Depends} substitutions and adding them to substvars files. It
 will also add a postinst and a prerm script if required.
@@ -27,7 +31,8 @@ specific python version. The dependency will be substituted into your
 package's control file wherever you place the token "${python:Depends}".
 
 If some modules need to be byte-compiled at install time, appropriate
-postinst and prerm scripts will be generated.
+postinst and prerm scripts will be generated. If already byte-compiled
+modules are found, they are removed.
 
 If you use this program, your package should build-depend on python.
 
@@ -43,12 +48,14 @@ command line. By default, it will check /usr/lib/site-python,
 /usr/lib/$PACKAGE, /usr/share/$PACKAGE, /usr/lib/games/$PACKAGE,
 /usr/share/games/$PACKAGE and /usr/lib/python?.?/site-packages.
 
+Note: only /usr/lib/site-python, /usr/lib/python?.?/site-packages and the
+extra names on the command line are searched for binary (.so) modules.
+
 =item B<-V> I<version>
 
 If the .py files your package ships are meant to be used by a specific
-pythonX.Y version, you can set this option with the desired X.Y python
-version.
-Do not use if you ship modules in /usr/lib/site-python.
+pythonX.Y version, you can use this option to specify the desired version,
+such as 2.3. Do not use if you ship modules in /usr/lib/site-python.
 
 =item B<-n>, B<--noscripts>
 
@@ -66,12 +73,24 @@ Python policy, version 0.3.7
 
 init();
 
+if (-e "debian/pycompat") {
+       warning("Doing nothing since dh_pycompat exists; dh_pysupport or dh_pycentral should do the work. You can remove dh_python from your rules file.");
+       exit 0;
+}
+elsif (`grep Python-Version: debian/control`) {
+       warning("Doing nothing since Python-Version is set; dh_pysupport or dh_pycentral should do the work. You can remove dh_python from your rules file.");
+       exit 0;
+}
+else {
+       warning("This program is deprecated, you should use dh_pysupport or dh_pycentral instead.");
+}
+
 my $python = 'python';
 
 # The current python major version
 my $python_major;
 my $python_version = `$python -V 2>&1`;
-if ("$python_version" eq "") {
+if (! defined $python_version || $python_version eq "") {
        error("Python is not installed, aborting. (Probably forgot to Build-Depend on python.)");
 }
 elsif ($python_version =~ m/^Python\s+(\d+)\.(\d+)(\.\d+)*/) {
@@ -85,7 +104,7 @@ elsif ($python_version =~ m/^Python\s+(\d+)\.(\d+)(\.\d+)*/) {
 my $python_nextversion = $python_version + 0.1;
 my $python_nextmajor = $python_major + 1;
 
-my @python_allversions = ('1.5','2.1','2.2','2.3');
+my @python_allversions = ('1.5','2.1','2.2','2.3','2.4');
 foreach (@python_allversions) {
        s/^/python/;
 }
@@ -95,6 +114,9 @@ my $usepython = "python$python_version";
 if($dh{V_FLAG_SET}) {
        $usepython = $dh{V_FLAG};
        $usepython =~ s/^/python/;
+       if (! grep { $_ eq $usepython } @python_allversions) {
+               error("Unknown python version $dh{V_FLAG}");
+       }
 }
 
 # Cleaning the paths given on the command line
@@ -107,6 +129,8 @@ foreach (@ARGV) {
 use constant PROGRAM   => 1;
 use constant PY_MODULE => 2;
 use constant PY_MODULE_NONSTANDARD => 4;
+use constant SO_MODULE => 8;
+use constant SO_MODULE_NONSTANDARD => 16;
 
 foreach my $package (@{$dh{DOPACKAGES}}) {
        my $tmp = tmpdir($package);
@@ -114,27 +138,30 @@ foreach my $package (@{$dh{DOPACKAGES}}) {
        delsubstvar($package, "python:Depends");
 
        my @dirs = ("usr/lib/site-python", "usr/lib/$package", "usr/share/$package", "usr/lib/games/$package", "usr/share/games/$package", @ARGV );
+       my @dirs_so = ("usr/lib/site-python", @ARGV );
 
        my $dep_on_python = 0;
        my $strong_dep = 0;
        my $look_for_pythonXY = 1;
 
-       # First, the case of python-foo
+       # First, the case of python-foo and pythonX.Y-foo
        if ($package =~ /^python-/) {
                $dep_on_python = 1;
                $strong_dep = 1;
                my $pack = $package;
                $pack =~ s/^python/python$python_version/;
-               if (grep { "$_" eq "$pack" } GetPackages()) {
+               if (grep { "$_" eq "$pack" } getpackages()) {
                        addsubstvar($package, "python:Depends", $pack);
                }
-               else {
-                       push @dirs, "usr/lib/python$python_version/site-packages" ;
-                       $look_for_pythonXY = 0;
-               }
+       }
+       if ($package !~ /^python[0-9].[0-9]-/) {
+               push @dirs, "usr/lib/$usepython/site-packages";
+               push @dirs_so, "usr/lib/$usepython/site-packages";
+               $look_for_pythonXY = 0;
        }
 
        @dirs = grep -d, map "$tmp/$_", @dirs;
+       @dirs_so = grep -d, map "$tmp/$_", @dirs_so;
 
        my $deps = 0;
        my %verdeps = ();
@@ -165,7 +192,10 @@ foreach my $package (@{$dh{DOPACKAGES}}) {
                        $curdir =~ s%^$tmp/%%;
                        find sub {
                                return unless -f;
-                               $has_module = 1 if /\.py$/;
+                               if (/\.py$/) {
+                                       $has_module = 1;
+                                       doit(("rm","-f",$_."c",$_."o"));
+                               }
                        }, "$tmp/$curdir" ;
                        if ($has_module) {
                                if ($dh{V_FLAG_SET}) {
@@ -177,10 +207,28 @@ foreach my $package (@{$dh{DOPACKAGES}}) {
                        }
                }
        }
+       if (@dirs_so) {
+               foreach my $curdir (@dirs_so) {
+                       my $has_module = 0;
+                       $curdir =~ s%^$tmp/%%;
+                       find sub {
+                               return unless -f;
+                               $has_module = 1 if /\.so$/;
+                       }, "$tmp/$curdir" ;
+                       if ($has_module) {
+                               if ($dh{V_FLAG_SET}) {
+                                       $verdeps{$usepython} |= SO_MODULE_NONSTANDARD;
+                               }
+                               else {
+                                       $deps |= SO_MODULE;
+                               }
+                       }
+               }
+       }
 
        # Dependencies on current python
        $dep_on_python = 1 if $deps;
-       $strong_dep = 1 if($deps & PY_MODULE);
+       $strong_dep = 1 if($deps & (PY_MODULE|SO_MODULE));
 
        if ($dep_on_python) {
                addsubstvar($package, "python:Depends", $python, ">= $python_version");
@@ -200,7 +248,11 @@ foreach my $package (@{$dh{DOPACKAGES}}) {
                        if (grep -d,"$tmp$pydir") {
                                find sub {
                                        return unless -f;
-                                       $verdeps{$pyver} |= PY_MODULE if /\.py$/;
+                                       if (/\.py$/) {
+                                               $verdeps{$pyver} |= PY_MODULE;
+                                               doit(("rm","-f",$_."c",$_."o"));
+                                       }
+                                       $verdeps{$pyver} |= SO_MODULE if /\.so$/;
                                }, "$tmp$pydir";
                        }
                }
@@ -240,4 +292,3 @@ Josselin Mouette <joss@debian.org>
 most ideas stolen from Brendan O'Dea <bod@debian.org>
 
 =cut
-