[Checkins] SVN: zc.zope3recipes/trunk/ Add support for relative paths buildout option.

Zvezdan Petkovic zvezdan at zope.com
Thu Oct 1 10:26:53 EDT 2009


Log message for revision 104681:
  Add support for relative paths buildout option.
  
  

Changed:
  U   zc.zope3recipes/trunk/README.txt
  U   zc.zope3recipes/trunk/setup.py
  U   zc.zope3recipes/trunk/zc/zope3recipes/README.txt
  U   zc.zope3recipes/trunk/zc/zope3recipes/recipes.py

-=-
Modified: zc.zope3recipes/trunk/README.txt
===================================================================
--- zc.zope3recipes/trunk/README.txt	2009-10-01 13:22:02 UTC (rev 104680)
+++ zc.zope3recipes/trunk/README.txt	2009-10-01 14:26:53 UTC (rev 104681)
@@ -18,9 +18,18 @@
 ********
 
 ===================
-0.10.0 (unreleased)
+0.11.0 (2009/10/01)
 ===================
 
+- Added support and tests for relative paths buildout option.
+- Changed the dependency requirements to >=1.2.0 for zc.buildout and
+  zc.recipe.egg because relative paths are added in these releases.
+- Added missing release date for the previous release (0.10.0).
+
+===================
+0.10.0 (2009/09/16)
+===================
+
 Removed support for creating a logrotate script for the access.log because it
 is not possible to reopen the log with ZDaemons ``reopen_transacript``. Note
 however that is is possible to declare ``when`` and ``interval`` in a logfile

Modified: zc.zope3recipes/trunk/setup.py
===================================================================
--- zc.zope3recipes/trunk/setup.py	2009-10-01 13:22:02 UTC (rev 104680)
+++ zc.zope3recipes/trunk/setup.py	2009-10-01 14:26:53 UTC (rev 104681)
@@ -29,10 +29,10 @@
     include_package_data = True,
     namespace_packages = ['zc'],
     install_requires = [
-        'zc.buildout',
+        'zc.buildout >=1.2.0',
         'zope.testing',
         'setuptools',
-        'zc.recipe.egg',
+        'zc.recipe.egg >=1.2.0',
         'ZConfig >=2.4a5'],
     entry_points = {
         'zc.buildout': [

Modified: zc.zope3recipes/trunk/zc/zope3recipes/README.txt
===================================================================
--- zc.zope3recipes/trunk/zc/zope3recipes/README.txt	2009-10-01 13:22:02 UTC (rev 104680)
+++ zc.zope3recipes/trunk/zc/zope3recipes/README.txt	2009-10-01 14:26:53 UTC (rev 104681)
@@ -120,6 +120,98 @@
     if __name__ == '__main__':
         zc.zope3recipes.debugzope.debug(main_module=zope.app.twisted.main)
 
+
+Relative paths
+--------------
+
+If requested in a buildout configuration, the scripts will be generated
+with relative paths instead of absolute.
+
+Let's change a buildout configuration to include ``relative-paths``.
+
+    >>> write('buildout.cfg',
+    ... '''
+    ... [buildout]
+    ... develop = demo1 demo2
+    ... parts = myapp
+    ... relative-paths = true
+    ...
+    ... [myapp]
+    ... recipe = zc.zope3recipes:application
+    ... site.zcml = <include package="demo2" />
+    ...             <principal
+    ...                 id="zope.manager"
+    ...                 title="Manager"
+    ...                 login="jim"
+    ...                 password_manager="SHA1"
+    ...                 password="40bd001563085fc35165329ea1ff5c5ecbdbbeef"
+    ...                 />
+    ...             <grant
+    ...                 role="zope.Manager"
+    ...                 principal="zope.manager"
+    ...                 />
+    ... eggs = demo2
+    ... ''' % globals())
+
+    >>> print system(join('bin', 'buildout')),
+    Develop: '/sample-buildout/demo1'
+    Develop: '/sample-buildout/demo2'
+    Uninstalling myapp.
+    Installing myapp.
+    Generated script '/sample-buildout/parts/myapp/runzope'.
+    Generated script '/sample-buildout/parts/myapp/debugzope'.
+
+We get runzope script with relative paths.
+
+    >>> cat('parts', 'myapp', 'runzope')
+    #!/usr/local/bin/python2.4
+    <BLANKLINE>
+    import os
+    <BLANKLINE>
+    join = os.path.join
+    base = os.path.dirname(os.path.abspath(os.path.realpath(__file__)))
+    base = os.path.dirname(base)
+    base = os.path.dirname(base)
+    <BLANKLINE>
+    import sys
+    sys.path[0:0] = [
+      join(base, 'demo2'),
+      join(base, 'demo1'),
+      ]
+    <BLANKLINE>
+    import zope.app.twisted.main
+    <BLANKLINE>
+    if __name__ == '__main__':
+        zope.app.twisted.main.main()
+
+Similarly, debugzope script has relative paths.
+
+    >>> cat('parts', 'myapp', 'debugzope')
+    #!/usr/local/bin/python2.4
+    <BLANKLINE>
+    import os
+    <BLANKLINE>
+    join = os.path.join
+    base = os.path.dirname(os.path.abspath(os.path.realpath(__file__)))
+    base = os.path.dirname(base)
+    base = os.path.dirname(base)
+    <BLANKLINE>
+    import sys
+    sys.path[0:0] = [
+      join(base, 'demo2'),
+      join(base, 'demo1'),
+      '/zope3recipes',
+      ]
+    <BLANKLINE>
+    import zope.app.twisted.main
+    <BLANKLINE>
+    <BLANKLINE>
+    import zc.zope3recipes.debugzope
+    <BLANKLINE>
+    if __name__ == '__main__':
+        zc.zope3recipes.debugzope.debug(main_module=zope.app.twisted.main)
+
+
 Building Zope 3 Applications (from Zope 3 checkouts/tarballs)
 =============================================================
 
@@ -416,6 +508,100 @@
         zc.zope3recipes.debugzope.debug(main_module=zope.app.server.main)
 
 
+Relative paths
+--------------
+
+We can also request relative paths.
+
+    >>> write('buildout.cfg',
+    ... '''
+    ... [buildout]
+    ... develop = demo1 demo2
+    ... parts = myapp
+    ... relative-paths = true
+    ...
+    ... [zope3]
+    ... location = %(zope3)s
+    ...
+    ... [myapp]
+    ... recipe = zc.zope3recipes:app
+    ... servers = zserver
+    ... site.zcml = <include package="demo2" />
+    ...             <principal
+    ...                 id="zope.manager"
+    ...                 title="Manager"
+    ...                 login="jim"
+    ...                 password_manager="SHA1"
+    ...                 password="40bd001563085fc35165329ea1ff5c5ecbdbbeef"
+    ...                 />
+    ...             <grant
+    ...                 role="zope.Manager"
+    ...                 principal="zope.manager"
+    ...                 />
+    ... eggs = demo2
+    ... ''' % globals())
+
+    >>> print system(join('bin', 'buildout')),
+    Develop: '/sample-buildout/demo1'
+    Develop: '/sample-buildout/demo2'
+    Uninstalling myapp.
+    Installing myapp.
+    Generated script '/sample-buildout/parts/myapp/runzope'.
+    Generated script '/sample-buildout/parts/myapp/debugzope'.
+
+The runzope script has relative paths.
+
+    >>> cat('parts', 'myapp', 'runzope')
+    #!/usr/local/bin/python2.4
+    <BLANKLINE>
+    import os
+    <BLANKLINE>
+    join = os.path.join
+    base = os.path.dirname(os.path.abspath(os.path.realpath(__file__)))
+    base = os.path.dirname(base)
+    base = os.path.dirname(base)
+    <BLANKLINE>
+    import sys
+    sys.path[0:0] = [
+      join(base, 'demo2'),
+      join(base, 'demo1'),
+      '/zope3/src',
+      ]
+    <BLANKLINE>
+    import zope.app.server.main
+    <BLANKLINE>
+    if __name__ == '__main__':
+        zope.app.server.main.main()
+
+The debugzope script also has relative paths.
+
+    >>> cat('parts', 'myapp', 'debugzope')
+    #!/usr/local/bin/python2.4
+    <BLANKLINE>
+    import os
+    <BLANKLINE>
+    join = os.path.join
+    base = os.path.dirname(os.path.abspath(os.path.realpath(__file__)))
+    base = os.path.dirname(base)
+    base = os.path.dirname(base)
+    <BLANKLINE>
+    import sys
+    sys.path[0:0] = [
+      join(base, 'demo2'),
+      join(base, 'demo1'),
+      '/zope3/src',
+      '/zope3recipes',
+      ]
+    <BLANKLINE>
+    import zope.app.server.main
+    <BLANKLINE>
+    <BLANKLINE>
+    import zc.zope3recipes.debugzope
+    <BLANKLINE>
+    if __name__ == '__main__':
+        zc.zope3recipes.debugzope.debug(main_module=zope.app.server.main)
+
+
 Legacy Functional Testing Support
 ---------------------------------
 
@@ -1880,3 +2066,88 @@
         path STDOUT
       </logfile>
     </eventlog>
+
+
+Relative paths
+--------------
+
+Relative paths will be used in the control script if they are requested
+in a buildout configuration.
+
+    >>> write('buildout.cfg',
+    ... '''
+    ... [buildout]
+    ... develop = demo1 demo2
+    ... parts = instance
+    ... relative-paths = true
+    ...
+    ... [zope3]
+    ... location = %(zope3)s
+    ...
+    ... [myapp]
+    ... recipe = zc.zope3recipes:app
+    ... site.zcml = <include package="demo2" />
+    ...             <principal
+    ...                 id="zope.manager"
+    ...                 title="Manager"
+    ...                 login="jim"
+    ...                 password_manager="SHA1"
+    ...                 password="40bd001563085fc35165329ea1ff5c5ecbdbbeef"
+    ...                 />
+    ...             <grant
+    ...                 role="zope.Manager"
+    ...                 principal="zope.manager"
+    ...                 />
+    ... eggs = demo2
+    ...
+    ... [instance]
+    ... recipe = zc.zope3recipes:instance
+    ... application = myapp
+    ... zope.conf = ${database:zconfig}
+    ...
+    ... [database]
+    ... recipe = zc.recipe.filestorage
+    ... ''' % globals())
+
+    >>> print system(join('bin', 'buildout')),
+    Develop: '/sample-buildout/demo1'
+    Develop: '/sample-buildout/demo2'
+    Uninstalling instance2.
+    Uninstalling instance.
+    Uninstalling myapp.
+    Updating database.
+    Installing myapp.
+    Generated script '/sample-buildout/parts/myapp/runzope'.
+    Generated script '/sample-buildout/parts/myapp/debugzope'.
+    Installing instance.
+    Generated script '/sample-buildout/bin/instance'.
+
+    Both ``sys.path`` and arguments to the `ctl` are using relative
+    paths now.
+
+    >>> cat('bin', 'instance')
+    #!/usr/local/bin/python2.4
+    <BLANKLINE>
+    import os
+    <BLANKLINE>
+    join = os.path.join
+    base = os.path.dirname(os.path.abspath(os.path.realpath(__file__)))
+    base = os.path.dirname(base)
+    <BLANKLINE>
+    import sys
+    sys.path[0:0] = [
+      join(base, 'eggs/zdaemon-pyN.N.egg'),
+      join(base, 'eggs/setuptools-pyN.N.egg'),
+      join(base, 'eggs/ZConfig-pyN.N.egg'),
+      '/zope3recipes',
+      ]
+    <BLANKLINE>
+    import zc.zope3recipes.ctl
+    <BLANKLINE>
+    if __name__ == '__main__':
+        zc.zope3recipes.ctl.main([
+            join(base, 'parts/myapp/debugzope'),
+            join(base, 'parts/instance/zope.conf'),
+            '-C', join(base, 'parts/instance/zdaemon.conf'),
+            ]+sys.argv[1:]
+            )

Modified: zc.zope3recipes/trunk/zc/zope3recipes/recipes.py
===================================================================
--- zc.zope3recipes/trunk/zc/zope3recipes/recipes.py	2009-10-01 13:22:02 UTC (rev 104680)
+++ zc.zope3recipes/trunk/zc/zope3recipes/recipes.py	2009-10-01 14:26:53 UTC (rev 104681)
@@ -79,6 +79,7 @@
                 [('runzope', server_module, 'main')],
                 ws, options['executable'], dest,
                 extra_paths = extra_paths.split(),
+                relative_paths=self.egg._relative_paths,
                 )
 
             options['extra-paths'] = extra_paths + '\n' + this_loc
@@ -91,6 +92,7 @@
                 extra_paths = options['extra-paths'].split(),
                 initialization = initialization,
                 arguments = arguments,
+                relative_paths=self.egg._relative_paths,
                 )
 
             ftesting_zcml = options.get('ftesting.zcml')
@@ -320,39 +322,68 @@
                 )
                 open(logrotate_path, 'w').write(logrotate_event_log)
 
+            # XXX: We are using a private zc.buildout.easy_install
+            # function below.  It would be better if self.egg had a
+            # method to install scripts.  All recipe options and
+            # relative path information would be available to the egg
+            # instance and the recipe would have no need to call
+            # zc.buildout.easy_install.scripts directly.  Since that
+            # requires changes to zc.recipe.egg/zc.buildout we are
+            # fixing our immediate need to generate correct relative
+            # paths by using the private API.
+            # This should be done "right" in the future.
+            if self.egg._relative_paths:
+                arg_paths = (
+                    os.path.join(app_loc, 'debugzope'),
+                    zope_conf_path,
+                    zdaemon_conf_path,
+                    )
+                spath, x = zc.buildout.easy_install._relative_path_and_setup(
+                    os.path.join(options['bin-directory'], 'ctl'),
+                    arg_paths,
+                    self.egg._relative_paths,
+                    )
+                rpath = spath.split(',\n  ')
+                debugzope_loc, zope_conf_path, zdaemon_conf_path = rpath
+                arguments = ('['
+                             '\n        %s,'
+                             '\n        %s,'
+                             '\n        %r, %s,'
+                             '\n        ]+sys.argv[1:]'
+                             '\n        '
+                             % (debugzope_loc,
+                                zope_conf_path,
+                                '-C', zdaemon_conf_path,
+                                )
+                             )
+            else:
+                arguments = ('['
+                             '\n        %r,'
+                             '\n        %r,'
+                             '\n        %r, %r,'
+                             '\n        ]+sys.argv[1:]'
+                             '\n        '
+                             % (os.path.join(app_loc, 'debugzope'),
+                                zope_conf_path,
+                                '-C', zdaemon_conf_path,
+                                )
+                             )
+
             if WIN:
                 zc.buildout.easy_install.scripts(
                     [(rc, 'zc.zope3recipes.winctl', 'main')],
                     ws, options['executable'], options['bin-directory'],
-                    extra_paths = [this_loc],
-                    arguments = ('['
-                                 '\n        %r,'
-                                 '\n        %r,'
-                                 '\n        %r, %r,'
-                                 '\n        ]+sys.argv[1:]'
-                                 '\n        '
-                                 % (os.path.join(app_loc, 'debugzope'),
-                                    zope_conf_path,
-                                    '-C', zdaemon_conf_path,
-                                    )
-                                 ),
+                    extra_paths=[this_loc],
+                    arguments=arguments,
+                    relative_paths=self.egg._relative_paths,
                     )
             else:
                 zc.buildout.easy_install.scripts(
                     [(rc, 'zc.zope3recipes.ctl', 'main')],
                     ws, options['executable'], options['bin-directory'],
-                    extra_paths = [this_loc],
-                    arguments = ('['
-                                 '\n        %r,'
-                                 '\n        %r,'
-                                 '\n        %r, %r,'
-                                 '\n        ]+sys.argv[1:]'
-                                 '\n        '
-                                 % (os.path.join(app_loc, 'debugzope'),
-                                    zope_conf_path,
-                                    '-C', zdaemon_conf_path,
-                                    )
-                                 ),
+                    extra_paths=[this_loc],
+                    arguments=arguments,
+                    relative_paths=self.egg._relative_paths,
                     )
 
             return creating



More information about the checkins mailing list