aboutsummaryrefslogtreecommitdiffstats
path: root/setuptools/command
diff options
context:
space:
mode:
authorPJ Eby <distutils-sig@python.org>2006-02-10 21:09:12 +0000
committerPJ Eby <distutils-sig@python.org>2006-02-10 21:09:12 +0000
commita0662830b342b51d58d9ae76881007daa6266aa7 (patch)
tree121e9521740c41850a632b0319f48d38612cfc8d /setuptools/command
parent884ec05cabc1545ae07f0b074c1e79b525ccf3cb (diff)
downloadexternal_python_setuptools-a0662830b342b51d58d9ae76881007daa6266aa7.tar.gz
external_python_setuptools-a0662830b342b51d58d9ae76881007daa6266aa7.tar.bz2
external_python_setuptools-a0662830b342b51d58d9ae76881007daa6266aa7.zip
Implemented DWIM for PYTHONPATH. That is, ez_setup and easy_install
should now "just work" if you're using a PYTHONPATH target, and if it can't "just work", you get helpful instructions and doc links. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4042308
Diffstat (limited to 'setuptools/command')
-rwxr-xr-xsetuptools/command/develop.py4
-rwxr-xr-xsetuptools/command/easy_install.py111
2 files changed, 99 insertions, 16 deletions
diff --git a/setuptools/command/develop.py b/setuptools/command/develop.py
index fafe60b5..774b6b5f 100755
--- a/setuptools/command/develop.py
+++ b/setuptools/command/develop.py
@@ -67,6 +67,8 @@ class develop(easy_install):
self.reinitialize_command('build_ext', inplace=1)
self.run_command('build_ext')
+ self.install_site_py() # ensure that target dir is site-safe
+
# create an .egg-link in the installation dir, pointing to our egg
log.info("Creating %s (link to %s)", self.egg_link, self.egg_base)
if not self.dry_run:
@@ -78,8 +80,6 @@ class develop(easy_install):
# and handling requirements
self.process_distribution(None, self.dist)
-
-
def uninstall_link(self):
if os.path.exists(self.egg_link):
log.info("Removing %s (link to %s)", self.egg_link, self.egg_base)
diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py
index 082eda7f..10f42b81 100755
--- a/setuptools/command/easy_install.py
+++ b/setuptools/command/easy_install.py
@@ -99,7 +99,7 @@ class easy_install(Command):
self.ignore_conflicts_at_my_risk = None
self.site_dirs = None
self.installed_projects = {}
-
+ self.sitepy_installed = False
# Always read easy_install options, even if we are subclassed, or have
# an independent instance created. This ensures that defaults will
# always come from the standard configuration file(s)' "easy_install"
@@ -155,21 +155,20 @@ class easy_install(Command):
)
else:
self.all_site_dirs.append(normalize_path(d))
- instdir = normalize_path(self.install_dir or self.all_site_dirs[-1])
+ instdir = normalize_path(self.install_dir)
if instdir in self.all_site_dirs:
if self.pth_file is None:
self.pth_file = PthDistributions(
os.path.join(instdir,'easy-install.pth')
)
- elif self.multi_version is None:
- self.multi_version = True
-
elif not self.multi_version:
- # explicit false set from Python code; raise an error
- raise DistutilsArgError(
- "Can't do single-version installs outside 'site-package' dirs"
- )
+ # Can't install non-multi to non-site dir
+ raise DistutilsError(self.no_default_version_msg())
+
+ if instdir in map(normalize_path, self.site_dirs or []):
+ # don't install site.py if install target is already a site dir
+ self.sitepy_installed = True
self.install_dir = instdir
self.index_url = self.index_url or "http://www.python.org/pypi"
@@ -194,6 +193,7 @@ class easy_install(Command):
self.find_links = self.find_links.split()
else:
self.find_links = []
+
self.package_index.add_find_links(self.find_links)
self.set_undefined_options('install_lib', ('optimize','optimize'))
if not isinstance(self.optimize,int):
@@ -288,6 +288,7 @@ class easy_install(Command):
def easy_install(self, spec, deps=False):
tmpdir = tempfile.mkdtemp(prefix="easy_install-")
download = None
+ self.install_site_py()
try:
if not isinstance(spec,Requirement):
@@ -325,7 +326,6 @@ class easy_install(Command):
if os.path.exists(tmpdir):
rmtree(tmpdir)
-
def install_item(self, spec, download, tmpdir, deps, install_needed=False):
# Installation is also needed if file in tmpdir or is not an egg
@@ -687,7 +687,7 @@ class easy_install(Command):
if f: f.close()
if filename not in blockers:
blockers.append(filename)
- elif ext in exts:
+ elif ext in exts and base!='site': # XXX ugh
blockers.append(os.path.join(path,filename))
if blockers:
@@ -900,9 +900,92 @@ See the setuptools documentation for the "develop" command for more info.
+ def no_default_version_msg(self):
+ return """
+-----------------------------------------------------------------------
+CONFIGURATION PROBLEM:
+
+You are attempting to install a package to a directory that is not
+on PYTHONPATH and is not registered as supporting Python ".pth" files
+by default. Here are some of your options for correcting this:
+
+* You can choose a different installation directory, i.e., one that is
+ on PYTHONPATH or supports .pth files
+
+* You can add the installation directory to the PYTHONPATH environment
+ variable. (It must then also be on PYTHONPATH whenever you run
+ Python and want to use the package(s) you are installing.)
+
+* You can set up the installation directory to support ".pth" files,
+ and configure EasyInstall to recognize this, by using one of the
+ approaches described here:
+
+ http://peak.telecommunity.com/EasyInstall.html#custom-installation-locations
+
+Please make the appropriate changes for your system and try again.
+Thank you for your patience.
+-----------------------------------------------------------------------
+"""
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ def install_site_py(self):
+ """Make sure there's a site.py in the target dir, if needed"""
+
+ if self.sitepy_installed:
+ return # already did it, or don't need to
+
+ sitepy = os.path.join(self.install_dir, "site.py")
+ source = resource_string(Requirement.parse("setuptools"), "site.py")
+
+ if os.path.exists(sitepy):
+ log.debug("Checking existing site.py in %s", self.install_dir)
+ current = open(sitepy,'rb').read()
+ if current != source:
+ raise DistutilsError(
+ "%s is not a setuptools-generated site.py; please"
+ " remove it." % sitepy
+ )
+ else:
+ log.info("Creating %s", sitepy)
+ if not self.dry_run:
+ f = open(sitepy,'wb')
+ f.write(source)
+ f.close()
+ self.byte_compile([sitepy])
+
+ self.sitepy_installed = True
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
def get_site_dirs():
- # return a list of 'site' dirs, based on 'site' module's code to do this
- sitedirs = []
+ # return a list of 'site' dirs
+ sitedirs = filter(None,os.environ.get('PYTHONPATH','').split(os.pathsep))
prefixes = [sys.prefix]
if sys.exec_prefix != sys.prefix:
prefixes.append(sys.exec_prefix)
@@ -939,7 +1022,7 @@ def get_site_dirs():
sitedirs = filter(os.path.isdir, sitedirs)
sitedirs = map(normalize_path, sitedirs)
- return sitedirs # ensure at least one
+ return sitedirs
def expand_paths(inputs):
"""Yield sys.path directories that might contain "old-style" packages"""