[PATCH 5/8] Include the data for Debian releases in the Python distribution build.

Ben Finney bignose at debian.org
Sat Jan 14 16:25:58 UTC 2017


---
 debian/changelog |  8 +++++++
 debian/control   |  2 ++
 setup.py.in      | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 74 insertions(+)

diff --git a/debian/changelog b/debian/changelog
index 5f242153..ff49a030 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,11 @@
+python-debian (0.1.30) UNRELEASED; urgency=medium
+
+  [ Ben Finney ]
+
+  * Include the data for Debian releases in the Python distribution build.
+
+ --
+
 python-debian (0.1.29) unstable; urgency=medium
 
   * Fix handling of gpgv output from gnupg 2 (Closes: #782904).
diff --git a/debian/control b/debian/control
index 9528b288..3fe99556 100644
--- a/debian/control
+++ b/debian/control
@@ -26,6 +26,8 @@ Build-Depends:
  python3-nose,
  python3-setuptools,
  python3-six (>> 1.4~)
+Build-Depends-Indep:
+ distro-info-data
 Standards-Version: 3.9.8
 Vcs-Browser: https://anonscm.debian.org/git/pkg-python-debian/python-debian.git
 Vcs-Git: https://anonscm.debian.org/git/pkg-python-debian/python-debian.git
diff --git a/setup.py.in b/setup.py.in
index 697e2c23..d3b612f3 100644
--- a/setup.py.in
+++ b/setup.py.in
@@ -18,8 +18,65 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
+import distutils.command.build
+import distutils.core
+import os.path
+import shutil
+
 from setuptools import setup
 
+
+default_infile_path = os.path.join("/usr/share/distro-info", "debian.csv")
+
+class WriteDebianReleasesCommand(distutils.command.build.build, object):
+    """ Distutils command to write the data file of Debian releases. """
+
+    description = "Write the data file of Debian releases."
+
+    user_options = ([
+            ("infile-path=", None,
+             "Filesystem path to the input data file."),
+            ] + distutils.command.build.build.user_options)
+
+    def initialize_options(self):
+        """ Initialise command options to defaults. """
+        super(WriteDebianReleasesCommand, self).initialize_options()
+        self.infile_path = None
+        self.outfile_path = None
+
+    def finalize_options(self):
+        """ Finalise command options before execution. """
+        super(WriteDebianReleasesCommand, self).finalize_options()
+
+        self.set_undefined_options(
+                'build',
+                ('build_lib', 'build_lib'),
+                ('force', 'force'),
+        )
+
+        if self.infile_path is None:
+            self.infile_path = default_infile_path
+
+        self.outfile_path = os.path.join(
+                self.build_lib, "debian", "releases.csv")
+
+    def run(self):
+        """ Execute this command. """
+        distutils.log.info(
+                "Writing data file from {source} to {dest}".format(
+                    source=self.infile_path, dest=self.outfile_path))
+        shutil.copy(self.infile_path, self.outfile_path)
+
+
+class BuildCommand(distutils.command.build.build, object):
+    """ Custom ‘build’ command for this distribution. """
+
+    sub_commands = (
+            distutils.command.build.build.sub_commands + [
+                ('write_releases_data', (lambda dist: True)),
+            ])
+
+
 setup(
     name='python-debian',
     version='__CHANGELOG_VERSION__',
@@ -27,7 +84,14 @@ setup(
     url='http://packages.debian.org/sid/python-debian',
     package_dir={'': 'lib'},
     packages=['debian', 'debian_bundle'],
+    cmdclass={
+        "write_releases_data": WriteDebianReleasesCommand,
+        "build": BuildCommand,
+    },
     py_modules=['deb822'],
+    package_data={
+        'debian': ['*.csv'],
+    },
     maintainer='Debian python-debian Maintainers',
     maintainer_email='pkg-python-debian-maint at lists.alioth.debian.org',
     install_requires=['six'],
-- 
2.11.0

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.alioth.debian.org/pipermail/pkg-python-debian-maint/attachments/20170115/3a6ad1c8/attachment.sig>


More information about the pkg-python-debian-maint mailing list