Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added support for non-JIT installation as well as experimental OS X s…

…upport.
  • Loading branch information...
commit 0a6e307dd02436268cd6f4660cb137d8f7cb2d18 1 parent 70af431
@boronine authored
Showing with 75 additions and 23 deletions.
  1. +75 −23 pypyenv
View
98 pypyenv
@@ -6,6 +6,8 @@ import urllib2
import tarfile
import shutil
import stat
+import getopt
+import platform
base = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
srcdir = "src"
@@ -13,22 +15,24 @@ bindir = "bin"
binpypy = os.path.join(bindir, "pypy")
pypydir = "pypy"
+def out(s):
+ print " * " + s
+
def install():
os.chdir(base)
# Clean up if anything was left over
uninstall()
# Create src directory
if not os.path.exists(srcdir):
- print "creating ENV/%s directory" % srcdir
+ out("creating ENV/%s directory" % srcdir)
os.mkdir(srcdir)
- archive = os.path.join(srcdir, "pypy-1.3-linux.tar.bz2")
+ archive = os.path.join(srcdir, download.split("/")[-1])
# Download archive
if os.path.exists(archive):
- print "using previously downloaded ENV/%s" % archive
+ out("using previously downloaded ENV/%s" % archive)
else:
- print "downloading PyPy"
- linux_jit = "http://pypy.org/download/pypy-1.3-linux.tar.bz2"
- urlfile = urllib2.urlopen(linux_jit)
+ out("downloading PyPy")
+ urlfile = urllib2.urlopen(download)
archivefile = open(archive, "w")
while True:
data = urlfile.read(4096)
@@ -39,42 +43,90 @@ def install():
archiveobj = tarfile.open(archive, mode="r:bz2")
unpacked = os.path.join(srcdir, archiveobj.next().name)
if os.path.exists(unpacked):
- print "using previously unpacked %s" % unpacked
- else:
- print "unpacking archive"
- archiveobj.extractall(srcdir)
+ out("deleting ENV/%s" % unpacked)
+ shutil.rmtree(unpacked)
+ out("unpacking archive")
+ archiveobj.extractall(srcdir)
# Copying PyPy directory into virtualenv root
- print "copying PyPy directory into root"
+ out("copying PyPy directory into root")
shutil.copytree(unpacked, pypydir)
# Install PyPy executable symlink
- print "installing ENV/%s symlink" % binpypy
+ out("installing ENV/%s symlink" % binpypy)
os.symlink(os.path.join("..", "pypy", "bin", "pypy"), binpypy)
- print "giving it execute permissions"
+ out("giving it execute permissions")
os.chmod(binpypy, stat.S_IXUSR)
# Install site-packages symlink
pythonsite = os.path.join("..", "lib", "python2.5", "site-packages")
pypysite = os.path.join("pypy", "site-packages")
- print "installing ENV/%s symlink" % pypysite
+ out("installing ENV/%s symlink" % pypysite)
os.symlink(pythonsite, pypysite)
def uninstall():
os.chdir(base)
- if os.path.exists(binpypy):
- print "deleting ENV/%s symlink" % binpypy
- os.remove(binpypy)
+ if os.path.exists(binpypy):
+ if confirm_deletion(binpypy):
+ os.remove(binpypy)
+ else:
+ sys.exit(1)
if os.path.exists(pypydir):
- print "deleting ENV/%s" % pypydir
- shutil.rmtree(pypydir)
+ if confirm_deletion(pypydir):
+ shutil.rmtree(pypydir)
+ else:
+ sys.exit(1)
+
+def confirm_deletion(tree):
+ yes = ("y","yes")
+ return raw_input("Delete ENV/%s? [y/N] " % tree) in yes
help_message = """pypyenv install - installs PyPy in this virtualenv
-pypyenv uninstall - uninstalls PyPy from this virtualenv"""
+pypyenv uninstall - uninstalls PyPy from this virtualenv
+ --nojit - Install non-JIT version."""
if __name__ == "__main__":
- if len(sys.argv) < 2:
+ try:
+ opts, args = getopt.getopt(sys.argv[1:], "", ["nojit"])
+ except getopt.GetoptError:
print help_message
- elif sys.argv[1] == "install":
+ sys.exit(2)
+
+ if len(args) != 1:
+ print help_message
+ sys.exit(2)
+
+ nojit = False
+ for o, a in opts:
+ if o == "--nojit":
+ nojit = True
+ jit = not nojit
+
+ osx = platform.system() == "Darwin"
+ win = platform.system() == "Windows"
+ linux = not osx and not win
+
+ x86_64 = platform.machine() == "x86_64"
+ x86 = not x86_64
+
+ if win:
+ print "Supports only Linux and OS X at this point"
+ sys.exit(2)
+ if x86_64 and jit:
+ print "JIT is not supported on x86_64, rerun with --nojit"
+ sys.exit(2)
+
+ if linux and x86 and jit:
+ download = "http://pypy.org/download/pypy-1.3-linux.tar.bz2"
+ if linux and x86 and nojit:
+ download = "http://pypy.org/download/pypy-1.3-linux-nojit.tar.bz2"
+ elif linux and x86_64:
+ download = "http://pypy.org/download/pypy-1.3-linux64-nojit.tar.bz2"
+ elif osx and jit:
+ download = "http://pypy.org/download/pypy-1.3-osx.tar.bz2"
+ elif osx and nojit:
+ download = "http://pypy.org/download/pypy-1.3-osx-nojit.tar.bz2"
+
+ if args[0] == "install":
install()
- elif sys.argv[1] == "uninstall":
+ elif args[0] == "uninstall":
uninstall()
else:
print help_message
Please sign in to comment.
Something went wrong with that request. Please try again.