Commit 04efb577 authored by Lele Gaifax's avatar Lele Gaifax

Allow download-cache and eggs-directory to be relative paths

This implements additional suggestions on issue #171.
parent 3f85f61e
......@@ -10,6 +10,14 @@ Unreleased
- Add ``BUILDOUT_HOME`` as an alternate way to control how the user default
configuration is found.
- Treat ``download-cache`` and ``eggs-directory`` in a special manner:
a) they can be relative paths, relative to the location of the configuration
file that defines them
b) the can be in the form ``~/subdir``, with the usual convention that the
``~`` char means the home directory of the user executing the buildout
2.2.1 (2013-09-05)
==================
......
......@@ -253,6 +253,36 @@ class Buildout(DictMixin):
if k not in versions
))
# Absolutize some particular directory, handling also the ~/foo form,
# and considering the location of the configuration file that generated
# the setting as the base path, falling back to the main configuration
# file location
for name in ('download-cache', 'eggs-directory'):
if name in data['buildout']:
origdir, src = data['buildout'][name]
if '${' in origdir:
continue
if not os.path.isabs(origdir):
if src in ('DEFAULT_VALUE',
'COMPUTED_VALUE',
'COMMAND_LINE_VALUE'):
if 'directory' in data['buildout']:
basedir = data['buildout']['directory'][0]
else:
basedir = self._buildout_dir
else:
if _isurl(src):
raise zc.buildout.UserError(
'Setting "%s" to a non absolute location ("%s") '
'within a\n'
'remote configuration file ("%s") is ambiguous.' % (
name, origdir, src))
basedir = os.path.dirname(src)
absdir = os.path.expanduser(origdir)
if not os.path.isabs(absdir):
absdir = os.path.join(basedir, absdir)
data['buildout'][name] = (absdir, src)
self._annotated = copy.deepcopy(data)
self._raw = _unannotate(data)
self._data = {}
......
......@@ -810,7 +810,7 @@ COMMAND_LINE_VALUE).
DEFAULT_VALUE
directory= /sample-buildout
COMPUTED_VALUE
eggs-directory= eggs
eggs-directory= /sample-buildout/eggs
DEFAULT_VALUE
executable= ...
DEFAULT_VALUE
......
......@@ -46,7 +46,7 @@ download:
<a href="index/">index/</a><br>
<a href="other-1.0-py2.4.egg">other-1.0-py2.4.egg</a><br>
</body></html>
We'll enable logging on the link server so we can see what's going on:
......@@ -87,7 +87,7 @@ If we remove the installed eggs from eggs directory and re-run the buildout:
>>> for f in os.listdir('eggs'):
... if f.startswith('demo'):
... remove('eggs', f)
>>> print_(system(buildout), end='')
GET 200 /
Updating eggs.
......@@ -159,3 +159,58 @@ created, provided it is within an already existing directory::
>>> ls(cache)
d dist
d newdir
Using relative paths
--------------------
You can use a relative path for ``download-cache`` (the same logic is applied
to ``eggs-directory`` too) and in such case it is considered relative to the
location of the configuration file that sets its value.
As an example, we create a ``base.cfg`` configuration in a different directory::
>>> basedir = tmpdir('basecfg')
>>> write(basedir, 'base.cfg',
... '''
... [buildout]
... download-cache = cache
... ''')
and a ``buildout.cfg`` that extends from there::
>>> write('buildout.cfg',
... '''
... [buildout]
... extends = %(basedir)s/base.cfg
... parts =
... ''' % globals())
>>> dummy = system(buildout)
>>> ls(basedir)
- base.cfg
d cache
Of course this cannot be used when the base configuration is not on the local
filesystem because it wouldn't make any sense having a remote cache::
>>> server_data = tmpdir('server_data')
>>> server_url = start_server(server_data)
>>> cd(sample_buildout)
>>> write(server_data, 'base.cfg', """\
... [buildout]
... download-cache = cache
... """)
>>> write('buildout.cfg',
... '''
... [buildout]
... extends = %(server_url)s/base.cfg
... parts =
... ''' % globals())
>>> print_(system(buildout), end='') # doctest: +ELLIPSIS
While:
Initializing.
Error: Setting "download-cache" to a non absolute location ("cache") within a
remote configuration file...
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment