[Checkins] SVN: zc.buildout/trunk/src/zc/buildout/easy_install.
Added an option to install only from a download cache.
Jim Fulton
jim at zope.com
Mon Mar 19 09:00:22 EDT 2007
Log message for revision 73338:
Added an option to install only from a download cache.
Changed:
U zc.buildout/trunk/src/zc/buildout/easy_install.py
U zc.buildout/trunk/src/zc/buildout/easy_install.txt
-=-
Modified: zc.buildout/trunk/src/zc/buildout/easy_install.py
===================================================================
--- zc.buildout/trunk/src/zc/buildout/easy_install.py 2007-03-19 10:41:32 UTC (rev 73337)
+++ zc.buildout/trunk/src/zc/buildout/easy_install.py 2007-03-19 13:00:21 UTC (rev 73338)
@@ -104,11 +104,11 @@
'from setuptools.command.easy_install import main; main()'
)
-
class Installer:
_versions = {}
_download_cache = None
+ _install_from_cache = False
def __init__(self,
dest=None,
@@ -121,6 +121,14 @@
versions=None,
):
self._dest = dest
+
+ if self._install_from_cache:
+ if not self._download_cache:
+ raise ValueError("install_from_cache set to true with no"
+ " download cache")
+ links = ()
+ index = 'file://' + self._download_cache
+
self._links = links = list(links)
if self._download_cache and (self._download_cache not in links):
links.insert(0, self._download_cache)
@@ -453,7 +461,9 @@
# XXX Need test for this
for dist in dists:
- if dist.has_metadata('dependency_links.txt'):
+ if (dist.has_metadata('dependency_links.txt')
+ and not self._install_from_cache
+ ):
for link in dist.get_metadata_lines('dependency_links.txt'):
link = link.strip()
if link not in self._links:
@@ -625,7 +635,6 @@
if tmp != self._download_cache:
shutil.rmtree(tmp)
-
def default_versions(versions=None):
old = Installer._versions
if versions is not None:
@@ -635,9 +644,17 @@
def download_cache(path=-1):
old = Installer._download_cache
if path != -1:
+ if path:
+ path = os.path.abspath(path)
Installer._download_cache = path
return old
+def install_from_cache(setting=None):
+ old = Installer._install_from_cache
+ if setting is not None:
+ Installer._install_from_cache = bool(setting)
+ return old
+
def install(specs, dest,
links=(), index=None,
executable=sys.executable, always_unzip=False,
Modified: zc.buildout/trunk/src/zc/buildout/easy_install.txt
===================================================================
--- zc.buildout/trunk/src/zc/buildout/easy_install.txt 2007-03-19 10:41:32 UTC (rev 73337)
+++ zc.buildout/trunk/src/zc/buildout/easy_install.txt 2007-03-19 13:00:21 UTC (rev 73338)
@@ -919,7 +919,62 @@
Note that we didn't download the distributions from the link server.
+If we remove the restriction on demo, we'll download a newer version
+from the link server:
+
+ >>> ws = zc.buildout.easy_install.install(
+ ... ['demo'], dest,
+ ... links=[link_server], index=link_server+'index/',
+ ... always_unzip=True)
+ GET 200 /demo-0.3-py2.4.egg
+
+Normally, the download cache is the prefered source of downloads, but
+not the only one.
+
+Installing solely from a download cache
+
+A download cache can be used as the basis of application sources
+releases. In an application source release, we want to distribute an
+application that can be built without making any network accesses. In
+this case, we distribute a download cache and tell the easy_install
+module to install from the download cache only, without making network
+accesses. The install_from_cache function can be used to signal that
+packages should be installed only from the download cache. The
+function always returns the previous setting. Calling it with no
+arguments returns the current setting without changing it:
+
+ >>> zc.buildout.easy_install.install_from_cache()
+ False
+
+Calling it with a boolean value changes the setting and returns the
+previous setting:
+
+ >>> zc.buildout.easy_install.install_from_cache(True)
+ False
+
+Let's remove demo-0.3-py2.4.egg from the cache, clear the index cache,
+recreate the destination directory, and reinstall demo:
+
+ >>> remove(cache, 'demo-0.3-py2.4.egg')
+ >>> zc.buildout.easy_install.clear_index_cache()
+ >>> remove(dest)
+ >>> dest = tmpdir('sample-install')
+
+ >>> ws = zc.buildout.easy_install.install(
+ ... ['demo'], dest,
+ ... links=[link_server], index=link_server+'index/',
+ ... always_unzip=True)
+
+ >>> ls(dest)
+ d demo-0.2-py2.4.egg
+ d demoneeded-1.1-py2.4.egg
+
+This time, we didn't download from or even query the link server.
+
.. Disable the download cache:
>>> zc.buildout.easy_install.download_cache(None)
'/cache'
+
+ >>> zc.buildout.easy_install.install_from_cache(False)
+ True
More information about the Checkins
mailing list