summaryrefslogtreecommitdiff
path: root/virtual-python.py
diff options
context:
space:
mode:
authorpje <pje@6015fed2-1504-0410-9fe1-9d1591cc4771>2005-10-17 02:26:39 +0000
committerpje <pje@6015fed2-1504-0410-9fe1-9d1591cc4771>2005-10-17 02:26:39 +0000
commitc70724954e8f3d74adbf14dfae5d294cfd3a712c (patch)
treee931e6f30fe51eb6ee968a008e9ac4c439249ea8 /virtual-python.py
parent64091da29d13967a2bce9f44b30e5beda0bc1ab8 (diff)
downloadpython-setuptools-c70724954e8f3d74adbf14dfae5d294cfd3a712c.tar.gz
Significantly enhanced support and docs for "non-root" installation,
including both "virtual" and PYTHONPATH-based installs. The activation precedence of distributions has also changed so that PYTHONPATH-based non-root installs can include eggs that override system-defined packages (whether managed or unmanaged). This version should eliminate most common installation complaints from non-root Python users. Note: this version includes a hacked 'site.py' to support processing .pth files in directories that come *before* site-packages on sys.path. However, because of its placement, it should only come into play when a user puts the setuptools .egg file *directly* on PYTHONPATH, so it doesn't affect "virtual" or "root" installations. It's strictly to provide support for luddites who refuse to give up their existing non-root PYTHONPATH setup unless you pry it from their cold, dead hands. :) git-svn-id: http://svn.python.org/projects/sandbox/trunk/setuptools@41262 6015fed2-1504-0410-9fe1-9d1591cc4771
Diffstat (limited to 'virtual-python.py')
-rwxr-xr-xvirtual-python.py123
1 files changed, 123 insertions, 0 deletions
diff --git a/virtual-python.py b/virtual-python.py
new file mode 100755
index 0000000..8624f37
--- /dev/null
+++ b/virtual-python.py
@@ -0,0 +1,123 @@
+"""Create a "virtual" Python installation
+
+Based on a script created by Ian Bicking."""
+
+import sys, os, optparse, shutil
+join = os.path.join
+py_version = 'python%s.%s' % (sys.version_info[0], sys.version_info[1])
+
+def mkdir(path):
+ if not os.path.exists(path):
+ print 'Creating %s' % path
+ os.makedirs(path)
+ else:
+ if verbose:
+ print 'Directory %s already exists'
+
+def symlink(src, dest):
+ if not os.path.exists(dest):
+ if verbose:
+ print 'Creating symlink %s' % dest
+ os.symlink(src, dest)
+ else:
+ print 'Symlink %s already exists' % dest
+
+
+def rmtree(dir):
+ if os.path.exists(dir):
+ print 'Deleting tree %s' % dir
+ shutil.rmtree(dir)
+ else:
+ if verbose:
+ print 'Do not need to delete %s; already gone' % dir
+
+def make_exe(fn):
+ if os.name == 'posix':
+ oldmode = os.stat(fn).st_mode & 07777
+ newmode = (oldmode | 0555) & 07777
+ os.chmod(fn, newmode)
+ if verbose:
+ print 'Changed mode of %s to %s' % (fn, oct(newmode))
+
+def main():
+ if os.name != 'posix':
+ print "This script only works on Unix-like platforms, sorry."
+ return
+
+ parser = optparse.OptionParser()
+
+ parser.add_option('-v', '--verbose', action='count', dest='verbose',
+ default=0, help="Increase verbosity")
+
+ parser.add_option('--prefix', dest="prefix", default='~',
+ help="The base directory to install to (default ~)")
+
+ parser.add_option('--clear', dest='clear', action='store_true',
+ help="Clear out the non-root install and start from scratch")
+
+ parser.add_option('--no-site-packages', dest='no_site_packages',
+ action='store_true',
+ help="Don't copy the contents of the global site-packages dir to the "
+ "non-root site-packages")
+
+ options, args = parser.parse_args()
+ global verbose
+
+ home_dir = os.path.expanduser(options.prefix)
+ lib_dir = join(home_dir, 'lib', py_version)
+ inc_dir = join(home_dir, 'include', py_version)
+ bin_dir = join(home_dir, 'bin')
+
+ if sys.executable.startswith(bin_dir):
+ print 'Please use the *system* python to run this script'
+ return
+
+ verbose = options.verbose
+ assert not args, "No arguments allowed"
+
+ if options.clear:
+ rmtree(lib_dir)
+ rmtree(inc_dir)
+ print 'Not deleting', bin_dir
+
+ prefix = sys.prefix
+ mkdir(lib_dir)
+ stdlib_dir = join(prefix, 'lib', py_version)
+ for fn in os.listdir(stdlib_dir):
+ if fn != 'site-packages':
+ symlink(join(stdlib_dir, fn), join(lib_dir, fn))
+
+ mkdir(join(lib_dir, 'site-packages'))
+ if not options.no_site_packages:
+ for fn in os.listdir(join(stdlib_dir, 'site-packages')):
+ symlink(join(stdlib_dir, 'site-packages', fn),
+ join(lib_dir, 'site-packages', fn))
+
+ mkdir(inc_dir)
+ stdinc_dir = join(prefix, 'include', py_version)
+ for fn in os.listdir(stdinc_dir):
+ symlink(join(stdinc_dir, fn), join(inc_dir, fn))
+
+ if sys.exec_prefix != sys.prefix:
+ exec_dir = join(sys.exec_prefix, 'lib', py_version)
+ for fn in os.listdir(exec_dir):
+ symlink(join(exec_dir, fn), join(lib_dir, fn))
+
+ mkdir(bin_dir)
+ print 'Copying %s to %s' % (sys.executable, bin_dir)
+ py_executable = join(bin_dir, 'python')
+ if sys.executable != py_executable:
+ shutil.copyfile(sys.executable, py_executable)
+ make_exe(py_executable)
+
+ pydistutils = os.path.expanduser('~/.pydistutils.cfg')
+ if os.path.exists(pydistutils):
+ print 'Please make sure you remove any previous custom paths from'
+ print "your", pydistutils, "file."
+
+ print "You're now ready to download ez_setup.py, and run"
+ print py_executable, "ez_setup.py"
+
+if __name__ == '__main__':
+ main()
+