[Checkins] SVN: zc.buildout/trunk/ Refactored generation of relative egg paths to generate simpler code.

Jim Fulton jim at zope.com
Wed Mar 18 10:56:44 EDT 2009


Log message for revision 98239:
  Refactored generation of relative egg paths to generate simpler code.
  

Changed:
  U   zc.buildout/trunk/CHANGES.txt
  U   zc.buildout/trunk/src/zc/buildout/easy_install.py
  U   zc.buildout/trunk/src/zc/buildout/easy_install.txt
  U   zc.buildout/trunk/zc.recipe.egg_/CHANGES.txt
  U   zc.buildout/trunk/zc.recipe.egg_/src/zc/recipe/egg/README.txt

-=-
Modified: zc.buildout/trunk/CHANGES.txt
===================================================================
--- zc.buildout/trunk/CHANGES.txt	2009-03-18 14:33:44 UTC (rev 98238)
+++ zc.buildout/trunk/CHANGES.txt	2009-03-18 14:56:44 UTC (rev 98239)
@@ -4,6 +4,11 @@
 Change History
 **************
 
+1.2.1 (2009-03-18)
+==================
+
+- Refactored generation of relative egg paths to generate simpler code.
+
 1.2.0 (2009-03-17)
 ==================
 

Modified: zc.buildout/trunk/src/zc/buildout/easy_install.py
===================================================================
--- zc.buildout/trunk/src/zc/buildout/easy_install.py	2009-03-18 14:33:44 UTC (rev 98238)
+++ zc.buildout/trunk/src/zc/buildout/easy_install.py	2009-03-18 14:56:44 UTC (rev 98239)
@@ -973,6 +973,8 @@
              for path_item in path]
             )
         rpsetup = relative_paths_setup
+        for i in range(_relative_depth(relative_paths, sname)):
+            rpsetup += "base = os.path.dirname(base)\n"
     else:
         spath = repr(path)[1:-1].replace(', ', ',\n  ')
         rpsetup = ''
@@ -1011,9 +1013,7 @@
     if (common == relative_paths or
         common.startswith(os.path.join(relative_paths, ''))
         ):
-        return "join(dirname(%s, __file__), %r)" % (
-            _relative_depth(common, script), _relative_path(common, path)
-            )
+        return "join(base, %r)" % _relative_path(common, path)
     else:
         return repr(path)
 
@@ -1021,13 +1021,8 @@
 relative_paths_setup = """
 import os
 
-def dirname(n, path):
-    while n >= 0:
-        n -= 1
-        path = os.path.dirname(path)
-    return path
-
 join = os.path.join
+base = os.path.dirname(__file__)
 """
 
 def _script(module_name, attrs, path, dest, executable, arguments,
@@ -1124,7 +1119,6 @@
 
 py_script_template = script_header + '''\
 
-
 %(relative_paths_setup)s
 import sys
 

Modified: zc.buildout/trunk/src/zc/buildout/easy_install.txt
===================================================================
--- zc.buildout/trunk/src/zc/buildout/easy_install.txt	2009-03-18 14:33:44 UTC (rev 98238)
+++ zc.buildout/trunk/src/zc/buildout/easy_install.txt	2009-03-18 14:56:44 UTC (rev 98239)
@@ -814,20 +814,16 @@
     <BLANKLINE>
     import os
     <BLANKLINE>
-    def dirname(n, path):
-        while n >= 0:
-            n -= 1
-            path = os.path.dirname(path)
-        return path
-    <BLANKLINE>
     join = os.path.join
+    base = os.path.dirname(__file__)
+    base = os.path.dirname(base)
     <BLANKLINE>
     import sys
     sys.path[0:0] = [
-      join(dirname(1, __file__), 'eggs/demo-0.3-py2.4.egg'),
-      join(dirname(1, __file__), 'eggs/demoneeded-1.1-py2.4.egg'),
+      join(base, 'eggs/demo-0.3-pyN.N.egg'),
+      join(base, 'eggs/demoneeded-1.1-pyN.N.egg'),
       '/foo',
-      join(dirname(1, __file__), 'bar'),
+      join(base, 'bar'),
       ]
     <BLANKLINE>
     import eggrecipedemo
@@ -848,24 +844,19 @@
     >>> cat(bo, 'bin', 'py')
     #!/usr/local/bin/python2.4
     <BLANKLINE>
-    <BLANKLINE>
     import os
     <BLANKLINE>
-    def dirname(n, path):
-        while n >= 0:
-            n -= 1
-            path = os.path.dirname(path)
-        return path
-    <BLANKLINE>
     join = os.path.join
+    base = os.path.dirname(__file__)
+    base = os.path.dirname(base)
     <BLANKLINE>
     import sys
     <BLANKLINE>
     sys.path[0:0] = [
-      join(dirname(1, __file__), 'eggs/demo-0.3-py2.4.egg'),
-      join(dirname(1, __file__), 'eggs/demoneeded-1.1-py2.4.egg'),
+      join(base, 'eggs/demo-0.3-pyN.N.egg'),
+      join(base, 'eggs/demoneeded-1.1-pyN.N.egg'),
       '/foo',
-      join(dirname(1, __file__), 'bar'),
+      join(base, 'bar'),
       ]
     <BLANKLINE>
     _interactive = True

Modified: zc.buildout/trunk/zc.recipe.egg_/CHANGES.txt
===================================================================
--- zc.buildout/trunk/zc.recipe.egg_/CHANGES.txt	2009-03-18 14:33:44 UTC (rev 98238)
+++ zc.buildout/trunk/zc.recipe.egg_/CHANGES.txt	2009-03-18 14:56:44 UTC (rev 98239)
@@ -1,6 +1,11 @@
 Change History
 **************
 
+1.2.1 (2009-03-18)
+==================
+
+- Refactored generation of relative egg paths to generate simpler code.
+
 1.2.0 (2009-03-17)
 ==================
 

Modified: zc.buildout/trunk/zc.recipe.egg_/src/zc/recipe/egg/README.txt
===================================================================
--- zc.buildout/trunk/zc.recipe.egg_/src/zc/recipe/egg/README.txt	2009-03-18 14:33:44 UTC (rev 98238)
+++ zc.buildout/trunk/zc.recipe.egg_/src/zc/recipe/egg/README.txt	2009-03-18 14:56:44 UTC (rev 98239)
@@ -424,20 +424,16 @@
     <BLANKLINE>
     import os
     <BLANKLINE>
-    def dirname(n, path):
-        while n >= 0:
-            n -= 1
-            path = os.path.dirname(path)
-        return path
-    <BLANKLINE>
     join = os.path.join
+    base = os.path.dirname(__file__)
+    base = os.path.dirname(base)
     <BLANKLINE>
     import sys
     sys.path[0:0] = [
-      join(dirname(1, __file__), 'eggs/demo-0.4c1-py2.4.egg'),
-      join(dirname(1, __file__), 'eggs/demoneeded-1.2c1-py2.4.egg'),
+      join(base, 'eggs/demo-0.4c1-pyN.N.egg'),
+      join(base, 'eggs/demoneeded-1.2c1-pyN.N.egg'),
       '/foo/bar',
-      join(dirname(1, __file__), 'spam'),
+      join(base, 'spam'),
       ]
     <BLANKLINE>
     import eggrecipedemo
@@ -475,20 +471,16 @@
     <BLANKLINE>
     import os
     <BLANKLINE>
-    def dirname(n, path):
-        while n >= 0:
-            n -= 1
-            path = os.path.dirname(path)
-        return path
-    <BLANKLINE>
     join = os.path.join
+    base = os.path.dirname(__file__)
+    base = os.path.dirname(base)
     <BLANKLINE>
     import sys
     sys.path[0:0] = [
-      join(dirname(1, __file__), 'eggs/demo-0.4c1-py2.4.egg'),
-      join(dirname(1, __file__), 'eggs/demoneeded-1.2c1-py2.4.egg'),
+      join(base, 'eggs/demo-0.4c1-pyN.N.egg'),
+      join(base, 'eggs/demoneeded-1.2c1-pyN.N.egg'),
       '/foo/bar',
-      join(dirname(1, __file__), 'spam'),
+      join(base, 'spam'),
       ]
     <BLANKLINE>
     import eggrecipedemo



More information about the Checkins mailing list