1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
#!/usr/bin/python
# Copyright (C) 2012 Denis Bilenko (http://denisbilenko.com)
"""
Create a source distribution of gevent.
Does the following:
- Clones the repo into a temporary location.
- Run set_version.py that will update gevent/__init__.py.
- Run 'python setup.py sdist'.
"""
import sys
import os
import glob
import optparse
from os.path import exists, join, abspath, basename
from pipes import quote
TMPDIR = '/tmp/gevent-make-dist'
def system(cmd, noisy=True):
if noisy:
print cmd
res = os.system(cmd)
if res:
sys.exit('%r failed with %s' % (cmd, res))
def makedist(*args, **kwargs):
cwd = os.getcwd()
try:
return _makedist(*args, **kwargs)
finally:
os.chdir(cwd)
def _makedist(version=None, dest=None):
assert exists('gevent/__init__.py'), 'Where am I?'
basedir = abspath(os.getcwd())
version = version or 'dev'
set_version_command = 'util/set_version.py --version %s ./gevent/__init__.py' % version
os.chdir('/tmp')
system('rm -fr ' + TMPDIR)
os.mkdir(TMPDIR)
os.chdir(TMPDIR)
system('git clone %s gevent' % basedir)
directory = os.listdir('.')
assert len(directory) == 1, directory
os.chdir(directory[0])
system('git branch')
system(set_version_command)
system('git diff', noisy=False)
system('python setup.py -q sdist')
dist_filename = glob.glob('dist/gevent-*.tar.gz')
assert len(dist_filename) == 1, dist_filename
dist_path = abspath(dist_filename[0])
dist_filename = basename(dist_path)
if dest:
if os.path.isdir(dest):
dest = join(dest, dist_filename)
else:
if not exists(join(basedir, 'dist')):
os.mkdir(join(basedir, 'dist'))
dest = join(basedir, 'dist', dist_filename)
copy(dist_path, dest)
return dist_path
def main():
parser = optparse.OptionParser()
parser.add_option('--dest')
parser.add_option('--version')
options, args = parser.parse_args()
assert not args, 'Expected no arguments'
return makedist(options.version, dest=options.dest)
def copy(source, dest):
system('cp -a %s %s' % (quote(source), quote(dest)))
if __name__ == '__main__':
main()
|