[Checkins] SVN: zc.buildout/branches/tarek-allow-host-option/ first
draft of allow-hosts option
Tarek Ziade
ziade.tarek at gmail.com
Sat Apr 5 03:20:06 EDT 2008
Log message for revision 85110:
first draft of allow-hosts option
Changed:
U zc.buildout/branches/tarek-allow-host-option/buildout.cfg
A zc.buildout/branches/tarek-allow-host-option/src/zc/buildout/allowhosts.txt
U zc.buildout/branches/tarek-allow-host-option/src/zc/buildout/buildout.py
U zc.buildout/branches/tarek-allow-host-option/src/zc/buildout/easy_install.py
U zc.buildout/branches/tarek-allow-host-option/src/zc/buildout/tests.py
U zc.buildout/branches/tarek-allow-host-option/zc.recipe.egg_/src/zc/recipe/egg/egg.py
-=-
Modified: zc.buildout/branches/tarek-allow-host-option/buildout.cfg
===================================================================
--- zc.buildout/branches/tarek-allow-host-option/buildout.cfg 2008-04-05 00:57:29 UTC (rev 85109)
+++ zc.buildout/branches/tarek-allow-host-option/buildout.cfg 2008-04-05 07:20:04 UTC (rev 85110)
@@ -1,10 +1,20 @@
[buildout]
develop = zc.recipe.egg_ .
parts =
- test2.3 py2.3 oltest2.3
test2.4 py2.4 oltest2.4
- test2.5 py2.5 oltest2.5
+#test2.5 py2.5 oltest2.5
+#test2.3 py2.3 oltest2.3
+
+[python2.3]
+executable = python2.3
+
+[python2.4]
+executable = bin/python2.4
+
+[python2.5]
+executable = python2.5
+
[py2.3]
recipe = zc.recipe.egg
eggs = zc.buildout
Added: zc.buildout/branches/tarek-allow-host-option/src/zc/buildout/allowhosts.txt
===================================================================
--- zc.buildout/branches/tarek-allow-host-option/src/zc/buildout/allowhosts.txt (rev 0)
+++ zc.buildout/branches/tarek-allow-host-option/src/zc/buildout/allowhosts.txt 2008-04-05 07:20:04 UTC (rev 85110)
@@ -0,0 +1,85 @@
+Allow hosts
+-----------
+
+
+On some environments the links visited by `zc.buildout` can be forbidden
+by paranoiac firewalls. These URL might be on the chain of links
+visited by `zc.buildout` wheter they are defined in the `find-links` option,
+wheter they are defined by various eggs in their `url`, `download_url`,
+`dependency_links` metadata.
+
+It is even harder to track that package_index works like a spider and
+might visit links and go to other location.
+
+The `allow-hosts` option provides a way to prevent this, and
+works exactly like the one provided in `easy_install`
+(see `easy_install allow-hosts option`_).
+
+You can provide a list of allowed host, together with wildcards::
+
+ [buildout]
+ ...
+
+ allow-hosts =
+ *.python.org
+ example.com
+
+Let's create a develop egg in our buildout that specifies
+`dependency_links` which points to a server in the outside world::
+
+ >>> mkdir(sample_buildout, 'allowdemo')
+ >>> write(sample_buildout, 'allowdemo', 'dependencydemo.py',
+ ... 'import eggrecipekss.core')
+ >>> write(sample_buildout, 'allowdemo', 'setup.py',
+ ... '''from setuptools import setup; setup(
+ ... name='allowdemo', py_modules=['dependencydemo'],
+ ... install_requires = 'kss.core',
+ ... dependency_links = ['http://dist.plone.org'],
+ ... zip_safe=True, version='1')
+ ... ''')
+
+Now let's configure the buildout to use the develop egg,
+together with some rules that disallow any website but PyPI and
+local files::
+
+ >>> write(sample_buildout, 'buildout.cfg',
+ ... '''
+ ... [buildout]
+ ... develop = allowdemo
+ ... parts = eggs
+ ... allow-hosts =
+ ... pypi.python.org
+ ...
+ ... [eggs]
+ ... recipe = zc.recipe.egg:eggs
+ ... eggs = allowdemo
+ ... ''')
+
+Now we can run the buildout and make sure all attempts to dist.plone.org fails::
+
+ >>> print system(buildout)
+ <BLANKLINE>
+ Link to file://.../setuptools/ ***BLOCKED*** by --allow-hosts
+ <BLANKLINE>
+ <BLANKLINE>
+ Link to file://.../ ***BLOCKED*** by --allow-hosts
+ <BLANKLINE>
+ Develop: '/sample-buildout/allowdemo'
+ Installing eggs.
+ <BLANKLINE>
+ Link to http://dist.plone.org ***BLOCKED*** by --allow-hosts
+ <BLANKLINE>
+ <BLANKLINE>
+ Link to file://.../kss.core/ ***BLOCKED*** by --allow-hosts
+ <BLANKLINE>
+ Couldn't find index page for 'kss.core' (maybe misspelled?)
+ <BLANKLINE>
+ Link to file://.../ ***BLOCKED*** by --allow-hosts
+ <BLANKLINE>
+ Getting distribution for 'kss.core'.
+ While:
+ Installing eggs.
+ Getting distribution for 'kss.core'.
+ Error: Couldn't find a distribution for 'kss.core'.
+ <BLANKLINE>
+
Property changes on: zc.buildout/branches/tarek-allow-host-option/src/zc/buildout/allowhosts.txt
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: zc.buildout/branches/tarek-allow-host-option/src/zc/buildout/buildout.py
===================================================================
--- zc.buildout/branches/tarek-allow-host-option/src/zc/buildout/buildout.py 2008-04-05 00:57:29 UTC (rev 85109)
+++ zc.buildout/branches/tarek-allow-host-option/src/zc/buildout/buildout.py 2008-04-05 07:20:04 UTC (rev 85110)
@@ -128,6 +128,10 @@
links = options.get('find-links', '')
self._links = links and links.split() or ()
+
+ allow_hosts = options.get('allow-hosts', '*').split('\n')
+ self._allow_hosts = tuple([host.strip() for host in allow_hosts
+ if host.strip() != ''])
self._buildout_dir = options['directory']
for name in ('bin', 'parts', 'eggs', 'develop-eggs'):
@@ -657,7 +661,8 @@
self['buildout']['eggs-directory'],
links = self['buildout'].get('find-links', '').split(),
index = self['buildout'].get('index'),
- path = [self['buildout']['develop-eggs-directory']]
+ path = [self['buildout']['develop-eggs-directory']],
+ allow_hosts = self._allow_hosts
)
upgraded = []
@@ -735,7 +740,7 @@
working_set=pkg_resources.working_set,
links = self['buildout'].get('find-links', '').split(),
index = self['buildout'].get('index'),
- newest=self.newest)
+ newest=self.newest, allow_hosts=self._allow_hosts)
# Clear cache because extensions might now let us read pages we
# couldn't read before.
@@ -828,6 +833,7 @@
path=path,
working_set=pkg_resources.working_set,
newest=buildout.newest,
+ allow_hosts=buildout._allow_hosts
)
__doing__ = 'Loading %s recipe entry %s:%s.', group, spec, entry
Modified: zc.buildout/branches/tarek-allow-host-option/src/zc/buildout/easy_install.py
===================================================================
--- zc.buildout/branches/tarek-allow-host-option/src/zc/buildout/easy_install.py 2008-04-05 00:57:29 UTC (rev 85109)
+++ zc.buildout/branches/tarek-allow-host-option/src/zc/buildout/easy_install.py 2008-04-05 07:20:04 UTC (rev 85110)
@@ -72,7 +72,7 @@
return version
_indexes = {}
-def _get_index(executable, index_url, find_links):
+def _get_index(executable, index_url, find_links, allow_hosts=('*',)):
key = executable, index_url, tuple(find_links)
index = _indexes.get(key)
if index is not None:
@@ -80,11 +80,11 @@
if index_url is None:
index_url = default_index_url
-
index = setuptools.package_index.PackageIndex(
- index_url, python=_get_version(executable)
+ index_url, hosts=allow_hosts, python=_get_version(executable)
)
+ index._l = allow_hosts
if find_links:
index.add_find_links(find_links)
@@ -124,8 +124,10 @@
newest=True,
versions=None,
use_dependency_links=None,
+ allow_hosts=('*',)
):
self._dest = dest
+ self._allow_hosts = allow_hosts
if self._install_from_cache:
if not self._download_cache:
@@ -152,7 +154,7 @@
self._newest = newest
self._env = pkg_resources.Environment(path,
python=_get_version(executable))
- self._index = _get_index(executable, index, links)
+ self._index = _get_index(executable, index, links, self._allow_hosts)
if versions is not None:
self._versions = versions
@@ -162,9 +164,9 @@
if not dists:
logger.debug('We have no distributions for %s that satisfies %r.',
req.project_name, str(req))
+
return None, self._obtain(req, source)
-
# Note that dists are sorted from best to worst, as promised by
# env.__getitem__
@@ -345,9 +347,9 @@
shutil.rmtree(tmp)
def _obtain(self, requirement, source=None):
-
# initialize out index for this project:
index = self._index
+
if index.obtain(requirement) is None:
# Nothing is available.
return None
@@ -425,7 +427,7 @@
# Maybe an existing dist is already the best dist that satisfies the
# requirement
dist, avail = self._satisfied(requirement)
-
+
if dist is None:
if self._dest is not None:
logger.info(*__doing__)
@@ -514,7 +516,8 @@
logger.debug('Adding find link %r from %s', link, dist)
self._links.append(link)
self._index = _get_index(self._executable,
- self._index_url, self._links)
+ self._index_url, self._links,
+ self._allow_hosts)
for dist in dists:
# Check whether we picked a version and, if we did, report it:
@@ -729,18 +732,19 @@
links=(), index=None,
executable=sys.executable, always_unzip=False,
path=None, working_set=None, newest=True, versions=None,
- use_dependency_links=None):
+ use_dependency_links=None, allow_hosts=('*',)):
installer = Installer(dest, links, index, executable, always_unzip, path,
- newest, versions, use_dependency_links)
+ newest, versions, use_dependency_links,
+ allow_hosts=allow_hosts)
return installer.install(specs, working_set)
def build(spec, dest, build_ext,
links=(), index=None,
executable=sys.executable,
- path=None, newest=True, versions=None):
+ path=None, newest=True, versions=None, allow_hosts=('*',)):
installer = Installer(dest, links, index, executable, True, path, newest,
- versions)
+ versions, allow_hosts=allow_hosts)
return installer.build(spec, build_ext)
Modified: zc.buildout/branches/tarek-allow-host-option/src/zc/buildout/tests.py
===================================================================
--- zc.buildout/branches/tarek-allow-host-option/src/zc/buildout/tests.py 2008-04-05 00:57:29 UTC (rev 85109)
+++ zc.buildout/branches/tarek-allow-host-option/src/zc/buildout/tests.py 2008-04-05 07:20:04 UTC (rev 85110)
@@ -2655,6 +2655,7 @@
doctest.DocFileSuite(
'easy_install.txt', 'downloadcache.txt', 'dependencylinks.txt',
+ 'allowhosts.txt',
setUp=easy_install_SetUp,
tearDown=zc.buildout.testing.buildoutTearDown,
Modified: zc.buildout/branches/tarek-allow-host-option/zc.recipe.egg_/src/zc/recipe/egg/egg.py
===================================================================
--- zc.buildout/branches/tarek-allow-host-option/zc.recipe.egg_/src/zc/recipe/egg/egg.py 2008-04-05 00:57:29 UTC (rev 85109)
+++ zc.buildout/branches/tarek-allow-host-option/zc.recipe.egg_/src/zc/recipe/egg/egg.py 2008-04-05 07:20:04 UTC (rev 85110)
@@ -39,6 +39,11 @@
options['index'] = index
self.index = index
+ allow_hosts = buildout['buildout'].get('allow-hosts', '*')
+ allow_hosts = tuple([host.strip() for host in allow_hosts.split('\n')
+ if host.strip()!=''])
+ self.allow_hosts = allow_hosts
+
options['eggs-directory'] = buildout['buildout']['eggs-directory']
options['_e'] = options['eggs-directory'] # backward compat.
options['develop-eggs-directory'
@@ -78,6 +83,7 @@
always_unzip=options.get('unzip') == 'true',
path=[options['develop-eggs-directory']],
newest=self.buildout['buildout'].get('newest') == 'true',
+ allow_hosts=self.allow_hosts
)
return orig_distributions, ws
More information about the Checkins
mailing list