Ronny Pfannschmidt avatar Ronny Pfannschmidt committed 3ea27d2

enable easy_install --user, *warning breaks tests*

the test-isolation got borked and operates on the users home instead of the test-tempdirs

Comments (0)

Files changed (4)

setuptools/command/develop.py

 from distutils.util import convert_path, subst_vars
 from pkg_resources import Distribution, PathMetadata, normalize_path
 from distutils import log
-from distutils.errors import *
-import sys, os, setuptools, glob
-from distutils.sysconfig import get_config_vars
-from distutils.command.install import INSTALL_SCHEMES, SCHEME_KEYS
-
-if sys.version < "2.6":
-    USER_BASE = None
-    USER_SITE = None
-    HAS_USER_SITE = False
-else:
-    from site import USER_BASE
-    from site import USER_SITE
-    HAS_USER_SITE = True
+from distutils.errors import DistutilsError, DistutilsOptionError
+import os, setuptools, glob
 
 class develop(easy_install):
     """Set up package for development"""
 
     boolean_options = easy_install.boolean_options + ['uninstall']
 
-    if HAS_USER_SITE:
-        user_options.append(('user', None,
-                             "install in user site-package '%s'" % USER_SITE))
-        boolean_options.append('user')
-
     command_consumes_arguments = False  # override base
 
     def run(self):
         easy_install.initialize_options(self)
         self.setup_path = None
         self.always_copy_from = '.'   # always copy eggs installed in curdir
-        self.user = 0
-        self.install_purelib = None     # for pure module distributions
-        self.install_platlib = None     # non-pure (dists w/ extensions)
-        self.install_headers = None     # for C/C++ headers
-        self.install_lib = None         # set to either purelib or platlib
-        self.install_scripts = None
-        self.install_data = None
-        self.install_base = None
-        self.install_platbase = None
-        self.install_userbase = USER_BASE
-        self.install_usersite = USER_SITE
 
-    def select_scheme(self, name):
-        """Sets the install directories by applying the install schemes."""
-        # it's the caller's problem if they supply a bad name!
-        scheme = INSTALL_SCHEMES[name]
-        for key in SCHEME_KEYS:
-            attrname = 'install_' + key
-            if getattr(self, attrname) is None:
-                setattr(self, attrname, scheme[key])
-
-    def create_home_path(self):
-        """Create directories under ~."""
-        if not self.user:
-            return
-        home = convert_path(os.path.expanduser("~"))
-        for name, path in self.config_vars.iteritems():
-            if path.startswith(home) and not os.path.isdir(path):
-                self.debug_print("os.makedirs('%s', 0700)" % path)
-                os.makedirs(path, 0700)
 
     def _expand_attrs(self, attrs):
         for attr in attrs:
         self.args = [ei.egg_name]
 
 
-        py_version = sys.version.split()[0]
-        prefix, exec_prefix = get_config_vars('prefix', 'exec_prefix')
-        self.config_vars = {'dist_name': self.distribution.get_name(),
-                            'dist_version': self.distribution.get_version(),
-                            'dist_fullname': self.distribution.get_fullname(),
-                            'py_version': py_version,
-                            'py_version_short': py_version[0:3],
-                            'py_version_nodot': py_version[0] + py_version[2],
-                            'sys_prefix': prefix,
-                            'prefix': prefix,
-                            'sys_exec_prefix': exec_prefix,
-                            'exec_prefix': exec_prefix,
-                           }
 
-        if HAS_USER_SITE:
-            self.config_vars['userbase'] = self.install_userbase
-            self.config_vars['usersite'] = self.install_usersite
 
-        # fix the install_dir if "--user" was used
-        if self.user:
-            self.create_home_path()
-            if self.install_userbase is None:
-                raise DistutilsPlatformError(
-                    "User base directory is not specified")
-            self.install_base = self.install_platbase = self.install_userbase
-            if os.name == 'posix':
-                self.select_scheme("unix_user")
-            else:
-                self.select_scheme(os.name + "_user")
-
+        easy_install.finalize_options(self)
         self.expand_basedirs()
         self.expand_dirs()
-
-        if self.user and self.install_purelib:
-            self.install_dir = self.install_purelib
-            self.script_dir = self.install_scripts
-
-        easy_install.finalize_options(self)
         # pick up setup-dir .egg files only: no .egg-info
         self.package_index.scan(glob.glob('*.egg'))
 

setuptools/command/easy_install.py

 from setuptools import Command
 from setuptools.sandbox import run_setup
 from distutils import log, dir_util
-from distutils.sysconfig import get_python_lib
+from distutils.util import convert_path, subst_vars
+from distutils.sysconfig import get_python_lib, get_config_vars
 from distutils.errors import DistutilsArgError, DistutilsOptionError, \
     DistutilsError
+from distutils.command.install import INSTALL_SCHEMES, SCHEME_KEYS
 from setuptools.archive_util import unpack_archive
 from setuptools.package_index import PackageIndex, parse_bdist_wininst
 from setuptools.package_index import URL_SCHEME
     'main', 'get_exe_prefixes',
 ]
 
+
+if sys.version < "2.6":
+    USER_BASE = None
+    USER_SITE = None
+    HAS_USER_SITE = False
+else:
+    from site import USER_BASE
+    from site import USER_SITE
+    HAS_USER_SITE = True
+
 def samefile(p1,p2):
     if hasattr(os.path,'samefile') and (
         os.path.exists(p1) and os.path.exists(p2)
         'delete-conflicting', 'ignore-conflicts-at-my-risk', 'editable',
         'no-deps', 'local-snapshots-ok', 'version'
     ]
+
+    if HAS_USER_SITE:
+        user_options.append(('user', None,
+                             "install in user site-package '%s'" % USER_SITE))
+        boolean_options.append('user')
+
+
     negative_opt = {'always-unzip': 'zip-ok'}
     create_index = PackageIndex
 
     def initialize_options(self):
+        self.user = 0
         self.zip_ok = self.local_snapshots_ok = None
         self.install_dir = self.script_dir = self.exclude_scripts = None
         self.index_url = None
         self.editable = self.no_deps = self.allow_hosts = None
         self.root = self.prefix = self.no_report = None
         self.version = None
+        self.install_purelib = None     # for pure module distributions
+        self.install_platlib = None     # non-pure (dists w/ extensions)
+        self.install_headers = None     # for C/C++ headers
+        self.install_lib = None         # set to either purelib or platlib
+        self.install_scripts = None
+        self.install_data = None
+        self.install_base = None
+        self.install_platbase = None
+        self.install_userbase = USER_BASE
+        self.install_usersite = USER_SITE
 
         # Options not specifiable via command line
         self.package_index = None
             print 'distribute %s' % get_distribution('distribute').version
             sys.exit()
 
+        py_version = sys.version.split()[0]
+        prefix, exec_prefix = get_config_vars('prefix', 'exec_prefix')
+
+        self.config_vars = {'dist_name': self.distribution.get_name(),
+                            'dist_version': self.distribution.get_version(),
+                            'dist_fullname': self.distribution.get_fullname(),
+                            'py_version': py_version,
+                            'py_version_short': py_version[0:3],
+                            'py_version_nodot': py_version[0] + py_version[2],
+                            'sys_prefix': prefix,
+                            'prefix': prefix,
+                            'sys_exec_prefix': exec_prefix,
+                            'exec_prefix': exec_prefix,
+                           }
+
+        if HAS_USER_SITE:
+            self.config_vars['userbase'] = self.install_userbase
+            self.config_vars['usersite'] = self.install_usersite
+
+        # fix the install_dir if "--user" was used
+        #XXX: duplicate of the code in the setup command
+        if self.user:
+            self.create_home_path()
+            if self.install_userbase is None:
+                raise DistutilsPlatformError(
+                    "User base directory is not specified")
+            self.install_base = self.install_platbase = self.install_userbase
+            if os.name == 'posix':
+                self.select_scheme("unix_user")
+            else:
+                self.select_scheme(os.name + "_user")
+
+        if self.user and self.install_purelib:
+            self.install_dir = self.install_purelib
+            self.script_dir = self.install_scripts
+
         self._expand('install_dir','script_dir','build_directory','site_dirs')
         # If a non-default installation directory was specified, default the
         # script directory to match it.
 
 
 
+    def select_scheme(self, name):
+        """Sets the install directories by applying the install schemes."""
+        # it's the caller's problem if they supply a bad name!
+        scheme = INSTALL_SCHEMES[name]
+        for key in SCHEME_KEYS:
+            attrname = 'install_' + key
+            if getattr(self, attrname) is None:
+                setattr(self, attrname, scheme[key])
+
 
 
 
 
 
 
-
+    def create_home_path(self):
+        """Create directories under ~."""
+        if not self.user:
+            return
+        home = convert_path(os.path.expanduser("~"))
+        for name, path in self.config_vars.iteritems():
+            if path.startswith(home) and not os.path.isdir(path):
+                self.debug_print("os.makedirs('%s', 0700)" % path)
+                os.makedirs(path, 0700)
 
 
 

setuptools/tests/test_develop.py

 from StringIO import StringIO
 
 from setuptools.command.develop import develop
-from setuptools.command import develop as develop_pkg
+from setuptools.command import easy_install as easy_install_pkg
 from setuptools.dist import Distribution
 
 SETUP_PY = """\
 
 class TestDevelopTest(unittest.TestCase):
 
-    def setUp(self):
+    def setUp(self): 
         self.dir = tempfile.mkdtemp()
         setup = os.path.join(self.dir, 'setup.py')
         f = open(setup, 'w')
         os.chdir(self.dir)
         if sys.version >= "2.6":
             self.old_base = site.USER_BASE
-            site.USER_BASE = develop_pkg.USER_BASE = tempfile.mkdtemp()
+            site.USER_BASE = easy_install_pkg.USER_BASE = tempfile.mkdtemp()
             self.old_site = site.USER_SITE
-            site.USER_SITE = develop_pkg.USER_SITE = tempfile.mkdtemp()
+            site.USER_SITE = easy_install_pkg.USER_SITE = tempfile.mkdtemp()
 
-    def tearDown(self):
+    def tearDown(self): 
         os.chdir(self.old_cwd)
         shutil.rmtree(self.dir)
         if sys.version >= "2.6":
             shutil.rmtree(site.USER_BASE)
             shutil.rmtree(site.USER_SITE)
-            site.USER_BASE = self.old_base
-            site.USER_SITE = self.old_site
+            easy_install_pkg.USER_BASE = site.USER_BASE = self.old_base
+            easy_install_pkg.USER_SITE = site.USER_SITE = self.old_site
 
     def test_develop(self):
         if sys.version < "2.6":

setuptools/tests/test_easy_install.py

 """
 import sys
 import os, shutil, tempfile, unittest
+import site
 from setuptools.command.easy_install import easy_install, get_script_args, main
 from setuptools.command.easy_install import  PthDistributions
+from setuptools.command import easy_install as easy_install_pkg
 from setuptools.dist import Distribution
 from pkg_resources import Distribution as PRDistribution
 
         pth.add(PRDistribution('/test/location/does-not-have-to-exist'))
         self.assertFalse(pth.dirty)
 
+
+
+class TestUserInstallTest(unittest.TestCase):
+
+    def setUp(self):
+        self.dir = tempfile.mkdtemp()
+        setup = os.path.join(self.dir, 'setup.py')
+        f = open(setup, 'w')
+        f.write(SETUP_PY)
+        f.close()
+        self.old_cwd = os.getcwd()
+        os.chdir(self.dir)
+        if sys.version >= "2.6":
+            self.old_base = site.USER_BASE
+            site.USER_BASE = easy_install_pkg.USER_BASE = tempfile.mkdtemp()
+            self.old_site = site.USER_SITE
+            site.USER_SITE = easy_install_pkg.USER_SITE = tempfile.mkdtemp()
+
+    def tearDown(self):
+        os.chdir(self.old_cwd)
+        shutil.rmtree(self.dir)
+        if sys.version >=  "2.6":
+            shutil.rmtree(site.USER_BASE)
+            shutil.rmtree(site.USER_SITE)
+            easy_install_pkg.USER_BASE = site.USER_BASE = self.old_base
+            easy_install_pkg.USER_SITE = site.USER_SITE = self.old_site
+
+    def test_install(self):
+        if sys.version < "2.6":
+            return
+        dist = Distribution()
+        dist.script_name = 'setup.py'
+        cmd = easy_install(dist)
+        cmd.user = 1
+        cmd.ensure_finalized()
+        cmd.user = 1
+        old_stdout = sys.stdout
+        sys.stdout = StringIO()
+        try:
+            cmd.run()
+        finally:
+            sys.stdout = old_stdout
+
+        # let's see if we got our egg link at the right place
+        content = os.listdir(site.USER_SITE)
+        content.sort()
+        self.assertEquals(content, ['UNKNOWN.egg-link', 'easy-install.pth'])
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.