annotate INSTALL.py @ 86:fa23c078b928

wip
author Jeff Hammel <k0scist@gmail.com>
date Sun, 01 Mar 2015 17:01:38 -0800
parents 48d0f28311a3
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
1 #!/usr/bin/env python
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
2
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
3 """
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
4 installation script for kplot
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
5 personal experiments in plotting
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
6 """
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
7
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
8 import os
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
9 import sys
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
10 import urllib2
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
11 import subprocess
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
12 try:
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
13 from subprocess import check_call as call
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
14 except:
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
15 from subprocess import call
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
16
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
17 REPO='http://k0s.org/hg/kplot'
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
18 DEST='kplot' # name of the virtualenv
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
19 VIRTUALENV='https://raw.github.com/pypa/virtualenv/develop/virtualenv.py'
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
20
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
21 def which(binary, path=os.environ['PATH']):
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
22 dirs = path.split(os.pathsep)
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
23 for dir in dirs:
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
24 if os.path.isfile(os.path.join(dir, fileName)):
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
25 return os.path.join(dir, fileName)
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
26 if os.path.isfile(os.path.join(dir, fileName + ".exe")):
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
27 return os.path.join(dir, fileName + ".exe")
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
28
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
29 def main(args=sys.argv[1:]):
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
30
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
31 # create a virtualenv
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
32 virtualenv = which('virtualenv') or which('virtualenv.py')
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
33 if virtualenv:
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
34 call([virtualenv, DEST])
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
35 else:
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
36 process = subproces.Popen([sys.executable, '-', DEST], stdin=subprocess.PIPE)
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
37 process.communicate(stdin=urllib2.urlopen(VIRTUALENV).read())
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
38
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
39 # create a src directory
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
40 src = os.path.join(DEST, 'src')
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
41 os.mkdir(src)
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
42
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
43 # clone the repository
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
44 call(['hg', 'clone', REPO], cwd=src)
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
45
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
46 # find the virtualenv python
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
47 python = None
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
48 for path in (('bin', 'python'), ('Scripts', 'python.exe')):
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
49 _python = os.path.join(DEST, *path)
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
50 if os.path.exists(_python)
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
51 python = _python
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
52 break
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
53 else:
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
54 raise Exception("Python binary not found in %s" % DEST)
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
55
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
56 # find the clone
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
57 filename = REPO.rstrip('/')
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
58 filename = filename.split('/')[-1]
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
59 clone = os.path.join(src, filename)
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
60 assert os.path.exists(clone), "Clone directory not found in %s" % src
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
61
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
62 # ensure setup.py exists
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
63 assert os.path.exists(os.path.join(clone, 'setup.py')), 'setup.py not found in %s' % clone
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
64
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
65 # install the package in develop mode
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
66 call([python 'setup.py', 'develop'], cwd=clone)
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
67