X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=dh_python;h=722d81354f5fa0af6d0ea95ccf29d8bce3cc700d;hb=fb8f18f4a98669c3b85e1bd7920fbabfc00b886e;hp=d936f31845ba8cd79735fb157315066afdd3e71e;hpb=ace87ed101089bbbaddce7274d76f02652e5b0a6;p=debhelper.git diff --git a/dh_python b/dh_python index d936f31..722d813 100755 --- 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 @@ -12,24 +12,29 @@ use Debian::Debhelper::Dh_Lib; =head1 SYNOPSIS -B [S>] [B<-n>] [S>] +B [S>] [B<-n>] [B<-V> I] [S ...>] =head1 DESCRIPTION -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. +Note: This program is deprecated. You should use B instead. +This program will do nothing if F or a +B F file field exists. -The program will look at python scripts and modules in your package, and -will use this information to generate a dependency on python, with the -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}". +B is a debhelper program that is responsible for generating the +B<${python:Depends}> substitutions and adding them to substvars files. It +will also add a F and a F script if required. -If some modules need to be byte-compiled at build time, appropriate -postinst and prerm scripts will be generated. +The program will look at Python scripts and modules in your package, and +will use this information to generate a dependency on B, with the +current major version, or on BIB<.>I if your scripts or modules need a +specific B version. The dependency will be substituted into your +package's F file wherever you place the token B<${python:Depends}>. -If you use this program, your package should build-depend on python. +If some modules need to be byte-compiled at install time, appropriate +F and F 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 B. =head1 OPTIONS @@ -37,15 +42,24 @@ If you use this program, your package should build-depend on python. =item I -If your package installs python modules in non-standard directories, you -can make dh_python check those directories by passing their names on the -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. +If your package installs Python modules in non-standard directories, you +can make F check those directories by passing their names on the +command line. By default, it will check F, +F, F, F, +F and F. + +Note: only F, F and the +extra names on the command line are searched for binary (F<.so>) modules. + +=item B<-V> I + +If the F<.py> files your package ships are meant to be used by a specific +BIB<.>I version, you can use this option to specify the desired version, +such as B<2.3>. Do not use if you ship modules in F. =item B<-n>, B<--noscripts> -Do not modify postinst/postrm scripts. +Do not modify F/F scripts. =back @@ -59,15 +73,27 @@ 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_python2 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_python2 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+/) { +elsif ($python_version =~ m/^Python\s+(\d+)\.(\d+)(\.\d+)*/) { $python_version = "$1.$2" ; $python_major = $1 ; } else { @@ -78,11 +104,21 @@ 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/; } +# Check for -V +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 foreach (@ARGV) { s#/$##; @@ -92,15 +128,38 @@ foreach (@ARGV) { # dependency types 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); - 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 @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 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()) { + addsubstvar($package, "python:Depends", $pack); + } + } + 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 = (); @@ -131,29 +190,44 @@ 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) { - $deps |= PY_MODULE; + if ($dh{V_FLAG_SET}) { + $verdeps{$usepython} |= PY_MODULE_NONSTANDARD; + } else { + $deps |= PY_MODULE; + } $dirlist="$dirlist /$curdir"; } } } + 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 - 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; - } - } + $strong_dep = 1 if($deps & (PY_MODULE|SO_MODULE)); + if ($dep_on_python) { addsubstvar($package, "python:Depends", $python, ">= $python_version"); if ($strong_dep) { @@ -168,18 +242,24 @@ 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; + if (/\.py$/) { + $verdeps{$pyver} |= PY_MODULE; + doit(("rm","-f",$_."c",$_."o")); + } + $verdeps{$pyver} |= SO_MODULE if /\.so$/; + }, "$tmp$pydir"; + } } - + # Go for the dependencies addsubstvar($package, "python:Depends", $pyver) if $verdeps{$pyver}; # And now, the postinst and prerm stuff - if ($pyver eq "python$python_version") { + if ($pyver eq "$usepython") { if ($verdeps{$pyver} & PY_MODULE) { $pydir = $pydir.$dirlist; } else { @@ -187,7 +267,7 @@ foreach my $package (@{$dh{DOPACKAGES}}) { } $verdeps{$pyver} |= PY_MODULE if($deps & PY_MODULE); } - if ($verdeps{$pyver} & PY_MODULE && ! $dh{NOSCRIPTS}) { + if ($verdeps{$pyver} & (PY_MODULE|PY_MODULE_NONSTANDARD) && ! $dh{NOSCRIPTS}) { autoscript($package,"postinst","postinst-python","s%#PYVER#%$pyver%;s%#DIRLIST#%$pydir%"); $need_prerm = 1; } @@ -210,4 +290,3 @@ Josselin Mouette most ideas stolen from Brendan O'Dea =cut -