From ec9810f72561909aaca474ff92a278f79cc7eccd 2009-08-02 05:35:37 From: Fernando Perez Date: 2009-08-02 05:35:37 Subject: [PATCH] Cleaned up release tools directory. Converted almost all to python scripts and made toollib to collect common functions and avoid repetition. Properly commented and documented what each script does. The run_ipy_in_profiler one seems broken, I'm not sure what to do with it. We need to either fix it or remove it later, but it's not critical for 0.10. --- diff --git a/tools/compile.py b/tools/compile.py index 4a08400..be34c42 100755 --- a/tools/compile.py +++ b/tools/compile.py @@ -1,20 +1,19 @@ #!/usr/bin/env python -"""Call the compile script to check that all code we ship compiles correctly. -""" +"""Script to check that all code in a directory compiles correctly. -import os -import sys +Usage: + compile.py -vstr = '.'.join(map(str,sys.version_info[:2])) +This script verifies that all Python files in the directory where run, and all +of its subdirectories, compile correctly. -stat = os.system('python %s/lib/python%s/compileall.py .' % (sys.prefix,vstr)) +Before a release, call this script from the top-level directory. +""" + +import sys -print -if stat: - print '*** THERE WAS AN ERROR! ***' - print 'See messages above for the actual file that produced it.' -else: - print 'OK' +from toollib import compile_tree -sys.exit(stat) +if __name__ == '__main__': + compile_tree() diff --git a/tools/make_tarball.py b/tools/make_tarball.py index d143bd5..bceaf10 100755 --- a/tools/make_tarball.py +++ b/tools/make_tarball.py @@ -2,35 +2,22 @@ """Simple script to create a tarball with proper bzr version info. """ -import os,sys,shutil +import os +import sys +import shutil -basever = '0.9.0' +from toollib import * -def oscmd(c): - print ">",c - s = os.system(c) - if s: - print "Error",s - sys.exit(s) +c('python update_revnum.py') -def verinfo(): - - out = os.popen('bzr version-info') - pairs = (l.split(':',1) for l in out) - d = dict(((k,v.strip()) for (k,v) in pairs)) - return d - -basename = 'ipython' - -#tarname = '%s.r%s.tgz' % (basename, ver) -oscmd('python update_revnum.py') +execfile('../IPython/Release.py') # defines version_base -ver = verinfo() +ver = version_info() if ver['branch-nick'] == 'ipython': - tarname = 'ipython-%s.bzr.r%s.tgz' % (basever, ver['revno']) + tarname = 'ipython-%s.bzr.r%s.tgz' % (version_base, ver['revno']) else: - tarname = 'ipython-%s.bzr.r%s.%s.tgz' % (basever, ver['revno'], + tarname = 'ipython-%s.bzr.r%s.%s.tgz' % (version_base, ver['revno'], ver['branch-nick']) -oscmd('bzr export ' + tarname) +c('bzr export ' + tarname) diff --git a/tools/mkrel.py b/tools/mkrel.py index 01c8a8a..2ef9c19 100755 --- a/tools/mkrel.py +++ b/tools/mkrel.py @@ -1,48 +1,42 @@ #!/usr/bin/env python -"""IPython release script - -Create ipykit and exe installer - -requires py2exe +"""IPython release build script. """ +from toollib import * -import os -import distutils.dir_util -import sys - -execfile('../IPython/Release.py') - -def c(cmd): - print ">",cmd - os.system(cmd) +# Get main ipython dir, this will raise if it doesn't pass some checks +ipdir = get_ipdir() +cd(ipdir) -ipykit_name = "ipykit-%s" % version +# Load release info +execfile(pjoin('IPython','Release.py')) -os.chdir('..') -if os.path.isdir('dist'): - distutils.dir_util.remove_tree('dist') -if os.path.isdir(ipykit_name): - distutils.dir_util.remove_tree(ipykit_name) +# Check that everything compiles +compile_tree() -if sys.platform == 'win32': - c("python exesetup.py py2exe") - - os.rename('dist',ipykit_name) - - c("zip -r %s.zip %s" % (ipykit_name, ipykit_name)) +# Cleanup +for d in ['build','dist',pjoin('docs','build'),pjoin('docs','dist')]: + if os.path.isdir(d): + remove_tree(d) # Build source and binary distros c('./setup.py sdist --formats=gztar') -c("python2.4 ./setup.py bdist_rpm --binary-only --release=py24 --python=/usr/bin/python2.4") -c("python2.5 ./setup.py bdist_rpm --binary-only --release=py25 --python=/usr/bin/python2.5") +# Build version-specific RPMs, where we must use the --python option to ensure +# that the resulting RPM is really built with the requested python version (so +# things go to lib/python2.X/...) +c("python2.5 ./setup.py bdist_rpm --binary-only --release=py25 " + "--python=/usr/bin/python2.5") +c("python2.6 ./setup.py bdist_rpm --binary-only --release=py26 " + "--python=/usr/bin/python2.6") # Build eggs -c('python2.4 ./eggsetup.py bdist_egg') c('python2.5 ./eggsetup.py bdist_egg') +c('python2.6 ./eggsetup.py bdist_egg') +# Call the windows build separately, so that the extra Windows scripts don't +# get pulled into Unix builds (setup.py has code which checks for +# bdist_wininst) c("python setup.py bdist_wininst --install-script=ipython_win_post_install.py") -os.chdir('tools') -c('python make_tarball.py') - +# Change name so retarded Vista runs the installer correctly +c("rename 's/win32/win32-setup/' dist/*.exe") diff --git a/tools/release b/tools/release index 56572ef..557f952 100755 --- a/tools/release +++ b/tools/release @@ -1,35 +1,43 @@ -#!/bin/bash -# IPython release script +#!/usr/bin/env python +"""IPython release script. -PYVER=`python -V 2>&1 | awk '{print $2}' | awk -F '.' '{print $1$2}' ` -version=`ipython -Version` -ipdir=~/ipython/ipython -ipbackupdir=~/ipython/backup +This should only be run at real release time. +""" -echo -echo "Releasing IPython version $version" -echo "==================================" +from toollib import * + +# Get main ipython dir, this will raise if it doesn't pass some checks +ipdir = get_ipdir() +cd(ipdir) + +# Load release info +execfile(pjoin('IPython','Release.py')) + +# Where I keep static backups of each release +ipbackupdir = os.path.expanduser('~/ipython/backup') + +print +print "Releasing IPython version $version" +print "==================================" # Perform local backup -cd $ipdir/tools -./make_tarball.py -mv ipython-*.tgz $ipbackupdir +c('./make_tarball.py') +c('mv ipython-*.tgz %s' % ipbackupdir) # Build release files -./testrel $ipdir +c('./mkrel.py %s' % ipdir) # Register with the Python Package Index (PyPI) -echo "Registering with PyPI..." -cd $ipdir -./setup.py register +print "Registering with PyPI..." +c('./setup.py register') # Upload all files -cd $ipdir/dist -echo "Uploading distribution files..." -scp * ipython@ipython.scipy.org:www/dist/ +cd('dist') +print "Uploading distribution files..." +c('scp * ipython@ipython.scipy.org:www/dist/') -echo "Uploading backup files..." -cd $ipbackupdir -scp `ls -1tr *tgz | tail -1` ipython@ipython.scipy.org:www/backup/ +print "Uploading backup files..." +cd(ipbackupdir) +c('scp `ls -1tr *tgz | tail -1` ipython@ipython.scipy.org:www/backup/') -echo "Done!" +print "Done!" diff --git a/tools/run_ipy_in_profiler.py b/tools/run_ipy_in_profiler.py index bcd0ef7..a58e0c5 100755 --- a/tools/run_ipy_in_profiler.py +++ b/tools/run_ipy_in_profiler.py @@ -1,3 +1,9 @@ +"""XXX - What exactly is the use of this script? + +I (fperez) tried it quickly and it doesn't work in its current form. Either it +needs to be fixed and documented or removed. +""" + import cProfile as profile import sys #import profile diff --git a/tools/testrel b/tools/testrel deleted file mode 100755 index e986655..0000000 --- a/tools/testrel +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash - -# Build the release files. Kept as a separate script so we can easily do local -# dry runs without uploading anything externally. - -ipdir=${1-..} - -cd $ipdir - -# Clean up build/dist directories -rm -rf build/* -rm -rf dist/* -rm -rf docs/build/* -rm -rf docs/dist/* - -# Build source and binary distros -./setup.py sdist --formats=gztar - -# Build version-specific RPMs, where we must use the --python option to ensure -# that the resulting RPM is really built with the requested python version (so -# things go to lib/python2.X/...) -python2.5 ./setup.py bdist_rpm --binary-only --release=py25 --python=/usr/bin/python2.5 -python2.6 ./setup.py bdist_rpm --binary-only --release=py26 --python=/usr/bin/python2.6 - -# Build eggs -python2.5 ./setup_bdist_egg.py -python2.6 ./setup_bdist_egg.py - -# Call the windows build separately, so that the extra Windows scripts don't -# get pulled into Unix builds (setup.py has code which checks for -# bdist_wininst) -./setup.py bdist_wininst --install-script=ipython_win_post_install.py - -# Change name so retarded Vista runs the installer correctly -rename 's/win32/win32-setup/' dist/*.exe diff --git a/tools/testupload b/tools/testupload index c2a19c0..a3a04db 100755 --- a/tools/testupload +++ b/tools/testupload @@ -1,5 +1,5 @@ #!/bin/sh - +# Simple upload script to push up into the testing directory a local build ipdir=$PWD/.. cd $ipdir/dist diff --git a/tools/toollib.py b/tools/toollib.py new file mode 100644 index 0000000..50355ce --- /dev/null +++ b/tools/toollib.py @@ -0,0 +1,55 @@ +"""Various utilities common to IPython release and maintenance tools. +""" +# Library imports +import os +import sys + +from distutils.dir_util import remove_tree + +# Useful shorthands +pjoin = os.path.join +cd = os.chdir + +# Utility functions +def c(cmd): + """Run system command, raise SystemExit if it returns an error.""" + print "$",cmd + #stat = os.system(cmd) + stat = 0 # Uncomment this and comment previous to run in debug mode + if stat: + raise SystemExit("Command %s failed with code: %s" % (cmd, stat)) + + +def get_ipdir(): + """Get IPython directory from command line, or assume it's the one above.""" + + # Initialize arguments and check location + try: + ipdir = sys.argv[1] + except IndexError: + ipdir = '..' + + ipdir = os.path.abspath(ipdir) + + cd(ipdir) + if not os.path.isdir('IPython') and os.path.isfile('setup.py'): + raise SystemExit('Invalid ipython directory: %s' % ipdir) + return ipdir + + +def compile_tree(): + """Compile all Python files below current directory.""" + vstr = '.'.join(map(str,sys.version_info[:2])) + stat = os.system('python %s/lib/python%s/compileall.py .' % + (sys.prefix,vstr)) + if stat: + msg = '*** ERROR: Some Python files in tree do NOT compile! ***\n' + msg += 'See messages above for the actual file that produced it.\n' + raise SystemExit(msg) + + +def version_info(): + """Return bzr version info as a dict.""" + out = os.popen('bzr version-info') + pairs = (l.split(':',1) for l in out) + return dict(((k,v.strip()) for (k,v) in pairs)) diff --git a/tools/update_revnum.py b/tools/update_revnum.py index f97b933..0228d96 100755 --- a/tools/update_revnum.py +++ b/tools/update_revnum.py @@ -1,23 +1,32 @@ #!/usr/bin/env python -""" Change the revision number in Release.py """ +"""Change the revision number in Release.py + +This edits in-place Release.py to update the revision number from bzr info. + +Usage: + +./update_revnum.py""" import os -import re,pprint +import pprint +import re -def verinfo(): - - out = os.popen('bzr version-info') - pairs = (l.split(':',1) for l in out) - d = dict(((k,v.strip()) for (k,v) in pairs)) - return d +from toollib import * -ver = verinfo() +if __name__ == '__main__': + ver = version_info() -pprint.pprint(ver) + pprint.pprint(ver) -rfile = open('../IPython/Release.py','rb').read() -newcont = re.sub(r'revision\s*=.*', "revision = '%s'" % ver['revno'], rfile) + rfile = open('../IPython/Release.py','rb').read() + newcont = re.sub(r'revision\s*=.*', + "revision = '%s'" % ver['revno'], + rfile) -newcont = re.sub(r'^branch\s*=[^=].*', "branch = '%s'" % ver['branch-nick'], newcont ) + newcont = re.sub(r'^branch\s*=[^=].*', + "branch = '%s'" % ver['branch-nick'], + newcont) -open('../IPython/Release.py','wb').write(newcont) + f = open('../IPython/Release.py','wb') + f.write(newcont) + f.close()