Beispiel #1
0
    def get_easy_install_cmd(self, build_only=False, **kwargs):
        """ Returns a correctly setup easy_install cmd class for passing
            into `pkglib.setuptools.buildout.install`.
            Lifted from `setuptools.dist`

            Parameters
            ----------
            build_only : `bool`
                Configured for build and testing packages - these will be installed into the
                directory returned from `pkglib.manage.get_build_egg_dir`

            kwargs:
                Other kwargs to pass to easy_install constructor

            Returns
            -------
            cmd : `setuptools.Command`
                Configured command-class
        """
        dist = self.distribution.__class__({'script_args': ['easy_install']})
        dist.parse_config_files()

        if build_only:
            cmd = easy_install(
                dist, args=["x"], install_dir=manage.get_build_egg_dir(), exclude_scripts=True,
                always_copy=False, build_directory=None, editable=False,
                upgrade=False, multi_version=True, no_report=True, **kwargs)
        else:
            cmd = easy_install(dist, args=['x'], **kwargs)

        cmd.ensure_finalized()
        return cmd
    def test_local_index(self):
        # make sure the local index is used
        # when easy_install looks for installed
        # packages
        new_location = tempfile.mkdtemp()
        target = tempfile.mkdtemp()
        egg_file = os.path.join(new_location, 'foo-1.0.egg-info')
        f = open(egg_file, 'w')
        try:
            f.write('Name: foo\n')
        except:
            f.close()

        sys.path.append(target)
        old_ppath = os.environ.get('PYTHONPATH')
        os.environ['PYTHONPATH'] = ':'.join(sys.path)
        try:
            dist = Distribution()
            dist.script_name = 'setup.py'
            cmd = easy_install(dist)
            cmd.install_dir = target
            cmd.args = ['foo']
            cmd.ensure_finalized()
            cmd.local_index.scan([new_location])
            res = cmd.easy_install('foo')
            self.assertEquals(res.location, new_location)
        finally:
            sys.path.remove(target)
            shutil.rmtree(new_location)
            shutil.rmtree(target)
            if old_ppath is not None:
                os.environ['PYTHONPATH'] = old_ppath
            else:
                del os.environ['PYTHONPATH']
Beispiel #3
0
    def fetch_build_egg(self, req):
        """Fetch an egg needed for building"""

        try:
            cmd = self._egg_fetcher
            cmd.package_index.to_scan = []
        except AttributeError:
            from setuptools.command.easy_install import easy_install
            dist = self.__class__({'script_args':['easy_install']})
            dist.parse_config_files()
            opts = dist.get_option_dict('easy_install')
            keep = (
                'find_links', 'site_dirs', 'index_url', 'optimize',
                'site_dirs', 'allow_hosts'
            )
            for key in list(opts.keys()):
                if key not in keep:
                    del opts[key]   # don't use any other settings
            if self.dependency_links:
                links = self.dependency_links[:]
                if 'find_links' in opts:
                    links = opts['find_links'][1].split() + links
                opts['find_links'] = ('setup', links)
            cmd = easy_install(
                dist, args=["x"], install_dir=os.curdir, exclude_scripts=True,
                always_copy=False, build_directory=None, editable=False,
                upgrade=False, multi_version=True, no_report=True, user=False
            )
            cmd.ensure_finalized()
            self._egg_fetcher = cmd
        return cmd.easy_install(req)
def install_context(request, tmpdir, monkeypatch):
    """Fixture to set up temporary installation directory.
    """
    # Save old values so we can restore them.
    new_cwd = tmpdir.mkdir("cwd")
    user_base = tmpdir.mkdir("user_base")
    user_site = tmpdir.mkdir("user_site")
    install_dir = tmpdir.mkdir("install_dir")

    def fin():
        # undo the monkeypatch, particularly needed under
        # windows because of kept handle on cwd
        monkeypatch.undo()
        new_cwd.remove()
        user_base.remove()
        user_site.remove()
        install_dir.remove()

    request.addfinalizer(fin)

    # Change the environment and site settings to control where the
    # files are installed and ensure we do not overwrite anything.
    monkeypatch.chdir(new_cwd)
    monkeypatch.setattr(easy_install_pkg, "__file__", user_site.strpath)
    monkeypatch.setattr("site.USER_BASE", user_base.strpath)
    monkeypatch.setattr("site.USER_SITE", user_site.strpath)
    monkeypatch.setattr("sys.path", sys.path + [install_dir.strpath])
    monkeypatch.setenv("PYTHONPATH", os.path.pathsep.join(sys.path))

    # Set up the command for performing the installation.
    dist = Distribution()
    cmd = easy_install(dist)
    cmd.install_dir = install_dir.strpath
    return cmd
Beispiel #5
0
 def fetch_build_egg(self, req):
     """Fetch an egg needed for building"""
     from setuptools.command.easy_install import easy_install
     dist = self.__class__({'script_args': ['easy_install']})
     opts = dist.get_option_dict('easy_install')
     opts.clear()
     opts.update(
         (k, v)
         for k, v in self.get_option_dict('easy_install').items()
         if k in (
             # don't use any other settings
             'find_links', 'site_dirs', 'index_url',
             'optimize', 'site_dirs', 'allow_hosts',
         ))
     if self.dependency_links:
         links = self.dependency_links[:]
         if 'find_links' in opts:
             links = opts['find_links'][1] + links
         opts['find_links'] = ('setup', links)
     install_dir = self.get_egg_cache_dir()
     cmd = easy_install(
         dist, args=["x"], install_dir=install_dir,
         exclude_scripts=True,
         always_copy=False, build_directory=None, editable=False,
         upgrade=False, multi_version=True, no_report=True, user=False
     )
     cmd.ensure_finalized()
     return cmd.easy_install(req)
Beispiel #6
0
	def fetch_build_egg(self, req):
		""" Specialized version of Distribution.fetch_build_egg
		that respects respects allow_hosts and index_url. """
		from setuptools.command.easy_install import easy_install
		dist = Distribution({'script_args': ['easy_install']})
		dist.parse_config_files()
		opts = dist.get_option_dict('easy_install')
		keep = (
			'find_links', 'site_dirs', 'index_url', 'optimize',
			'site_dirs', 'allow_hosts'
		)
		for key in list(opts):
			if key not in keep:
				del opts[key]  # don't use any other settings
		if self.dependency_links:
			links = self.dependency_links[:]
			if 'find_links' in opts:
				links = opts['find_links'][1].split() + links
			opts['find_links'] = ('setup', links)
		if self.allow_hosts:
			opts['allow_hosts'] = ('test', self.allow_hosts)
		if self.index_url:
			opts['index_url'] = ('test', self.index_url)
		install_dir_func = getattr(self, 'get_egg_cache_dir', _os.getcwd)
		install_dir = install_dir_func()
		cmd = easy_install(
			dist, args=["x"], install_dir=install_dir,
			exclude_scripts=True,
			always_copy=False, build_directory=None, editable=False,
			upgrade=False, multi_version=True, no_report=True, user=False
		)
		cmd.ensure_finalized()
		return cmd.easy_install(req)
 def _build_egg_fetcher(self):
     """Build an egg fetcher that respects index_url and allow_hosts"""
     # modified from setuptools.dist:Distribution.fetch_build_egg
     from setuptools.command.easy_install import easy_install
     main_dist = self.distribution
     # construct a fake distribution to store the args for easy_install
     dist = main_dist.__class__({'script_args': ['easy_install']})
     dist.parse_config_files()
     opts = dist.get_option_dict('easy_install')
     keep = (
         'find_links', 'site_dirs', 'index_url', 'optimize',
         'site_dirs', 'allow_hosts'
     )
     for key in opts.keys():
         if key not in keep:
             del opts[key]   # don't use any other settings
     if main_dist.dependency_links:
         links = main_dist.dependency_links[:]
         if 'find_links' in opts:
             links = opts['find_links'][1].split() + links
         opts['find_links'] = ('setup', links)
     if self.allow_hosts:
         opts['allow_hosts'] = ('test', self.allow_hosts)
     if self.index_url:
         opts['index_url'] = ('test', self.index_url)
     install_dir_func = getattr(dist, 'get_egg_cache_dir', os.getcwd)
     install_dir = install_dir_func()
     cmd = easy_install(
         dist, args=["x"], install_dir=install_dir, exclude_scripts=True,
         always_copy=False, build_directory=None, editable=False,
         upgrade=False, multi_version=True, no_report = True
     )
     cmd.ensure_finalized()
     main_dist._egg_fetcher = cmd
Beispiel #8
0
def install_scripts(distributions):
    """
    Regenerate the entry_points console_scripts for the named distribution.
    """
    try:
        if "__PEX_UNVENDORED__" in __import__("os").environ:
          from setuptools.command import easy_install  # vendor:skip
        else:
          from pex.third_party.setuptools.command import easy_install

        if "__PEX_UNVENDORED__" in __import__("os").environ:
          import pkg_resources  # vendor:skip
        else:
          import pex.third_party.pkg_resources as pkg_resources

    except ImportError:
        raise RuntimeError("'wheel install_scripts' needs setuptools.")

    for dist in distributions:
        pkg_resources_dist = pkg_resources.get_distribution(dist)
        install = get_install_command(dist)
        command = easy_install.easy_install(install.distribution)
        command.args = ['wheel']  # dummy argument
        command.finalize_options()
        command.install_egg_scripts(pkg_resources_dist)
Beispiel #9
0
    def fetch_build_egg(self, req):
        """Fetch an egg needed for building"""
        try:
            cmd = self._egg_fetcher
        except AttributeError:
            from setuptools.command.easy_install import easy_install

            dist = self.__class__({"script_args": ["easy_install"]})
            dist.parse_config_files()
            opts = dist.get_option_dict("easy_install")
            keep = ("find_links", "site_dirs", "index_url", "optimize", "site_dirs", "allow_hosts")
            for key in opts.keys():
                if key not in keep:
                    del opts[key]  # don't use any other settings
            if self.dependency_links:
                links = self.dependency_links[:]
                if "find_links" in opts:
                    links = opts["find_links"][1].split() + links
                opts["find_links"] = ("setup", links)
            cmd = easy_install(
                dist,
                args=["x"],
                install_dir=os.curdir,
                exclude_scripts=True,
                always_copy=False,
                build_directory=None,
                editable=False,
                upgrade=False,
                multi_version=True,
                no_report=True,
            )
            cmd.ensure_finalized()
            self._egg_fetcher = cmd
        return cmd.easy_install(req)
 def test_install_site_py(self, tmpdir):
     dist = Distribution()
     cmd = ei.easy_install(dist)
     cmd.sitepy_installed = False
     cmd.install_dir = str(tmpdir)
     cmd.install_site_py()
     assert (tmpdir / 'site.py').exists()
Beispiel #11
0
def install_context(request, tmpdir, monkeypatch):
    """Fixture to set up temporary installation directory.
    """
    # Save old values so we can restore them.
    new_cwd = tmpdir.mkdir('cwd')
    user_base = tmpdir.mkdir('user_base')
    user_site = tmpdir.mkdir('user_site')
    install_dir = tmpdir.mkdir('install_dir')

    def fin():
        new_cwd.remove()
        user_base.remove()
        user_site.remove()
        install_dir.remove()
    request.addfinalizer(fin)

    # Change the environment and site settings to control where the
    # files are installed and ensure we do not overwrite anything.
    monkeypatch.chdir(new_cwd)
    monkeypatch.setattr(easy_install_pkg, '__file__', user_site.strpath)
    monkeypatch.setattr('site.USER_BASE', user_base.strpath)
    monkeypatch.setattr('site.USER_SITE', user_site.strpath)
    monkeypatch.setattr('sys.path', sys.path + [install_dir.strpath])
    monkeypatch.setenv('PYTHONPATH', os.path.pathsep.join(sys.path))

    # Set up the command for performing the installation.
    dist = Distribution()
    cmd = easy_install(dist)
    cmd.install_dir = install_dir.strpath
    return cmd
 def assert_not_user_site():
     # create a finalized easy_install command
     dist = Distribution()
     dist.script_name = 'setup.py'
     cmd = ei.easy_install(dist)
     cmd.args = ['py']
     cmd.ensure_finalized()
     assert not cmd.user, 'user should not be implied'
 def test_user_install_implied(self):
     site.ENABLE_USER_SITE = True # disabled sometimes
     #XXX: replace with something meaningfull
     dist = Distribution()
     dist.script_name = 'setup.py'
     cmd = easy_install(dist)
     cmd.args = ['py']
     cmd.ensure_finalized()
     self.assertTrue(cmd.user, 'user should be implied')
 def test_user_install_not_implied_without_usersite_enabled(self):
     site.ENABLE_USER_SITE = False # usually enabled
     #XXX: replace with something meaningfull
     dist = Distribution()
     dist.script_name = 'setup.py'
     cmd = easy_install(dist)
     cmd.args = ['py']
     cmd.initialize_options()
     assert not cmd.user, 'NOT user should be implied'
 def test_write_exception(self):
     """
     Test that `cant_write_to_target` is rendered as a DistutilsError.
     """
     dist = Distribution()
     cmd = ei.easy_install(dist)
     cmd.install_dir = os.getcwd()
     with pytest.raises(distutils.errors.DistutilsError):
         cmd.cant_write_to_target()
Beispiel #16
0
 def fetch_build_egg(self, req):
     try:
         cmd = self._egg_fetcher
     except AttributeError:
         dist = self.__class__({'script_args': ['easy_install']})
         dist.parse_config_files()
         cmd = easy_install.easy_install(dist, args=['x'],
                                         index_url=get_index_url())
         cmd.ensure_finalized()
         self._egg_fetcher = cmd
     return cmd.easy_install(req)
 def test_install_site_py(self):
     dist = Distribution()
     cmd = easy_install(dist)
     cmd.sitepy_installed = False
     cmd.install_dir = tempfile.mkdtemp()
     try:
         cmd.install_site_py()
         sitepy = os.path.join(cmd.install_dir, 'site.py')
         self.assertTrue(os.path.exists(sitepy))
     finally:
         shutil.rmtree(cmd.install_dir)
 def test_user_install_not_implied_without_usersite_enabled(self):
     easy_install_pkg.HAS_USER_SITE = False # usually enabled
     #XXX: replace with something meaningfull
     if sys.version < "2.6":
         return #SKIP
     dist = Distribution()
     dist.script_name = 'setup.py'
     cmd = easy_install(dist)
     cmd.args = ['py']
     cmd.initialize_options()
     self.assertFalse(cmd.user, 'NOT user should be implied')
 def test_user_install_implied(self):
     easy_install_pkg.HAS_USER_SITE = True # disabled sometimes
     #XXX: replace with something meaningfull
     if sys.version < "2.6":
         return #SKIP
     dist = Distribution()
     dist.script_name = 'setup.py'
     cmd = easy_install(dist)
     cmd.args = ['py']
     cmd.ensure_finalized()
     self.assertTrue(cmd.user, 'user should be implied')
Beispiel #20
0
 def test_install_site_py(self):
     dist = Distribution()
     cmd = ei.easy_install(dist)
     cmd.sitepy_installed = False
     cmd.install_dir = tempfile.mkdtemp()
     try:
         cmd.install_site_py()
         sitepy = os.path.join(cmd.install_dir, 'site.py')
         assert os.path.exists(sitepy)
     finally:
         shutil.rmtree(cmd.install_dir)
 def test_user_install_not_implied_without_usersite_enabled(self):
     easy_install_pkg.HAS_USER_SITE = False  # usually enabled
     #XXX: replace with something meaningfull
     if sys.version < "2.6":
         return  #SKIP
     dist = Distribution()
     dist.script_name = 'setup.py'
     cmd = easy_install(dist)
     cmd.args = ['py']
     cmd.initialize_options()
     self.assertFalse(cmd.user, 'NOT user should be implied')
 def test_user_install_implied(self):
     easy_install_pkg.HAS_USER_SITE = True  # disabled sometimes
     #XXX: replace with something meaningfull
     if sys.version < "2.6":
         return  #SKIP
     dist = Distribution()
     dist.script_name = 'setup.py'
     cmd = easy_install(dist)
     cmd.args = ['py']
     cmd.ensure_finalized()
     self.assertTrue(cmd.user, 'user should be implied')
 def test_unicode_content_in_sdist(
         self, sdist_unicode_in_script, tmpdir, monkeypatch):
     """
     The install command should execute correctly even if
     the package has unicode in scripts.
     """
     dist = Distribution({"script_args": ["easy_install"]})
     target = (tmpdir / "target").ensure_dir()
     cmd = ei.easy_install(dist, install_dir=str(target), args=["x"])
     monkeypatch.setitem(os.environ, "PYTHONPATH", str(target))
     cmd.ensure_finalized()
     cmd.easy_install(sdist_unicode_in_script)
Beispiel #24
0
 def test_unicode_content_in_sdist(self, sdist_unicode_in_script, tmpdir,
                                   monkeypatch):
     """
     The install command should execute correctly even if
     the package has unicode in scripts.
     """
     dist = Distribution({"script_args": ["easy_install"]})
     target = (tmpdir / "target").ensure_dir()
     cmd = ei.easy_install(dist, install_dir=str(target), args=["x"])
     monkeypatch.setitem(os.environ, "PYTHONPATH", str(target))
     cmd.ensure_finalized()
     cmd.easy_install(sdist_unicode_in_script)
Beispiel #25
0
    def test_no_find_links(self):
        # new option '--no-find-links', that blocks find-links added at
        # the project level
        dist = Distribution()
        cmd = ei.easy_install(dist)
        cmd.check_pth_processing = lambda: True
        cmd.no_find_links = True
        cmd.find_links = ['link1', 'link2']
        cmd.install_dir = os.path.join(tempfile.mkdtemp(), 'ok')
        cmd.args = ['ok']
        cmd.ensure_finalized()
        assert cmd.package_index.scanned_urls == {}

        # let's try without it (default behavior)
        cmd = ei.easy_install(dist)
        cmd.check_pth_processing = lambda: True
        cmd.find_links = ['link1', 'link2']
        cmd.install_dir = os.path.join(tempfile.mkdtemp(), 'ok')
        cmd.args = ['ok']
        cmd.ensure_finalized()
        keys = sorted(cmd.package_index.scanned_urls.keys())
        assert keys == ['link1', 'link2']
    def test_no_find_links(self):
        # new option '--no-find-links', that blocks find-links added at
        # the project level
        dist = Distribution()
        cmd = ei.easy_install(dist)
        cmd.check_pth_processing = lambda: True
        cmd.no_find_links = True
        cmd.find_links = ['link1', 'link2']
        cmd.install_dir = os.path.join(tempfile.mkdtemp(), 'ok')
        cmd.args = ['ok']
        cmd.ensure_finalized()
        assert cmd.package_index.scanned_urls == {}

        # let's try without it (default behavior)
        cmd = ei.easy_install(dist)
        cmd.check_pth_processing = lambda: True
        cmd.find_links = ['link1', 'link2']
        cmd.install_dir = os.path.join(tempfile.mkdtemp(), 'ok')
        cmd.args = ['ok']
        cmd.ensure_finalized()
        keys = sorted(cmd.package_index.scanned_urls.keys())
        assert keys == ['link1', 'link2']
Beispiel #27
0
    def test_no_find_links(self):
        # new option '--no-find-links', that blocks find-links added at
        # the project level
        dist = Distribution()
        cmd = easy_install(dist)
        cmd.check_pth_processing = lambda: True
        cmd.no_find_links = True
        cmd.find_links = ["link1", "link2"]
        cmd.install_dir = os.path.join(tempfile.mkdtemp(), "ok")
        cmd.args = ["ok"]
        cmd.ensure_finalized()
        self.assertEquals(cmd.package_index.scanned_urls, {})

        # let's try without it (default behavior)
        cmd = easy_install(dist)
        cmd.check_pth_processing = lambda: True
        cmd.find_links = ["link1", "link2"]
        cmd.install_dir = os.path.join(tempfile.mkdtemp(), "ok")
        cmd.args = ["ok"]
        cmd.ensure_finalized()
        keys = cmd.package_index.scanned_urls.keys()
        keys.sort()
        self.assertEquals(keys, ["link1", "link2"])
Beispiel #28
0
 def test_unicode_filename_in_sdist(self, sdist_unicode, tmpdir, monkeypatch):
     """
     The install command should execute correctly even if
     the package has unicode filenames.
     """
     dist = Distribution({'script_args': ['easy_install']})
     target = (tmpdir / 'target').ensure_dir()
     cmd = ei.easy_install(
         dist,
         install_dir=str(target),
         args=['x'],
     )
     monkeypatch.setitem(os.environ, 'PYTHONPATH', str(target))
     cmd.ensure_finalized()
     cmd.easy_install(sdist_unicode)
 def test_unicode_filename_in_sdist(self, sdist_unicode, tmpdir, monkeypatch):
     """
     The install command should execute correctly even if
     the package has unicode filenames.
     """
     dist = Distribution({'script_args': ['easy_install']})
     target = (tmpdir / 'target').ensure_dir()
     cmd = ei.easy_install(
         dist,
         install_dir=str(target),
         args=['x'],
     )
     monkeypatch.setitem(os.environ, 'PYTHONPATH', str(target))
     cmd.ensure_finalized()
     cmd.easy_install(sdist_unicode)
Beispiel #30
0
 def test_script_install(self, sdist_script, tmpdir, monkeypatch):
     """
     Check scripts are installed.
     """
     dist = Distribution({'script_args': ['easy_install']})
     target = (tmpdir / 'target').ensure_dir()
     cmd = ei.easy_install(
         dist,
         install_dir=str(target),
         args=['x'],
     )
     monkeypatch.setitem(os.environ, 'PYTHONPATH', str(target))
     cmd.ensure_finalized()
     cmd.easy_install(sdist_script)
     assert (target / 'mypkg_script').exists()
 def test_script_install(self, sdist_script, tmpdir, monkeypatch):
     """
     Check scripts are installed.
     """
     dist = Distribution({'script_args': ['easy_install']})
     target = (tmpdir / 'target').ensure_dir()
     cmd = ei.easy_install(
         dist,
         install_dir=str(target),
         args=['x'],
     )
     monkeypatch.setitem(os.environ, 'PYTHONPATH', str(target))
     cmd.ensure_finalized()
     cmd.easy_install(sdist_script)
     assert (target / 'mypkg_script').exists()
 def test_local_index(self, foo_package, install_target):
     """
     The local index must be used when easy_install locates installed
     packages.
     """
     dist = Distribution()
     dist.script_name = 'setup.py'
     cmd = ei.easy_install(dist)
     cmd.install_dir = install_target
     cmd.args = ['foo']
     cmd.ensure_finalized()
     cmd.local_index.scan([foo_package])
     res = cmd.easy_install('foo')
     actual = os.path.normcase(os.path.realpath(res.location))
     expected = os.path.normcase(os.path.realpath(foo_package))
     assert actual == expected
Beispiel #33
0
 def test_local_index(self, foo_package, install_target):
     """
     The local index must be used when easy_install locates installed
     packages.
     """
     dist = Distribution()
     dist.script_name = 'setup.py'
     cmd = ei.easy_install(dist)
     cmd.install_dir = install_target
     cmd.args = ['foo']
     cmd.ensure_finalized()
     cmd.local_index.scan([foo_package])
     res = cmd.easy_install('foo')
     actual = os.path.normcase(os.path.realpath(res.location))
     expected = os.path.normcase(os.path.realpath(foo_package))
     assert actual == expected
Beispiel #34
0
def install_scripts(distributions):
    """
    Regenerate the entry_points console_scripts for the named distribution.
    """
    try:
        from setuptools.command import easy_install
        import pkg_resources
    except ImportError:
        raise RuntimeError("'wheel install_scripts' needs setuptools.")

    for dist in distributions:
        pkg_resources_dist = pkg_resources.get_distribution(dist)
        install = wheel.paths.get_install_command(dist)
        command = easy_install.easy_install(install.distribution)
        command.args = ['wheel'] # dummy argument
        command.finalize_options()
        command.install_egg_scripts(pkg_resources_dist)
Beispiel #35
0
    def fetch_build_egg(self, req):
        """ Specialized version of Distribution.fetch_build_egg
        that respects respects allow_hosts and index_url. """
        from setuptools.command.easy_install import easy_install

        dist = Distribution({'script_args': ['easy_install']})
        dist.parse_config_files()
        opts = dist.get_option_dict('easy_install')
        keep = (
            'find_links',
            'site_dirs',
            'index_url',
            'optimize',
            'site_dirs',
            'allow_hosts',
        )
        for key in list(opts):
            if key not in keep:
                del opts[key]  # don't use any other settings
        if self.dependency_links:
            links = self.dependency_links[:]
            if 'find_links' in opts:
                links = opts['find_links'][1].split() + links
            opts['find_links'] = ('setup', links)
        if self.allow_hosts:
            opts['allow_hosts'] = ('test', self.allow_hosts)
        if self.index_url:
            opts['index_url'] = ('test', self.index_url)
        install_dir_func = getattr(self, 'get_egg_cache_dir', _os.getcwd)
        install_dir = install_dir_func()
        cmd = easy_install(
            dist,
            args=["x"],
            install_dir=install_dir,
            exclude_scripts=True,
            always_copy=False,
            build_directory=None,
            editable=False,
            upgrade=False,
            multi_version=True,
            no_report=True,
            user=False,
        )
        cmd.ensure_finalized()
        return cmd.easy_install(req)
    def test_local_index(self):
        # make sure the local index is used
        # when easy_install looks for installed
        # packages
        new_location = tempfile.mkdtemp()
        target = tempfile.mkdtemp()
        egg_file = os.path.join(new_location, 'foo-1.0.egg-info')
        f = open(egg_file, 'w')
        try:
            f.write('Name: foo\n')
        finally:
            f.close()

        sys.path.append(target)
        old_ppath = os.environ.get('PYTHONPATH')
        os.environ['PYTHONPATH'] = os.path.pathsep.join(sys.path)
        try:
            dist = Distribution()
            dist.script_name = 'setup.py'
            cmd = easy_install(dist)
            cmd.install_dir = target
            cmd.args = ['foo']
            cmd.ensure_finalized()
            cmd.local_index.scan([new_location])
            res = cmd.easy_install('foo')
            actual = os.path.normcase(os.path.realpath(res.location))
            expected = os.path.normcase(os.path.realpath(new_location))
            self.assertEqual(actual, expected)
        finally:
            sys.path.remove(target)
            for basedir in [
                    new_location,
                    target,
            ]:
                if not os.path.exists(basedir) or not os.path.isdir(basedir):
                    continue
                try:
                    shutil.rmtree(basedir)
                except:
                    pass
            if old_ppath is not None:
                os.environ['PYTHONPATH'] = old_ppath
            else:
                del os.environ['PYTHONPATH']
Beispiel #37
0
    def fetch_build_egg(self, req):
        """Fetch an egg needed for building"""
        from setuptools.command.easy_install import easy_install

        dist = self.__class__({"script_args": ["easy_install"]})
        opts = dist.get_option_dict("easy_install")
        opts.clear()
        opts.update(
            (k, v)
            for k, v in self.get_option_dict("easy_install").items()
            if k
            in (
                # don't use any other settings
                "find_links",
                "site_dirs",
                "index_url",
                "optimize",
                "site_dirs",
                "allow_hosts",
            )
        )
        if self.dependency_links:
            links = self.dependency_links[:]
            if "find_links" in opts:
                links = opts["find_links"][1] + links
            opts["find_links"] = ("setup", links)
        install_dir = self.get_egg_cache_dir()
        cmd = easy_install(
            dist,
            args=["x"],
            install_dir=install_dir,
            exclude_scripts=True,
            always_copy=False,
            build_directory=None,
            editable=False,
            upgrade=False,
            multi_version=True,
            no_report=True,
            user=False,
        )
        cmd.ensure_finalized()
        return cmd.easy_install(req)
Beispiel #38
0
    def test_local_index(self):
        # make sure the local index is used
        # when easy_install looks for installed
        # packages
        new_location = tempfile.mkdtemp()
        target = tempfile.mkdtemp()
        egg_file = os.path.join(new_location, 'foo-1.0.egg-info')
        f = open(egg_file, 'w')
        try:
            f.write('Name: foo\n')
        finally:
            f.close()

        sys.path.append(target)
        old_ppath = os.environ.get('PYTHONPATH')
        os.environ['PYTHONPATH'] = os.path.pathsep.join(sys.path)
        try:
            dist = Distribution()
            dist.script_name = 'setup.py'
            cmd = easy_install(dist)
            cmd.install_dir = target
            cmd.args = ['foo']
            cmd.ensure_finalized()
            cmd.local_index.scan([new_location])
            res = cmd.easy_install('foo')
            actual = os.path.normcase(os.path.realpath(res.location))
            expected = os.path.normcase(os.path.realpath(new_location))
            self.assertEqual(actual, expected)
        finally:
            sys.path.remove(target)
            for basedir in [new_location, target, ]:
                if not os.path.exists(basedir) or not os.path.isdir(basedir):
                    continue
                try:
                    shutil.rmtree(basedir)
                except:
                    pass
            if old_ppath is not None:
                os.environ['PYTHONPATH'] = old_ppath
            else:
                del os.environ['PYTHONPATH']
Beispiel #39
0
def _legacy_fetch_build_egg(dist, req):
    """Fetch an egg needed for building.

    Legacy path using EasyInstall.
    """
    tmp_dist = dist.__class__({"script_args": ["easy_install"]})
    opts = tmp_dist.get_option_dict("easy_install")
    opts.clear()
    opts.update((k, v)
                for k, v in dist.get_option_dict("easy_install").items()
                if k in (
                    # don't use any other settings
                    "find_links",
                    "site_dirs",
                    "index_url",
                    "optimize",
                    "site_dirs",
                    "allow_hosts",
                ))
    if dist.dependency_links:
        links = dist.dependency_links[:]
        if "find_links" in opts:
            links = _fixup_find_links(opts["find_links"][1]) + links
        opts["find_links"] = ("setup", links)
    install_dir = dist.get_egg_cache_dir()
    cmd = easy_install(
        tmp_dist,
        args=["x"],
        install_dir=install_dir,
        exclude_scripts=True,
        always_copy=False,
        build_directory=None,
        editable=False,
        upgrade=False,
        multi_version=True,
        no_report=True,
        user=False,
    )
    cmd.ensure_finalized()
    return cmd.easy_install(req)
def install_context(request):
    """Fixture to set up temporary installation directory.
    """
    # Save old values so we can restore them.
    new_cwd = tempfile.mkdtemp()
    old_cwd = os.getcwd()
    old_enable_site = site.ENABLE_USER_SITE
    old_file = easy_install_pkg.__file__
    old_base = site.USER_BASE
    old_site = site.USER_SITE
    old_ppath = os.environ.get('PYTHONPATH')

    def fin():
        os.chdir(old_cwd)
        shutil.rmtree(new_cwd)
        shutil.rmtree(site.USER_BASE)
        shutil.rmtree(site.USER_SITE)
        site.USER_BASE = old_base
        site.USER_SITE = old_site
        site.ENABLE_USER_SITE = old_enable_site
        easy_install_pkg.__file__ = old_file
        os.environ['PYTHONPATH'] = old_ppath or ''
    request.addfinalizer(fin)

    # Change the environment and site settings to control where the
    # files are installed and ensure we do not overwrite anything.
    site.USER_BASE = tempfile.mkdtemp()
    site.USER_SITE = tempfile.mkdtemp()
    easy_install_pkg.__file__ = site.USER_SITE
    os.chdir(new_cwd)
    install_dir = tempfile.mkdtemp()
    sys.path.append(install_dir)
    os.environ['PYTHONPATH'] = os.path.pathsep.join(sys.path)

    # Set up the command for performing the installation.
    dist = Distribution()
    cmd = easy_install(dist)
    cmd.install_dir = install_dir
    return cmd
Beispiel #41
0
    def do_egg_install(self):

        from setuptools.command.easy_install import easy_install

        cmd = easy_install(
            self.distribution,
            args="x",
            root=self.root,
            record=self.record,
        )
        cmd.ensure_finalized()  # finalize before bdist_egg munges install cmd

        self.run_command('bdist_egg')
        args = [self.distribution.get_command_obj('bdist_egg').egg_output]

        if setuptools.bootstrap_install_from:
            # Bootstrap self-installation of setuptools
            args.insert(0, setuptools.bootstrap_install_from)

        cmd.args = args
        cmd.run()
        setuptools.bootstrap_install_from = None
Beispiel #42
0
    def test_local_index(self):
        # make sure the local index is used
        # when easy_install looks for installed
        # packages
        new_location = tempfile.mkdtemp()
        target = tempfile.mkdtemp()
        egg_file = os.path.join(new_location, "foo-1.0.egg-info")
        f = open(egg_file, "w")
        try:
            f.write("Name: foo\n")
        except:
            f.close()

        sys.path.append(target)
        old_ppath = os.environ.get("PYTHONPATH")
        os.environ["PYTHONPATH"] = os.path.pathsep.join(sys.path)
        try:
            dist = Distribution()
            dist.script_name = "setup.py"
            cmd = easy_install(dist)
            cmd.install_dir = target
            cmd.args = ["foo"]
            cmd.ensure_finalized()
            cmd.local_index.scan([new_location])
            res = cmd.easy_install("foo")
            self.assertEquals(res.location, new_location)
        finally:
            sys.path.remove(target)
            for basedir in [new_location, target]:
                if not os.path.exists(basedir) or not os.path.isdir(basedir):
                    continue
                try:
                    shutil.rmtree(basedir)
                except:
                    pass
            if old_ppath is not None:
                os.environ["PYTHONPATH"] = old_ppath
            else:
                del os.environ["PYTHONPATH"]
Beispiel #43
0
def _legacy_fetch_build_egg(dist, req):
    """Fetch an egg needed for building.

    Legacy path using EasyInstall.
    """
    tmp_dist = dist.__class__({'script_args': ['easy_install']})
    opts = tmp_dist.get_option_dict('easy_install')
    opts.clear()
    opts.update((k, v)
                for k, v in dist.get_option_dict('easy_install').items()
                if k in (
                    # don't use any other settings
                    'find_links',
                    'site_dirs',
                    'index_url',
                    'optimize',
                    'site_dirs',
                    'allow_hosts',
                ))
    if dist.dependency_links:
        links = dist.dependency_links[:]
        if 'find_links' in opts:
            links = opts['find_links'][1] + links
        opts['find_links'] = ('setup', links)
    install_dir = dist.get_egg_cache_dir()
    cmd = easy_install(tmp_dist,
                       args=["x"],
                       install_dir=install_dir,
                       exclude_scripts=True,
                       always_copy=False,
                       build_directory=None,
                       editable=False,
                       upgrade=False,
                       multi_version=True,
                       no_report=True,
                       user=False)
    cmd.ensure_finalized()
    return cmd.easy_install(req)
Beispiel #44
0
 def _build_egg_fetcher(self):
     """Build an egg fetcher that respects index_url and allow_hosts"""
     # modified from setuptools.dist:Distribution.fetch_build_egg
     from setuptools.command.easy_install import easy_install
     main_dist = self.distribution
     # construct a fake distribution to store the args for easy_install
     dist = main_dist.__class__({'script_args': ['easy_install']})
     dist.parse_config_files()
     opts = dist.get_option_dict('easy_install')
     keep = ('find_links', 'site_dirs', 'index_url', 'optimize',
             'site_dirs', 'allow_hosts')
     for key in opts.keys():
         if key not in keep:
             del opts[key]  # don't use any other settings
     if main_dist.dependency_links:
         links = main_dist.dependency_links[:]
         if 'find_links' in opts:
             links = opts['find_links'][1].split() + links
         opts['find_links'] = ('setup', links)
     if self.allow_hosts:
         opts['allow_hosts'] = ('test', self.allow_hosts)
     if self.index_url:
         opts['index_url'] = ('test', self.index_url)
     install_dir_func = getattr(dist, 'get_egg_cache_dir', _os.getcwd)
     install_dir = install_dir_func()
     cmd = easy_install(dist,
                        args=["x"],
                        install_dir=install_dir,
                        exclude_scripts=True,
                        always_copy=False,
                        build_directory=None,
                        editable=False,
                        upgrade=False,
                        multi_version=True,
                        no_report=True)
     cmd.ensure_finalized()
     main_dist._egg_fetcher = cmd
Beispiel #45
0
    def fetch_build_egg(self, req):
        """Fetch an egg needed for building"""

        try:
            cmd = self._egg_fetcher
            cmd.package_index.to_scan = []
        except AttributeError:
            from setuptools.command.easy_install import easy_install

            dist = self.__class__({'script_args': ['easy_install']})
            dist.parse_config_files()
            opts = dist.get_option_dict('easy_install')
            keep = ('find_links', 'site_dirs', 'index_url', 'optimize',
                    'site_dirs', 'allow_hosts')
            for key in list(opts):
                if key not in keep:
                    del opts[key]  # don't use any other settings
            if self.dependency_links:
                links = self.dependency_links[:]
                if 'find_links' in opts:
                    links = opts['find_links'][1].split() + links
                opts['find_links'] = ('setup', links)
            install_dir = self.get_egg_cache_dir()
            cmd = easy_install(dist,
                               args=["x"],
                               install_dir=install_dir,
                               exclude_scripts=True,
                               always_copy=False,
                               build_directory=None,
                               editable=False,
                               upgrade=False,
                               multi_version=True,
                               no_report=True,
                               user=False)
            cmd.ensure_finalized()
            self._egg_fetcher = cmd
        return cmd.easy_install(req)
Beispiel #46
0
    babel.compile_catalog = None
    babel.extract_messages = None
    babel.init_catalog = None
    babel.update_catalog = None

from distutils.core import setup, Extension

from setuptools.command.easy_install import main as easy_install

# check the PIL is installed; since its package name isn't the same as
# the distribution name, setuptools can't manage it as a dependency
try:
    import Image
except ImportError:
    print "Installing the Python Imaging Library"
    easy_install(["http://effbot.org/downloads/Imaging-1.1.6.tar.gz"])

# same with the captcha library
try:
    import Captcha
except ImportError:
    print "Installing the PyCaptcha Module"
    easy_install(["http://svn.navi.cx/misc/trunk/pycaptcha"])

# unfortunately, we use an old version of sqlalchemy right now
try:
    import sqlalchemy
    vers = sqlalchemy.__version__
    assert vers == "0.3.10", \
           ("reddit is only compatible with SqlAlchemy 0.3.10 not '%s' " % vers)
except ImportError:
Beispiel #47
0
    babel.extract_messages = None
    babel.init_catalog = None
    babel.update_catalog = None

from distutils.core import setup, Extension

from setuptools.command.easy_install import main as easy_install
import os

# check the PIL is installed; since its package name isn't the same as
# the distribution name, setuptools can't manage it as a dependency
try:
    import Image
except ImportError:
    print "Installing the Python Imaging Library"
    easy_install(["http://effbot.org/downloads/Imaging-1.1.6.tar.gz"])

# same with the captcha library
try:
    import Captcha
except ImportError:
    print "Installing the PyCaptcha Module"
    easy_install(["http://svn.navi.cx/misc/trunk/pycaptcha"])
    
# ditto for pylons
try:
    import pylons
    vers = pylons.__version__
    assert vers.startswith('0.9.6.') or vers == '0.9.6', \
           ("reddit is only compatible with pylons 0.9.6, not '%s'" % vers)
except ImportError:
Beispiel #48
0
    babel.extract_messages = None
    babel.init_catalog = None
    babel.update_catalog = None

from distutils.core import setup, Extension

from setuptools.command.easy_install import main as easy_install
import os

# check the PIL is installed; since its package name isn't the same as
# the distribution name, setuptools can't manage it as a dependency
try:
    import Image
except ImportError:
    print "Installing the Python Imaging Library"
    easy_install(["http://effbot.org/downloads/Imaging-1.1.6.tar.gz"])

# same with the captcha library
try:
    import Captcha
except ImportError:
    print "Installing the PyCaptcha Module"
    easy_install(["http://svn.navi.cx/misc/trunk/pycaptcha"])

# ditto for pylons
try:
    import pylons
    vers = pylons.__version__
    assert vers.startswith('0.9.6.') or vers == '0.9.6', \
           ("reddit is only compatible with pylons 0.9.6, not '%s'" % vers)
except ImportError:
Beispiel #49
0
    babel.compile_catalog = None
    babel.extract_messages = None
    babel.init_catalog = None
    babel.update_catalog = None

from distutils.core import setup, Extension

from setuptools.command.easy_install import main as easy_install

# check the PIL is installed; since its package name isn't the same as
# the distribution name, setuptools can't manage it as a dependency
try:
    import Image
except ImportError:
    print "Installing the Python Imaging Library"
    easy_install(["http://effbot.org/downloads/Imaging-1.1.6.tar.gz"])

# same with the captcha library
try:
    import Captcha
except ImportError:
    print "Installing the PyCaptcha Module"
    easy_install(["http://svn.navi.cx/misc/trunk/pycaptcha"])

# unfortunately, we use an old version of sqlalchemy right now
try:
    import sqlalchemy

    vers = sqlalchemy.__version__
    assert vers == "0.3.10", "reddit is only compatible with SqlAlchemy 0.3.10 not '%s' " % vers
except ImportError:
Beispiel #50
0
            opts = dist.get_option_dict('easy_install')
            keep = (
                'find_links', 'site_dirs', 'index_url', 'optimize',
                'site_dirs', 'allow_hosts'
            )
            for key in list(opts):
                if key not in keep:
                    del opts[key]   # don't use any other settings
            if self.dependency_links:
                links = self.dependency_links[:]
                if 'find_links' in opts:
                    links = opts['find_links'][1].split() + links
                opts['find_links'] = ('setup', links)
<<<<<<< HEAD
            install_dir = self.get_egg_cache_dir()
            cmd = easy_install(
                dist, args=["x"], install_dir=install_dir, exclude_scripts=True,
=======
            cmd = easy_install(
                dist, args=["x"], install_dir=os.curdir, exclude_scripts=True,
>>>>>>> e4baf504ede925f4f1e07d823c9b20b3d0dbe14c
                always_copy=False, build_directory=None, editable=False,
                upgrade=False, multi_version=True, no_report=True, user=False
            )
            cmd.ensure_finalized()
            self._egg_fetcher = cmd
        return cmd.easy_install(req)

    def _set_global_opts_from_features(self):
        """Add --with-X/--without-X options based on optional features"""

        go = []