From c8739e54257877eaa9b7a997540837ab90d93a7e Mon Sep 17 00:00:00 2001
From: Luke Campagnola <luke.campagnola@gmail.com>
Date: Sun, 12 Jan 2014 23:59:53 -0500
Subject: [PATCH] Updated build system to use pybuild - now generates
 python-pyqtgraph, python3-pyqtgraph, and python-pyqtgraph-doc packages -
 `python setup.py sdist deb` works

---
 MANIFEST.in                            |  1 +
 tools/debian/changelog                 |  5 ----
 tools/debian/control                   | 39 +++++++++++++++++++++++---
 tools/debian/files                     |  1 -
 tools/debian/postrm                    |  3 --
 tools/debian/python-pyqtgraph.install  |  1 +
 tools/debian/python3-pyqtgraph.install |  1 +
 tools/debian/rules                     | 13 ++++++++-
 tools/debian/watch                     |  3 ++
 tools/generateChangelog.py             |  2 +-
 tools/setupHelpers.py                  | 14 +++++----
 11 files changed, 63 insertions(+), 20 deletions(-)
 delete mode 100644 tools/debian/changelog
 delete mode 100644 tools/debian/files
 delete mode 100755 tools/debian/postrm
 create mode 100644 tools/debian/python-pyqtgraph.install
 create mode 100644 tools/debian/python3-pyqtgraph.install
 create mode 100644 tools/debian/watch

diff --git a/MANIFEST.in b/MANIFEST.in
index f4158fac..c6667d04 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -5,4 +5,5 @@ recursive-include doc *.rst *.py *.svg *.png *.jpg
 recursive-include doc/build/html *
 recursive-include tools *
 include doc/Makefile doc/make.bat README.md LICENSE.txt CHANGELOG
+global-exclude *.pyc
 
diff --git a/tools/debian/changelog b/tools/debian/changelog
deleted file mode 100644
index 1edf45f3..00000000
--- a/tools/debian/changelog
+++ /dev/null
@@ -1,5 +0,0 @@
-python-pyqtgraph (0.9.1-1) UNRELEASED; urgency=low
-
-  * Initial release.
-
- -- Luke <luke.campagnola@gmail.com>  Sat, 29 Dec 2012 01:07:23 -0500
diff --git a/tools/debian/control b/tools/debian/control
index 9d0519cc..a516920d 100644
--- a/tools/debian/control
+++ b/tools/debian/control
@@ -3,16 +3,47 @@ Maintainer: Luke Campagnola <luke.campagnola@gmail.com>
 Section: python
 Priority: optional
 Standards-Version: 3.9.4
-Build-Depends: debhelper (>= 8)
+Build-Depends: debhelper (>= 8), python-all (>= 2.6.6-3~), python-setuptools, python3-all, python3-setuptools, python-docutils, python-sphinx (>= 1.0.7+dfsg-1~)
+X-Python-Version: >= 2.6
+X-Python3-Version: >= 3.2
 
 Package: python-pyqtgraph
 Architecture: all
 Homepage: http://www.pyqtgraph.org
-Depends: python (>= 2.6), python-support (>= 0.90), python-qt4 | python-pyside, python-scipy, python-numpy, ${misc:Depends}
-Suggests: python-opengl, python-qt4-gl
-Description: Scientific Graphics and GUI Library for Python
+Depends: python-qt4 | python-pyside, python-scipy, python-numpy, ${python:Depends}, ${misc:Depends}
+Suggests: python-pyqtgraph-doc, python-opengl, python-qt4-gl
+Description: Scientific Graphics and GUI Library (Python 2)
  PyQtGraph is a pure-python graphics and GUI library built on PyQt4 and numpy. 
  It is intended for use in mathematics / scientific / engineering applications. 
  Despite being written entirely in python, the library is very fast due to its 
  heavy leverage of numpy for number crunching and Qt's GraphicsView framework 
  for fast display.
+ .
+ This is the Python 2 version of the package.
+
+Package: python3-pyqtgraph
+Architecture: all
+Homepage: http://www.pyqtgraph.org
+Depends: python-qt4 | python-pyside, python-scipy, python-numpy, ${python3:Depends}, ${misc:Depends}
+Suggests: python-pyqtgraph-doc, python-opengl, python-qt4-gl
+Description: Scientific Graphics and GUI Library (Python 3)
+ PyQtGraph is a pure-python graphics and GUI library built on PyQt4 and numpy. 
+ It is intended for use in mathematics / scientific / engineering applications. 
+ Despite being written entirely in python, the library is very fast due to its 
+ heavy leverage of numpy for number crunching and Qt's GraphicsView framework 
+ for fast display.
+ .
+ This is the Python 3 version of the package.
+
+Package: python-pyqtgraph-doc
+Architecture: all
+Section: doc
+Depends: ${sphinxdoc:Depends}, ${misc:Depends}
+Description: Scientific Graphics and GUI Library (common documentation)
+ PyQtGraph is a pure-python graphics and GUI library built on PyQt4 and numpy. 
+ It is intended for use in mathematics / scientific / engineering applications. 
+ Despite being written entirely in python, the library is very fast due to its 
+ heavy leverage of numpy for number crunching and Qt's GraphicsView framework 
+ for fast display.
+ .
+ This is the common documentation package.
diff --git a/tools/debian/files b/tools/debian/files
deleted file mode 100644
index 4af05533..00000000
--- a/tools/debian/files
+++ /dev/null
@@ -1 +0,0 @@
-python-pyqtgraph_0.9.1-1_all.deb python optional
diff --git a/tools/debian/postrm b/tools/debian/postrm
deleted file mode 100755
index e1eae9f2..00000000
--- a/tools/debian/postrm
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/bin/sh -e
-#DEBHELPER#
-rm -rf /usr/lib/python2.7/dist-packages/pyqtgraph
diff --git a/tools/debian/python-pyqtgraph.install b/tools/debian/python-pyqtgraph.install
new file mode 100644
index 00000000..b2cc1360
--- /dev/null
+++ b/tools/debian/python-pyqtgraph.install
@@ -0,0 +1 @@
+usr/lib/python2*
diff --git a/tools/debian/python3-pyqtgraph.install b/tools/debian/python3-pyqtgraph.install
new file mode 100644
index 00000000..4606faae
--- /dev/null
+++ b/tools/debian/python3-pyqtgraph.install
@@ -0,0 +1 @@
+usr/lib/python3*
diff --git a/tools/debian/rules b/tools/debian/rules
index 2d33f6ac..3132fbfd 100755
--- a/tools/debian/rules
+++ b/tools/debian/rules
@@ -1,4 +1,15 @@
 #!/usr/bin/make -f
+#export DH_VERBOSE=1
+export PYBUILD_NAME=pyqtgraph
 
 %:
-	dh $@
+	dh $@ --with python2,python3,sphinxdoc --buildsystem=pybuild
+
+override_dh_installdocs:
+	PYTHONPATH=`pwd` make -C doc html
+	dh_installdocs -ppython-pyqtgraph-doc doc/build/html
+	dh_installdocs -A
+
+override_dh_clean:
+	dh_clean
+	find ./ -name "*.pyc" -delete
\ No newline at end of file
diff --git a/tools/debian/watch b/tools/debian/watch
new file mode 100644
index 00000000..85ff1a55
--- /dev/null
+++ b/tools/debian/watch
@@ -0,0 +1,3 @@
+version=3
+opts=uversionmangle=s/(rc|dev|a|b|c)/~$1/ \
+https://pypi.python.org/packages/source/p/pyqtgraph/pyqtgraph-(.*)\.(?:tar\.gz|zip|tar\.bz2)
diff --git a/tools/generateChangelog.py b/tools/generateChangelog.py
index 10601b35..3dcd692d 100644
--- a/tools/generateChangelog.py
+++ b/tools/generateChangelog.py
@@ -76,5 +76,5 @@ if __name__ == '__main__':
         sys.stderr.write('Usage: generateChangelog.py package_name log_file version "Maintainer <maint@email.com>"\n')
         sys.exit(-1)
     
-    print generateDebianChangelog(*sys.argv[1:])
+    print(generateDebianChangelog(*sys.argv[1:]))
 
diff --git a/tools/setupHelpers.py b/tools/setupHelpers.py
index f1845ce4..5b17069a 100644
--- a/tools/setupHelpers.py
+++ b/tools/setupHelpers.py
@@ -114,14 +114,13 @@ def getVersionStrings(pkg):
     return version, forcedVersion, gitVersion, initVersion
 
 
-
 from distutils.core import Command
 import shutil, subprocess
 from generateChangelog import generateDebianChangelog
 
 class DebCommand(Command):
     description = "build .deb package using `debuild -us -uc`"
-    maintainer = "Luke <luke.campagnola@gmail.com>"
+    maintainer = "Luke Campagnola <luke.campagnola@gmail.com>"
     debTemplate = "tools/debian"
     debDir = "deb_build"
     
@@ -150,24 +149,30 @@ class DebCommand(Command):
         # copy sdist to build directory and extract
         os.mkdir(debDir)
         renamedSdist = '%s_%s.orig.tar.gz' % (debName, version)
+        print("copy %s => %s" % (sdist, os.path.join(debDir, renamedSdist)))
         shutil.copy(sdist, os.path.join(debDir, renamedSdist))
+        print("cd %s; tar -xzf %s" % (debDir, renamedSdist))
         if os.system("cd %s; tar -xzf %s" % (debDir, renamedSdist)) != 0:
             raise Exception("Error extracting source distribution.")
         buildDir = '%s/%s-%s' % (debDir, pkgName, version)
         
         # copy debian control structure
+        print("copytree %s => %s" % (self.debTemplate, buildDir+'/debian'))
         shutil.copytree(self.debTemplate, buildDir+'/debian')
         
         # Write new changelog
         chlog = generateDebianChangelog(pkgName, 'CHANGELOG', version, self.maintainer)
+        print("write changelog %s" % buildDir+'/debian/changelog')
         open(buildDir+'/debian/changelog', 'w').write(chlog)
         
         # build package
+        print('cd %s; debuild -us -uc' % buildDir)
         if os.system('cd %s; debuild -us -uc' % buildDir) != 0:
             raise Exception("Error during debuild.")
 
 
 class TestCommand(Command):
+    """Just for learning about distutils; not for running package tests."""
     description = ""
     user_options = []
     def initialize_options(self):
@@ -177,6 +182,5 @@ class TestCommand(Command):
     def run(self):
         global cmd
         cmd = self
-        print self.distribution.name
-        print self.distribution.version
-    
\ No newline at end of file
+        print(self.distribution.name)
+        print(self.distribution.version)
-- 
GitLab