* Jakub Wilk <jw...@debian.org>, 2011-05-26, 18:54:
The only missing bit, which would be nice to have, is a script to automatically generate correct dependencies on these virtual packages for packages that ship pre-generatare parser/lexer tables.

And here goes the missing bit.

I'm wasn't sure if we should be using new substitution variable (python-ply:Depends) or rather reuse python:Depends. For example dh_numy just reuses the latter, but OTOH new substitution variable feels safer to me.

--
Jakub Wilk
diff --git a/debian/control b/debian/control
--- a/debian/control
+++ b/debian/control
@@ -7,7 +7,8 @@
 Build-Depends: debhelper (>= 5.0.37.2),
                cdbs (>= 0.4.43),
                python-dev (>= 2.3.5-7),
-               python-support (>= 0.90)
+               python-support (>= 0.90),
+               perl
 Build-Depends-Indep: python-setuptools (>= 0.6a9)
 Standards-Version: 3.8.3
 Homepage: http://www.dabeaz.com/ply/
diff --git a/debian/dh_python-ply b/debian/dh_python-ply
new file mode 100755
--- /dev/null
+++ b/debian/dh_python-ply
@@ -0,0 +1,87 @@
+#!/usr/bin/perl
+
+=head1 NAME
+
+dh_python-ply - generate versioned dependencies on python-ply
+
+=cut
+
+use strict;
+use warnings;
+
+use Debian::Debhelper::Dh_Lib;
+
+=head1 SYNOPSIS
+
+B<dh_python-ply> [B<--dependency-field> I<dependencyfield>] [S<I<debhelper options>>] I<file>...
+
+=head1 DESCRIPTION
+
+B<dh_python-ply> is a debhelper program that is responsible for generating the
+B<python-ply:Depends> substitutions and adding them to substvars files.
+
+The program will look only at Python modules that are explicitly provided as
+its arguments, and will use this information to generate a strict versioned
+dependency on B<python-ply>.
+
+=head1 OPTIONS
+
+=over 4
+
+=item B<--dependency-field> I<dependencyfield>
+
+Use B<python-ply:>I<dependencyfield> substitution variable instead of
+B<python-ply:Depends>.
+
+=back
+
+=cut
+
+my $dependency_field = "Depends";
+
+init(options => { "dependency-field:s" => \$dependency_field });
+
+if (not @ARGV)
+{
+    error("at least one argument is required")
+}
+
+foreach my $filename (@ARGV)
+{
+    open FILE, $filename or error("cannot read $filename: $!");
+    read FILE, $_, 1024;
+    my $is_lextab = /^_lextokens\b/m;
+    my $is_parsetab = /^_lr_method\b/m;
+    $is_lextab or $is_parsetab or error("$filename doesn't look like a PLY table");
+    (my $tabversion) = /^_tabversion\s*=\s*'([0-9.]+)'/m or error("$filename was generated by a very old PLY");
+    my $dependency = sprintf "python-ply-%s-%s", $is_lextab ? "lex" : "yacc", $tabversion;
+    # Prefer real package names of "old" versions of PLY for easier upgrades from squeeze:
+    if ($dependency eq "python-ply-yacc-3.2")
+    {
+        # PLY 3.2, 3.3 and 3.4 embeds the same version number (3.2) in parser tables.
+        $dependency = "python-ply (>= 3.2), python-ply (<< 3.5) | $dependency";
+    }
+    elsif ($dependency eq "python-ply-lex-3.3")
+    {
+        # PLY 3.2, 3.3 and 3.4 embeds their own version number in lexer tables.
+        $dependency = "python-ply (>= 3.3), python-ply (<< 3.4) | $dependency";
+    }
+    foreach my $package (@{$dh{DOPACKAGES}})
+    {
+        addsubstvar($package, "python-ply:$dependency_field", $dependency);
+    }
+}
+
+=head1 SEE ALSO
+
+L<debhelper(7)>
+
+This program is not a part of debhelper, but it is meant to be used together with it.
+
+=head1 AUTHOR
+
+Jakub Wilk <jw...@debian.org>
+
+=cut
+
+# vim:ts=4 sw=4 et
diff --git a/debian/rules b/debian/rules
--- a/debian/rules
+++ b/debian/rules
@@ -12,5 +12,10 @@
 DEB_DESTDIR := debian/python-ply
 DEB_PYTHON_INSTALL_ARGS_ALL += --single-version-externally-managed
 
+binary-install/python-ply::
+	pod2man debian/dh_python-ply > dh_python-ply.1
+	dh_installman -p python-pl dh_python-ply.1
+	rm dh_python-ply.1
+
 binary-post-install/python-ply::
 	echo "python-ply:Provides=$$(python debian/virtual-packages.py)" >> debian/python-ply.substvars

Reply via email to