Skip to content

Commit 1d63690

Browse files
committed
Merge branch 'release-tools' into trunk
* release-tools: EHN - build eggs for multiple versions of Python EHN - better gitignore BUG - use correct name ENH - make script more portable ENH - Adapted build/release scripts from IPython (thanks to Fernando Perez)
2 parents 0f4e56a + 6fbcf2f commit 1d63690

File tree

6 files changed

+170
-0
lines changed

6 files changed

+170
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
################
5151
build # setup.py working directory
5252
_build # sphinx build directory
53+
MANIFEST
5354
./dist # setup.py dist directory
5455
./*.egg-info # Egg metadata
5556
./.shelf # The shelf plugin uses this dir

tools/build_release

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env python
2+
"""nibabel release build script.
3+
"""
4+
from toollib import *
5+
6+
# Get main nibabel dir, this will raise if it doesn't pass some checks
7+
nibdir = get_nibdir()
8+
cd(nibdir)
9+
10+
# Load release info
11+
execfile(pjoin('nibabel','info.py'))
12+
13+
# Check that everything compiles
14+
compile_tree()
15+
16+
# Cleanup
17+
for d in ['build','dist',pjoin('docs','build'),pjoin('docs','dist')]:
18+
if os.path.isdir(d):
19+
remove_tree(d)
20+
21+
# Build source and binary distros
22+
c('./setup.py sdist --formats=gztar,zip')
23+
24+
# Build eggs
25+
for version in ['2.5', '2.6', '2.7']:
26+
cmd='python'+version+' ./setup_egg.py bdist_egg'
27+
stat = os.system(cmd)

tools/compile.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env python
2+
"""Script to check that all code in a directory compiles correctly.
3+
4+
Usage:
5+
6+
compile.py
7+
8+
This script verifies that all Python files in the directory where run, and all
9+
of its subdirectories, compile correctly.
10+
11+
Before a release, call this script from the top-level directory.
12+
"""
13+
14+
import sys
15+
16+
from toollib import compile_tree
17+
18+
if __name__ == '__main__':
19+
compile_tree()

tools/make_tarball.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env python
2+
"""Simple script to create a tarball with proper git info.
3+
"""
4+
5+
import commands
6+
import os
7+
import sys
8+
import shutil
9+
10+
from toollib import *
11+
12+
tag = commands.getoutput('git describe')
13+
base_name = 'nibabel-%s' % tag
14+
tar_name = '%s.tgz' % base_name
15+
16+
# git archive is weird: Even if I give it a specific path, it still won't
17+
# archive the whole tree. It seems the only way to get the whole tree is to cd
18+
# to the top of the tree. There are long threads (since 2007) on the git list
19+
# about this and it still doesn't work in a sensible way...
20+
21+
start_dir = os.getcwd()
22+
cd('..')
23+
git_tpl = 'git archive --format=tar --prefix={0}/ HEAD | gzip > {1}'
24+
c(git_tpl.format(base_name, tar_name))
25+
c('mv {0} tools/'.format(tar_name))

tools/release

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env python
2+
"""nibabel release script.
3+
4+
This should only be run at real release time.
5+
"""
6+
7+
from toollib import *
8+
9+
# Get main nibabel dir, this will raise if it doesn't pass some checks
10+
nibdir = get_nibdir()
11+
tooldir = pjoin(nibdir,'tools')
12+
distdir = pjoin(nibdir,'dist')
13+
#### Where I keep static backups of each release
14+
###nibbackupdir = os.path.expanduser('~/nibabel/backup')
15+
16+
# Start in main nibabel dir
17+
cd(nibdir)
18+
19+
# Load release info
20+
execfile(pjoin('nibabel','info.py'))
21+
22+
print
23+
print "Releasing nibabel"
24+
print "================="
25+
print
26+
print 'Source nibabel directory:', nibdir
27+
print
28+
29+
# Perform local backup, go to tools dir to run it.
30+
cd(tooldir)
31+
c('./make_tarball.py')
32+
c('mv nibabel-*.tgz %s' % nibbackupdir)
33+
34+
# Build release files
35+
c('./build_release %s' % nibdir)
36+
37+
# Register with the Python Package Index (PyPI)
38+
print "Registering with PyPI..."
39+
cd(nibdir)
40+
c('./setup.py register')
41+
42+
#### Upload all files
43+
###c('./setup.py sdist --formats=gztar,zip upload')
44+
###cd(distdir)
45+
###print "Uploading distribution files..."
46+
###c('scp * [email protected]:www/dist/')
47+
###
48+
###print "Uploading backup files..."
49+
###cd(nibbackupdir)
50+
###c('scp `ls -1tr *tgz | tail -1` [email protected]:www/backup/')
51+
52+
print "Done!"

tools/toollib.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
"""Various utilities common to nibabel release and maintenance tools.
2+
"""
3+
# Library imports
4+
import os
5+
import sys
6+
7+
from distutils.dir_util import remove_tree
8+
9+
# Useful shorthands
10+
pjoin = os.path.join
11+
cd = os.chdir
12+
13+
# Utility functions
14+
def c(cmd):
15+
"""Run system command, raise SystemExit if it returns an error."""
16+
print "$",cmd
17+
stat = os.system(cmd)
18+
#stat = 0 # Uncomment this and comment previous to run in debug mode
19+
if stat:
20+
raise SystemExit("Command %s failed with code: %s" % (cmd, stat))
21+
22+
23+
def get_nibdir():
24+
"""Get nibabel directory from command line, or assume it's the one above."""
25+
26+
# Initialize arguments and check location
27+
try:
28+
nibdir = sys.argv[1]
29+
except IndexError:
30+
nibdir = '..'
31+
32+
nibdir = os.path.abspath(nibdir)
33+
34+
cd(nibdir)
35+
if not os.path.isdir('nibabel') and os.path.isfile('setup.py'):
36+
raise SystemExit('Invalid nibabel directory: %s' % nibdir)
37+
return nibdir
38+
39+
# import compileall and then get dir os.path.split
40+
def compile_tree():
41+
"""Compile all Python files below current directory."""
42+
stat = os.system('python -m compileall .')
43+
if stat:
44+
msg = '*** ERROR: Some Python files in tree do NOT compile! ***\n'
45+
msg += 'See messages above for the actual file that produced it.\n'
46+
raise SystemExit(msg)

0 commit comments

Comments
 (0)