]> git.donarmstrong.com Git - debhelper.git/blobdiff - dh_python
r1586: * dh_python: patch from Josselin to fix generated depends. Closes: #204717
[debhelper.git] / dh_python
index d936f31845ba8cd79735fb157315066afdd3e71e..f677ee2ee9c866ee66aeb2c2209d460a4951c55a 100755 (executable)
--- a/dh_python
+++ b/dh_python
@@ -26,7 +26,7 @@ current major version, or on pythonX.Y if your scripts or modules need a
 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 build time, appropriate
+If some modules need to be byte-compiled at install time, appropriate
 postinst and prerm scripts will be generated.
 
 If you use this program, your package should build-depend on python.
@@ -67,7 +67,7 @@ my $python_version = `$python -V 2>&1`;
 if ("$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+/) {
+elsif ($python_version =~ m/^Python\s+(\d+)\.(\d+)(\.\d+)*/) {
        $python_version = "$1.$2" ;
        $python_major = $1 ;
 } else { 
@@ -98,8 +98,27 @@ foreach my $package (@{$dh{DOPACKAGES}}) {
 
        delsubstvar($package, "python:Depends");
 
-       # Check for current python dependencies
        my @dirs = ("usr/lib/site-python", "usr/lib/$package", "usr/share/$package", "usr/lib/games/$package", "usr/share/games/$package", @ARGV );
+
+       my $dep_on_python = 0;
+       my $strong_dep = 0;
+       my $look_for_pythonXY = 1;
+
+       # First, the case of python-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()) {
+                       addsubstvar($package, "python:Depends", $pack);
+               }
+               else {
+                       push @dirs, "usr/lib/python$python_version/site-packages" ;
+                       $look_for_pythonXY = 0;
+               }
+       }
+
        @dirs = grep -d, map "$tmp/$_", @dirs;
 
        my $deps = 0;
@@ -141,19 +160,9 @@ foreach my $package (@{$dh{DOPACKAGES}}) {
        }
 
        # Dependencies on current python
-       my $dep_on_python = 0;
-       my $strong_dep = 0;
        $dep_on_python = 1 if $deps;
        $strong_dep = 1 if($deps & PY_MODULE);
-       if ($package =~ /^python-/) {
-               my $pack = $package;
-               $pack =~ s/^python/python$python_version/;
-               if (grep { "$_" eq "$pack" } GetPackages()) {
-                       addsubstvar($package, "python:Depends", $pack);
-                       $dep_on_python = 1;
-                       $strong_dep = 1;
-               }
-       }
+
        if ($dep_on_python) {
                addsubstvar($package, "python:Depends", $python, ">= $python_version");
                if ($strong_dep) {
@@ -168,13 +177,15 @@ foreach my $package (@{$dh{DOPACKAGES}}) {
        # Look for specific pythonX.Y modules
        foreach my $pyver (@python_allversions) {
                my $pydir="/usr/lib/$pyver/site-packages";
-               if (grep -d,"$tmp$pydir") {
-                       find sub {
-                               return unless -f;
-                               $verdeps{$pyver} |= PY_MODULE if /\.py$/;
-                       }, "$tmp$pydir";
+               if ($look_for_pythonXY) {
+                       if (grep -d,"$tmp$pydir") {
+                               find sub {
+                                       return unless -f;
+                                       $verdeps{$pyver} |= PY_MODULE if /\.py$/;
+                               }, "$tmp$pydir";
+                       }
                }
-               
+       
                # Go for the dependencies
                addsubstvar($package, "python:Depends", $pyver) if $verdeps{$pyver};