more reorganization to make setup-helpers code more generic

This commit is contained in:
Luke Campagnola 2014-01-12 11:50:52 -05:00
parent 7a45b9a0e2
commit 9a131f763b
4 changed files with 141 additions and 114 deletions

View File

@ -59,7 +59,7 @@ class Build(distutils.command.build.build):
def run(self):
global path, version, initVersion, forcedVersion
global buildVersion
## Make sure build directory is clean
buildPath = os.path.join(path, self.build_lib)
if os.path.isdir(buildPath):
@ -88,62 +88,11 @@ class Build(distutils.command.build.build):
sys.excepthook(*sys.exc_info())
return ret
from distutils.core import Command
import shutil, subprocess
class DebCommand(Command):
description = "build .deb package"
user_options = []
def initialize_options(self):
self.cwd = None
def finalize_options(self):
self.cwd = os.getcwd()
def run(self):
assert os.getcwd() == self.cwd, 'Must be in package root: %s' % self.cwd
global version
pkgName = "python-pyqtgraph-" + version
debDir = "deb_build"
if os.path.isdir(debDir):
raise Exception('DEB build dir already exists: "%s"' % debDir)
sdist = "dist/pyqtgraph-%s.tar.gz" % version
if not os.path.isfile(sdist):
raise Exception("No source distribution; run `setup.py sdist` first.")
# copy sdist to build directory and extract
os.mkdir(debDir)
renamedSdist = 'python-pyqtgraph_%s.orig.tar.gz' % version
shutil.copy(sdist, os.path.join(debDir, renamedSdist))
if os.system("cd %s; tar -xzf %s" % (debDir, renamedSdist)) != 0:
raise Exception("Error extracting source distribution.")
buildDir = '%s/pyqtgraph-%s' % (debDir, version)
# copy debian control structure
shutil.copytree('tools/debian', buildDir+'/debian')
# Write changelog
#chlog = subprocess.check_output([sys.executable, 'tools/generateChangelog.py', 'CHANGELOG'])
#open('%s/pyqtgraph-%s/debian/changelog', 'w').write(chlog)
if os.system('python tools/generateChangelog.py CHANGELOG %s > %s/debian/changelog' % (version, buildDir)) != 0:
raise Exception("Error writing debian/changelog")
# build package
if os.system('cd %s; debuild -us -uc' % buildDir) != 0:
raise Exception("Error during debuild.")
class TestCommand(Command):
description = ""
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
global cmd
cmd = self
setup(
version=version,
cmdclass={'build': Build, 'deb': DebCommand, 'test': TestCommand},
cmdclass={'build': Build, 'deb': helpers.DebCommand, 'test': helpers.TestCommand},
packages=allPackages,
package_dir={'pyqtgraph.examples': 'examples'}, ## install examples along with the rest of the source
#package_data={'pyqtgraph': ['graphicsItems/PlotItem/*.png']},

View File

@ -2,7 +2,7 @@ Source: python-pyqtgraph
Maintainer: Luke Campagnola <luke.campagnola@gmail.com>
Section: python
Priority: optional
Standards-Version: 3.9.3
Standards-Version: 3.9.4
Build-Depends: debhelper (>= 8)
Package: python-pyqtgraph

View File

@ -1,70 +1,80 @@
import re, time, sys
if len(sys.argv) < 3:
sys.stderr.write("Must specify changelog file and latest release!\n")
sys.exit(-1)
### Convert CHANGELOG format like:
"""
pyqtgraph-0.9.1 2012-12-29
- change
- change
"""
### to debian changelog format:
"""
python-pyqtgraph (0.9.1-1) UNRELEASED; urgency=low
* Initial release.
-- Luke <luke.campagnola@gmail.com> Sat, 29 Dec 2012 01:07:23 -0500
"""
def generateDebianChangelog(package, logFile, version, maintainer):
"""
------- Convert CHANGELOG format like:
pyqtgraph-0.9.1 2012-12-29
releases = []
current_version = None
current_log = None
current_date = None
for line in open(sys.argv[1]).readlines():
match = re.match(r'pyqtgraph-(\d+\.\d+\.\d+(\.\d+)?)\s*(\d+-\d+-\d+)\s*$', line)
if match is None:
if current_log is not None:
current_log.append(line)
else:
if current_log is not None:
releases.append((current_version, current_log, current_date))
current_version, current_date = match.groups()[0], match.groups()[2]
#sys.stderr.write("Found release %s\n" % current_version)
current_log = []
- change
- change
if releases[0][0] != sys.argv[2]:
sys.stderr.write("Latest release in changelog (%s) does not match current release (%s)\n" % (releases[0][0], sys.argv[2]))
sys.exit(-1)
for release, changes, date in releases:
date = time.strptime(date, '%Y-%m-%d')
changeset = [
"python-pyqtgraph (%s-1) UNRELEASED; urgency=low\n" % release,
"\n"] + changes + [
" -- Luke <luke.campagnola@gmail.com> %s -0%d00\n" % (time.strftime('%a, %d %b %Y %H:%M:%S', date), time.timezone/3600),
"\n" ]
-------- to debian changelog format:
python-pyqtgraph (0.9.1-1) UNRELEASED; urgency=low
# remove consecutive blank lines except between releases
clean = ""
lastBlank = True
for line in changeset:
if line.strip() == '':
if lastBlank:
continue
* Initial release.
-- Luke <luke.campagnola@gmail.com> Sat, 29 Dec 2012 01:07:23 -0500
*package* is the name of the python package.
*logFile* is the CHANGELOG file to read; must have the format described above.
*version* will be used to check that the most recent log entry corresponds
to the current package version.
*maintainer* should be string like "Luke <luke.campagnola@gmail.com>".
"""
releases = []
current_version = None
current_log = None
current_date = None
for line in open(logFile).readlines():
match = re.match(package+r'-(\d+\.\d+\.\d+(\.\d+)?)\s*(\d+-\d+-\d+)\s*$', line)
if match is None:
if current_log is not None:
current_log.append(line)
else:
if current_log is not None:
releases.append((current_version, current_log, current_date))
current_version, current_date = match.groups()[0], match.groups()[2]
#sys.stderr.write("Found release %s\n" % current_version)
current_log = []
if releases[0][0] != version:
raise Exception("Latest release in changelog (%s) does not match current release (%s)\n" % (releases[0][0], version))
output = []
for release, changes, date in releases:
date = time.strptime(date, '%Y-%m-%d')
changeset = [
"python-%s (%s-1) UNRELEASED; urgency=low\n" % (package, release),
"\n"] + changes + [
" -- %s %s -0%d00\n" % (maintainer, time.strftime('%a, %d %b %Y %H:%M:%S', date), time.timezone/3600),
"\n" ]
# remove consecutive blank lines except between releases
clean = ""
lastBlank = True
for line in changeset:
if line.strip() == '':
if lastBlank:
continue
else:
clean += line
lastBlank = True
else:
clean += line
lastBlank = True
else:
clean += line
lastBlank = False
print clean
print ""
lastBlank = False
output.append(clean)
output.append("")
return "\n".join(output) + "\n"
if __name__ == '__main__':
if len(sys.argv) < 5:
sys.stderr.write('Usage: generateChangelog.py package_name log_file version "Maintainer <maint@email.com>"\n')
sys.exit(-1)
print generateDebianChangelog(*sys.argv[1:])

View File

@ -111,4 +111,72 @@ def getVersionStrings(pkg):
else:
version = initVersion
return version, forcedVersion, gitVersion, initVersion
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>"
debTemplate = "tools/debian"
debDir = "deb_build"
user_options = []
def initialize_options(self):
self.cwd = None
def finalize_options(self):
self.cwd = os.getcwd()
def run(self):
version = self.distribution.get_version()
pkgName = self.distribution.get_name()
debName = "python-" + pkgName
debDir = self.debDir
assert os.getcwd() == self.cwd, 'Must be in package root: %s' % self.cwd
if os.path.isdir(debDir):
raise Exception('DEB build dir already exists: "%s"' % debDir)
sdist = "dist/%s-%s.tar.gz" % (pkgName, version)
if not os.path.isfile(sdist):
raise Exception("No source distribution; run `setup.py sdist` first.")
# copy sdist to build directory and extract
os.mkdir(debDir)
renamedSdist = '%s_%s.orig.tar.gz' % (debName, version)
shutil.copy(sdist, os.path.join(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
shutil.copytree(self.debTemplate, buildDir+'/debian')
# Write new changelog
chlog = generateDebianChangelog(pkgName, 'CHANGELOG', version, self.maintainer)
open(buildDir+'/debian/changelog', 'w').write(chlog)
# build package
if os.system('cd %s; debuild -us -uc' % buildDir) != 0:
raise Exception("Error during debuild.")
class TestCommand(Command):
description = ""
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
global cmd
cmd = self
print self.distribution.name
print self.distribution.version