Mercurial > hg > MakeItSo
annotate makeitso/python_package/INSTALL.py @ 206:d9d7bfdb54db
http://stackoverflow.com/questions/4375327/python-argparse-preformatted-help-text
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Fri, 21 Nov 2014 14:36:17 -0800 |
parents | 702216c49594 |
children |
rev | line source |
---|---|
133 | 1 #!/usr/bin/env python |
2 | |
3 """ | |
4 installation script for {{project}} | |
5 {{description}} | |
6 """ | |
96
cc17537254d2
add an install script template
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
7 |
133 | 8 import os |
9 import sys | |
10 import urllib2 | |
11 import subprocess | |
12 try: | |
13 from subprocess import check_call as call | |
14 except: | |
15 from subprocess import call | |
96
cc17537254d2
add an install script template
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
16 |
cc17537254d2
add an install script template
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
17 REPO='{{repo}}' |
cc17537254d2
add an install script template
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
18 DEST='{{project}}' # name of the virtualenv |
133 | 19 VIRTUALENV='https://raw.github.com/pypa/virtualenv/develop/virtualenv.py' |
96
cc17537254d2
add an install script template
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
20 |
133 | 21 def which(binary, path=os.environ['PATH']): |
22 dirs = path.split(os.pathsep) | |
23 for dir in dirs: | |
24 if os.path.isfile(os.path.join(dir, fileName)): | |
25 return os.path.join(dir, fileName) | |
26 if os.path.isfile(os.path.join(dir, fileName + ".exe")): | |
27 return os.path.join(dir, fileName + ".exe") | |
28 | |
29 def main(args=sys.argv[1:]): | |
96
cc17537254d2
add an install script template
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
30 |
133 | 31 # create a virtualenv |
32 virtualenv = which('virtualenv') or which('virtualenv.py') | |
33 if virtualenv: | |
34 call([virtualenv, DEST]) | |
35 else: | |
36 process = subproces.Popen([sys.executable, '-', DEST], stdin=subprocess.PIPE) | |
37 process.communicate(stdin=urllib2.urlopen(VIRTUALENV).read()) | |
38 | |
39 # create a src directory | |
40 src = os.path.join(DEST, 'src') | |
41 os.mkdir(src) | |
42 | |
43 # clone the repository | |
44 call(['hg', 'clone', REPO], cwd=src) | |
45 | |
143 | 46 # find the virtualenv python |
47 python = None | |
48 for path in (('bin', 'python'), ('Scripts', 'python.exe')): | |
49 _python = os.path.join(DEST, *path) | |
50 if os.path.exists(_python) | |
51 python = _python | |
52 break | |
53 else: | |
54 raise Exception("Python binary not found in %s" % DEST) | |
133 | 55 |
143 | 56 # find the clone |
57 filename = REPO.rstrip('/') | |
58 filename = filename.split('/')[-1] | |
59 clone = os.path.join(src, filename) | |
60 assert os.path.exists(clone), "Clone directory not found in %s" % src | |
61 | |
62 # ensure setup.py exists | |
63 assert os.path.exists(os.path.join(clone, 'setup.py')), 'setup.py not found in %s' % clone | |
64 | |
65 # install the package in develop mode | |
66 call([python 'setup.py', 'develop'], cwd=clone) |