[Checkins] SVN: zc.buildout/branches/prefer-final/ r96851@Avalon: jim | 2007-07-08 09:36:40 -0400

Jim Fulton jim at zope.com
Tue Jul 10 07:25:08 EDT 2007


Log message for revision 77673:
   r96851 at Avalon:  jim | 2007-07-08 09:36:40 -0400
   Implemented a policy of prefering final distributions with a
   python-level option to turn it off.
   
  

Changed:
  _U  zc.buildout/branches/prefer-final/
  D   zc.buildout/branches/prefer-final/src/
  A   zc.buildout/branches/prefer-final/src/
  U   zc.buildout/branches/prefer-final/src/zc/buildout/downloadcache.txt
  U   zc.buildout/branches/prefer-final/src/zc/buildout/easy_install.py
  U   zc.buildout/branches/prefer-final/src/zc/buildout/easy_install.txt
  U   zc.buildout/branches/prefer-final/src/zc/buildout/tests.py
  D   zc.buildout/branches/prefer-final/zc.recipe.egg_/
  A   zc.buildout/branches/prefer-final/zc.recipe.egg_/
  U   zc.buildout/branches/prefer-final/zc.recipe.egg_/src/zc/recipe/egg/README.txt

-=-

Property changes on: zc.buildout/branches/prefer-final
___________________________________________________________________
Name: svk:merge
   + 62d5b8a3-27da-0310-9561-8e5933582275:/zc.buildout/trunk:77455
c0866d8a-16ff-402e-90a7-1844f7e98520:/prefer-final:96851

Copied: zc.buildout/branches/prefer-final/src (from rev 77486, zc.buildout/branches/prefer-final/src)

Modified: zc.buildout/branches/prefer-final/src/zc/buildout/downloadcache.txt
===================================================================
--- zc.buildout/branches/prefer-final/src/zc/buildout/downloadcache.txt	2007-07-05 21:46:36 UTC (rev 77486)
+++ zc.buildout/branches/prefer-final/src/zc/buildout/downloadcache.txt	2007-07-10 11:25:08 UTC (rev 77673)
@@ -36,8 +36,10 @@
     <a href="demo-0.1-py2.4.egg">demo-0.1-py2.4.egg</a><br>
     <a href="demo-0.2-py2.4.egg">demo-0.2-py2.4.egg</a><br>
     <a href="demo-0.3-py2.4.egg">demo-0.3-py2.4.egg</a><br>
+    <a href="demo-0.4c1-py2.4.egg">demo-0.4c1-py2.4.egg</a><br>
     <a href="demoneeded-1.0.zip">demoneeded-1.0.zip</a><br>
     <a href="demoneeded-1.1.zip">demoneeded-1.1.zip</a><br>
+    <a href="demoneeded-1.2c1.zip">demoneeded-1.2c1.zip</a><br>
     <a href="extdemo-1.4.zip">extdemo-1.4.zip</a><br>
     <a href="index/">index/</a><br>
     <a href="other-1.0-py2.4.egg">other-1.0-py2.4.egg</a><br>

Modified: zc.buildout/branches/prefer-final/src/zc/buildout/easy_install.py
===================================================================
--- zc.buildout/branches/prefer-final/src/zc/buildout/easy_install.py	2007-07-05 21:46:36 UTC (rev 77486)
+++ zc.buildout/branches/prefer-final/src/zc/buildout/easy_install.py	2007-07-10 11:25:08 UTC (rev 77673)
@@ -116,6 +116,7 @@
     _versions = {}
     _download_cache = None
     _install_from_cache = False
+    _prefer_final = True
 
     def __init__(self,
                  dest=None,
@@ -166,6 +167,7 @@
                          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__
 
@@ -174,12 +176,6 @@
                 logger.debug('We have a develop egg: %s', dist)
                 return dist, None
 
-        if not self._newest:
-            # We don't need the newest, so we'll use the newest one we
-            # find, which is the first returned by
-            # Environment.__getitem__.
-            return dists[0], None
-
         # Special common case, we have a specification for a single version:
         specs = req.specs
         if len(specs) == 1 and specs[0][0] == '==':
@@ -187,6 +183,20 @@
                          str(req))
             return dists[0], None
 
+        if self._prefer_final:
+            fdists = [dist for dist in dists
+                      if _final_version(dist.parsed_version)
+                      ]
+            if fdists:
+                # There are final dists, so only use those
+                dists = fdists
+
+        if not self._newest:
+            # We don't need the newest, so we'll use the newest one we
+            # find, which is the first returned by
+            # Environment.__getitem__.
+            return dists[0], None
+
         best_we_have = dists[0] # Because dists are sorted from best to worst
 
         # We have some installed distros.  There might, theoretically, be
@@ -209,7 +219,14 @@
             return best_we_have, None
         else:
             # Let's find out if we already have the best available:
-            if best_we_have.parsed_version >= best_available.parsed_version:
+            if ((best_we_have.parsed_version >= best_available.parsed_version)
+                or
+                (self._prefer_final
+                 and
+                 _final_version(best_we_have.parsed_version)
+                 and not _final_version(best_available.parsed_version)
+                 )
+                ):
                 # Yup. Use it.
                 logger.debug(
                     'We have the best distribution that satisfies %r.',
@@ -316,17 +333,37 @@
             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
-        
+
+        # Filter the available dists for the requirement and source flag
+        dists = [dist for dist in index[requirement.project_name]
+                 if ((dist in requirement)
+                     and
+                     ((not source) or
+                      (dist.precedence == pkg_resources.SOURCE_DIST)
+                      )
+                     )
+                 ]
+
+        # If we prefer final dists, filter for final and use the
+        # result if it is non empty.
+        if self._prefer_final:
+            fdists = [dist for dist in dists
+                      if _final_version(dist.parsed_version)
+                      ]
+            if fdists:
+                # There are final dists, so only use those
+                dists = fdists
+
+        # Now find the best one:
         best = []
         bestv = ()
-        for dist in index[requirement.project_name]:
-            if dist not in requirement:
-                continue
-            if source and dist.precedence != pkg_resources.SOURCE_DIST:
-                continue
+        for dist in dists:
             distv = dist.parsed_version
             if distv > bestv:
                 best = [dist]
@@ -647,6 +684,12 @@
         Installer._install_from_cache = bool(setting)
     return old
 
+def prefer_final(setting=None):
+    old = Installer._prefer_final
+    if setting is not None:
+        Installer._prefer_final = bool(setting)
+    return old
+
 def install(specs, dest,
             links=(), index=None,
             executable=sys.executable, always_unzip=False,
@@ -976,5 +1019,9 @@
                 link += '/'
         yield link
 
-
-
+_final_parts = '*final-', '*final'
+def _final_version(parsed_version):
+    for part in parsed_version:
+        if (part[:1] == '*') and (part not in _final_parts):
+            return False
+    return True

Modified: zc.buildout/branches/prefer-final/src/zc/buildout/easy_install.txt
===================================================================
--- zc.buildout/branches/prefer-final/src/zc/buildout/easy_install.txt	2007-07-05 21:46:36 UTC (rev 77486)
+++ zc.buildout/branches/prefer-final/src/zc/buildout/easy_install.txt	2007-07-10 11:25:08 UTC (rev 77673)
@@ -93,8 +93,10 @@
     <a href="demo-0.1-py2.4.egg">demo-0.1-py2.4.egg</a><br>
     <a href="demo-0.2-py2.4.egg">demo-0.2-py2.4.egg</a><br>
     <a href="demo-0.3-py2.4.egg">demo-0.3-py2.4.egg</a><br>
+    <a href="demo-0.4c1-py2.4.egg">demo-0.4c1-py2.4.egg</a><br>
     <a href="demoneeded-1.0.zip">demoneeded-1.0.zip</a><br>
     <a href="demoneeded-1.1.zip">demoneeded-1.1.zip</a><br>
+    <a href="demoneeded-1.2c1.zip">demoneeded-1.2c1.zip</a><br>
     <a href="extdemo-1.4.zip">extdemo-1.4.zip</a><br>
     <a href="index/">index/</a><br>
     <a href="other-1.0-py2.4.egg">other-1.0-py2.4.egg</a><br>
@@ -120,6 +122,8 @@
     demo 0.2
     demoneeded 1.1
 
+We got demoneeded because it was a dependency of demo.
+
 And the actual eggs were added to the eggs directory.
 
     >>> ls(dest)
@@ -127,7 +131,7 @@
     -  demoneeded-1.1-py2.4.egg
 
 If we remove the version restriction on demo, but specify a false
-value for newest, no new didstributions will be installed:
+value for newest, no new distributions will be installed:
 
     >>> ws = zc.buildout.easy_install.install(
     ...     ['demo'], dest, links=[link_server], index=link_server+'index/',
@@ -145,6 +149,36 @@
     -  demo-0.3-py2.4.egg
     -  demoneeded-1.1-py2.4.egg
 
+Note that we didn't get the newest versions available.  There were
+release candidated for newer versions of both packages. By default,
+final releases are prefered.  We can change this behavior using the
+prefer_final function:
+
+    >>> zc.buildout.easy_install.prefer_final(False)
+    True
+
+The old setting is returned.
+
+    >>> ws = zc.buildout.easy_install.install(
+    ...     ['demo'], dest, links=[link_server], index=link_server+'index/')
+    >>> for dist in ws:
+    ...     print dist
+    demo 0.4c1
+    demoneeded 1.2c1
+
+    >>> ls(dest)
+    -  demo-0.2-py2.4.egg
+    -  demo-0.3-py2.4.egg
+    -  demo-0.4c1-py2.4.egg
+    -  demoneeded-1.1-py2.4.egg
+    -  demoneeded-1.2c1-py2.4.egg
+
+Let's put the setting back to the default.
+
+    >>> zc.buildout.easy_install.prefer_final(True)
+    False
+
+
 We can supply additional distributions.  We can also supply
 specifications for distributions that would normally be found via
 dependencies.  We might do this to specify a sprcific version.
@@ -162,8 +196,10 @@
     >>> ls(dest)
     -  demo-0.2-py2.4.egg
     -  demo-0.3-py2.4.egg
+    -  demo-0.4c1-py2.4.egg
     -  demoneeded-1.0-py2.4.egg
     -  demoneeded-1.1-py2.4.egg
+    -  demoneeded-1.2c1-py2.4.egg
     d  other-1.0-py2.4.egg
 
 We can request that eggs be unzipped even if they are zip safe.  This
@@ -685,8 +721,10 @@
     <a href="demo-0.1-py2.4.egg">demo-0.1-py2.4.egg</a><br>
     <a href="demo-0.2-py2.4.egg">demo-0.2-py2.4.egg</a><br>
     <a href="demo-0.3-py2.4.egg">demo-0.3-py2.4.egg</a><br>
+    <a href="demo-0.4c1-py2.4.egg">demo-0.4c1-py2.4.egg</a><br>
     <a href="demoneeded-1.0.zip">demoneeded-1.0.zip</a><br>
     <a href="demoneeded-1.1.zip">demoneeded-1.1.zip</a><br>
+    <a href="demoneeded-1.2c1.zip">demoneeded-1.2c1.zip</a><br>
     <a href="extdemo-1.4.zip">extdemo-1.4.zip</a><br>
     <a href="extdemo-1.5.zip">extdemo-1.5.zip</a><br>
     <a href="index/">index/</a><br>

Modified: zc.buildout/branches/prefer-final/src/zc/buildout/tests.py
===================================================================
--- zc.buildout/branches/prefer-final/src/zc/buildout/tests.py	2007-07-05 21:46:36 UTC (rev 77486)
+++ zc.buildout/branches/prefer-final/src/zc/buildout/tests.py	2007-07-10 11:25:08 UTC (rev 77673)
@@ -2073,6 +2073,25 @@
     
     """
 
+# XXX Tests needed:
+
+# Link added from package meta data
+
+# prefer final:
+#  - no existing and newer dev available
+#  - no existing and only dev available
+#  - final existing and only dev acailable
+#  - final existing and newer final available
+#  - final existing and same final available
+#  - final existing and older final available
+#  - only dev existing and final available
+#  - only dev existing and no final available newer dev available
+#  - only dev existing and no final available older dev available
+#  - only dev existing and no final available same dev available
+# Maybe same variations for non-prefer-final case.
+# Looks like a job for something fit like.
+
+
 ######################################################################
     
 def create_sample_eggs(test, executable=sys.executable):
@@ -2082,15 +2101,16 @@
     try:
         write(tmp, 'README.txt', '')
 
-        for i in (0, 1):
+        for i in (0, 1, 2):
             write(tmp, 'eggrecipedemobeeded.py', 'y=%s\n' % i)
+            c1 = i==2 and 'c1' or ''
             write(
                 tmp, 'setup.py',
                 "from setuptools import setup\n"
                 "setup(name='demoneeded', py_modules=['eggrecipedemobeeded'],"
-                " zip_safe=True, version='1.%s', author='bob', url='bob', "
+                " zip_safe=True, version='1.%s%s', author='bob', url='bob', "
                 "author_email='bob')\n"
-                % i
+                % (i, c1)
                 )
             zc.buildout.testing.sdist(tmp, dest)
 
@@ -2104,13 +2124,14 @@
 
         os.remove(os.path.join(tmp, 'eggrecipedemobeeded.py'))
 
-        for i in (1, 2, 3):
+        for i in (1, 2, 3, 4):
             write(
                 tmp, 'eggrecipedemo.py',
                 'import eggrecipedemobeeded\n'
                 'x=%s\n'
                 'def main(): print x, eggrecipedemobeeded.y\n'
                 % i)
+            c1 = i==4 and 'c1' or ''
             write(
                 tmp, 'setup.py',
                 "from setuptools import setup\n"
@@ -2118,7 +2139,7 @@
                 " install_requires = 'demoneeded',"
                 " entry_points={'console_scripts': "
                      "['demo = eggrecipedemo:main']},"
-                " zip_safe=True, version='0.%s')\n" % i
+                " zip_safe=True, version='0.%s%s')\n" % (i, c1)
                 )
             zc.buildout.testing.bdist_egg(tmp, executable, dest)
     finally:

Copied: zc.buildout/branches/prefer-final/zc.recipe.egg_ (from rev 77486, zc.buildout/branches/prefer-final/zc.recipe.egg_)

Modified: zc.buildout/branches/prefer-final/zc.recipe.egg_/src/zc/recipe/egg/README.txt
===================================================================
--- zc.buildout/branches/prefer-final/zc.recipe.egg_/src/zc/recipe/egg/README.txt	2007-07-05 21:46:36 UTC (rev 77486)
+++ zc.buildout/branches/prefer-final/zc.recipe.egg_/src/zc/recipe/egg/README.txt	2007-07-10 11:25:08 UTC (rev 77673)
@@ -36,8 +36,10 @@
     <a href="demo-0.1-py2.3.egg">demo-0.1-py2.3.egg</a><br>
     <a href="demo-0.2-py2.3.egg">demo-0.2-py2.3.egg</a><br>
     <a href="demo-0.3-py2.3.egg">demo-0.3-py2.3.egg</a><br>
+    <a href="demo-0.4c1-py2.3.egg">demo-0.4c1-py2.3.egg</a><br>
     <a href="demoneeded-1.0.zip">demoneeded-1.0.zip</a><br>
     <a href="demoneeded-1.1.zip">demoneeded-1.1.zip</a><br>
+    <a href="demoneeded-1.2c1.zip">demoneeded-1.2c1.zip</a><br>
     <a href="extdemo-1.4.zip">extdemo-1.4.zip</a><br>
     <a href="index/">index/</a><br>
     <a href="other-1.0-py2.3.egg">other-1.0-py2.3.egg</a><br>



More information about the Checkins mailing list