[Checkins] SVN: zc.buildout/branches/help-api/zc.recipe.egg_/src/zc/recipe/egg/ Added a relative-paths option to generate egg paths relative to script

Godefroid Chapelle gotcha at bubblenet.be
Sun Mar 29 17:28:54 EDT 2009


Log message for revision 98573:
  Added a relative-paths option to generate egg paths relative to script
  locations when generating scripts.

Changed:
  U   zc.buildout/branches/help-api/zc.recipe.egg_/src/zc/recipe/egg/README.txt
  U   zc.buildout/branches/help-api/zc.recipe.egg_/src/zc/recipe/egg/egg.py

-=-
Modified: zc.buildout/branches/help-api/zc.recipe.egg_/src/zc/recipe/egg/README.txt
===================================================================
--- zc.buildout/branches/help-api/zc.recipe.egg_/src/zc/recipe/egg/README.txt	2009-03-29 21:28:47 UTC (rev 98572)
+++ zc.buildout/branches/help-api/zc.recipe.egg_/src/zc/recipe/egg/README.txt	2009-03-29 21:28:54 UTC (rev 98573)
@@ -166,6 +166,12 @@
 arguments
    Specify some arguments to be passed to entry points as Python source.
 
+relative-paths
+   If set to true, then egg paths will be generated relative to the
+   script path.  This allows a buildout to be moved without breaking
+   egg paths.  This option can be set in either the script section or
+   in the buildout section.
+
 Let's add an interpreter option:
 
     >>> write(sample_buildout, 'buildout.cfg',
@@ -356,7 +362,7 @@
     ... scripts = demo=foo
     ... extra-paths =
     ...    /foo/bar
-    ...    /spam/eggs
+    ...    ${buildout:directory}/spam
     ... """ % dict(server=link_server))
 
     >>> print system(buildout),
@@ -374,7 +380,7 @@
       '/sample-buildout/eggs/demo-0.4c1-py2.4.egg',
       '/sample-buildout/eggs/demoneeded-1.2c1-py2.4.egg',
       '/foo/bar',
-      '/spam/eggs',
+      '/sample-buildout/spam',
       ]
     <BLANKLINE>
     import eggrecipedemo
@@ -382,6 +388,114 @@
     if __name__ == '__main__':
         eggrecipedemo.main()
 
+Relative egg paths
+------------------
+
+If the relative-paths option is specified with a true value, then
+paths will be generated relative to the script. This is useful when
+you want to be able to move a buildout directory around without
+breaking scripts.
+
+    >>> write(sample_buildout, 'buildout.cfg',
+    ... """
+    ... [buildout]
+    ... parts = demo
+    ...
+    ... [demo]
+    ... recipe = zc.recipe.egg
+    ... find-links = %(server)s
+    ... index = %(server)s/index
+    ... scripts = demo=foo
+    ... relative-paths = true
+    ... extra-paths =
+    ...    /foo/bar
+    ...    ${buildout:directory}/spam
+    ... """ % dict(server=link_server))
+
+    >>> print system(buildout),
+    Uninstalling demo.
+    Installing demo.
+    Generated script '/sample-buildout/bin/foo'.
+
+Let's look at the script that was generated:
+
+    >>> cat(sample_buildout, 'bin', 'foo') # doctest: +NORMALIZE_WHITESPACE
+    #!/usr/local/bin/python2.4
+    <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
+    <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'),
+      '/foo/bar',
+      join(dirname(1, __file__), 'spam'),
+      ]
+    <BLANKLINE>
+    import eggrecipedemo
+    <BLANKLINE>
+    if __name__ == '__main__':
+        eggrecipedemo.main()
+
+You can specify relative paths in the buildout section, rather than in
+each individual script section:
+
+
+    >>> write(sample_buildout, 'buildout.cfg',
+    ... """
+    ... [buildout]
+    ... parts = demo
+    ... relative-paths = true
+    ...
+    ... [demo]
+    ... recipe = zc.recipe.egg
+    ... find-links = %(server)s
+    ... index = %(server)s/index
+    ... scripts = demo=foo
+    ... extra-paths =
+    ...    /foo/bar
+    ...    ${buildout:directory}/spam
+    ... """ % dict(server=link_server))
+
+    >>> print system(buildout),
+    Uninstalling demo.
+    Installing demo.
+    Generated script '/sample-buildout/bin/foo'.
+
+    >>> cat(sample_buildout, 'bin', 'foo') # doctest: +NORMALIZE_WHITESPACE
+    #!/usr/local/bin/python2.4
+    <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
+    <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'),
+      '/foo/bar',
+      join(dirname(1, __file__), 'spam'),
+      ]
+    <BLANKLINE>
+    import eggrecipedemo
+    <BLANKLINE>
+    if __name__ == '__main__':
+        eggrecipedemo.main()
+
 Specifying initialialization code and arguments
 -----------------------------------------------
 
@@ -402,7 +516,7 @@
     ... scripts = demo=foo
     ... extra-paths =
     ...    /foo/bar
-    ...    /spam/eggs
+    ...    ${buildout:directory}/spam
     ... initialization = a = (1, 2
     ...                       3, 4)
     ... arguments = a, 2
@@ -421,7 +535,7 @@
       '/sample-buildout/eggs/demo-0.4c1-py2.4.egg',
       '/sample-buildout/eggs/demoneeded-1.2c1-py2.4.egg',
       '/foo/bar',
-      '/spam/eggs',
+      '/sample-buildout/spam',
       ]
     <BLANKLINE>
     a = (1, 2
@@ -454,7 +568,7 @@
     ... index = %(server)s/index
     ... extra-paths =
     ...    /foo/bar
-    ...    /spam/eggs
+    ...    ${buildout:directory}/spam
     ... entry-points = alt=eggrecipedemo:alt other=foo.bar:a.b.c
     ... """ % dict(server=link_server))
 
@@ -479,7 +593,7 @@
       '/sample-buildout/eggs/demo-0.4c1-py2.4.egg',
       '/sample-buildout/eggs/demoneeded-1.2c1-py2.4.egg',
       '/foo/bar',
-      '/spam/eggs',
+      '/sample-buildout/spam',
       ]
     <BLANKLINE>
     import foo.bar

Modified: zc.buildout/branches/help-api/zc.recipe.egg_/src/zc/recipe/egg/egg.py
===================================================================
--- zc.buildout/branches/help-api/zc.recipe.egg_/src/zc/recipe/egg/egg.py	2009-03-29 21:28:47 UTC (rev 98572)
+++ zc.buildout/branches/help-api/zc.recipe.egg_/src/zc/recipe/egg/egg.py	2009-03-29 21:28:54 UTC (rev 98573)
@@ -49,7 +49,7 @@
         options['develop-eggs-directory'
                 ] = buildout['buildout']['develop-eggs-directory']
         options['_d'] = options['develop-eggs-directory'] # backward compat.
-        
+
         assert options.get('unzip') in ('true', 'false', None)
 
         python = options.get('python', buildout['buildout']['python'])
@@ -113,6 +113,18 @@
         if self.extra_paths:
             options['extra-paths'] = '\n'.join(self.extra_paths)
 
+
+        relative_paths = options.get(
+            'relative-paths', 
+            buildout['buildout'].get('relative-paths', 'false')
+            )
+        if relative_paths == 'true':
+            options['buildout-directory'] = buildout['buildout']['directory']
+            self._relative_paths = options['buildout-directory']
+        else:
+            self._relative_paths = ''
+            assert relative_paths == 'false'
+
     parse_entry_point = re.compile(
         '([^=]+)=(\w+(?:[.]\w+)*):(\w+(?:[.]\w+)*)$'
         ).match
@@ -154,6 +166,7 @@
                 interpreter=options.get('interpreter'),
                 initialization=options.get('initialization', ''),
                 arguments=options.get('arguments', ''),
+                relative_paths=self._relative_paths,
                 )
 
         return ()



More information about the Checkins mailing list