[Checkins] SVN: zc.recipe.macro/trunk/ From CHANGES.txt:

Aaron Lehmann aaron at zope.com
Fri Jul 18 15:52:57 EDT 2008


Log message for revision 88539:
  From CHANGES.txt:
  - Fixed a bug that made self-targetting invocations fail when the macro utilized
    default values and the option that read the default came out the Options
    iteration first, added a regression test.
  - Changed the test setup so that buildouts are tested by calling methods rather
    than creating a subprocess.  This allows for the --coverage flage to work in
    bin/test, and makes debugging and mimmicking the test output significantly
    easier.
  - Fixed addition of targets so that they will show up properly when one calls
    buildout.keys().
  
  

Changed:
  U   zc.recipe.macro/trunk/CHANGES.txt
  U   zc.recipe.macro/trunk/src/zc/recipe/macro/README.txt
  U   zc.recipe.macro/trunk/src/zc/recipe/macro/recipe.py
  U   zc.recipe.macro/trunk/src/zc/recipe/macro/tests.py

-=-
Modified: zc.recipe.macro/trunk/CHANGES.txt
===================================================================
--- zc.recipe.macro/trunk/CHANGES.txt	2008-07-18 19:49:05 UTC (rev 88538)
+++ zc.recipe.macro/trunk/CHANGES.txt	2008-07-18 19:52:57 UTC (rev 88539)
@@ -1,6 +1,20 @@
 CHANGES
 =======
 
+1.2.4 (2008-07-18)
+------------------
+
+- Fixed a bug that made self-targetting invocations fail when the macro utilized
+  default values and the option that read the default came out the Options
+  iteration first, added a regression test.
+- Changed the test setup so that buildouts are tested by calling methods rather
+  than creating a subprocess.  This allows for the --coverage flage to work in
+  bin/test, and makes debugging and mimmicking the test output significantly
+  easier.
+- Fixed addition of targets so that they will show up properly when one calls
+  buildout.keys().
+
+
 1.2.3 (2008-07-11)
 ------------------
 

Modified: zc.recipe.macro/trunk/src/zc/recipe/macro/README.txt
===================================================================
--- zc.recipe.macro/trunk/src/zc/recipe/macro/README.txt	2008-07-18 19:49:05 UTC (rev 88538)
+++ zc.recipe.macro/trunk/src/zc/recipe/macro/README.txt	2008-07-18 19:52:57 UTC (rev 88539)
@@ -17,9 +17,9 @@
 that use it, except the recipe option.
 
 Macros are used by parts called "macro invocations".  The invocation uses the
-macro recipe, and identifies the "macro section" using the "macro" option::
+macro recipe, and identifies the "macro section" using the "macro" option:
 
-    >>> write(sample_buildout, "buildout.cfg",
+    >>> buildout = setupBuildout(sample_buildout, "buildout.cfg",
     ... """
     ... [buildout]
     ... parts = instance0 instance1
@@ -91,44 +91,55 @@
 Now we'll run the buildout.
 
     >>> import os
-    >>> here = os.getcwd()
     >>> os.chdir(sample_buildout)
-    >>> buildout = os.path.join(sample_buildout, 'bin', 'buildout')
-    >>> print system(buildout)
-    Installing instance0.
-        address: 8080
-        application: application
-        monitor-port: 8089
-        recipe: zc.recipe.macro:test
-        zope.conf: 
+    >>> buildout.install([])
+    >>> buildout_pprint(dict(buildout))
+    {'buildout': ...
+     'instance-macro': {'application': 'application',
+                        'zope.conf': '
             <eventlog>
-                <logfile>
-                    path /var/log/myapp/instance0-z3.log
-                </logfile>
+            <logfile>
+            path /var/log/myapp/$${:__name__}-z3.log
+            </logfile>
             </eventlog>
             <product-config zc.z3monitor>
-                port 8089
-            </product-config>
-    Installing instance1.
-        address: 9080
-        application: application
-        monitor-port: 9089
-        recipe: zc.recipe.macro:test
-        zope.conf: 
+            port $${:monitor-port}
+            </product-config>'},
+     'instance0': {'address': '8080',
+                   'application': 'application',
+                   'monitor-port': '8089',
+                   'recipe': 'zc.recipe.macro:test',
+                   'zope.conf': '
             <eventlog>
-                <logfile>
-                    path /var/log/myapp/instance1-z3.log
-                </logfile>
+            <logfile>
+            path /var/log/myapp/instance0-z3.log
+            </logfile>
             </eventlog>
             <product-config zc.z3monitor>
-                port 9089
-            </product-config>
-    <BLANKLINE>
+            port 8089
+            </product-config>'},
+     'instance1': {'address': '9080',
+                   'application': 'application',
+                   'monitor-port': '9089',
+                   'recipe': 'zc.recipe.macro:test',
+                   'zope.conf': '
+            <eventlog>
+            <logfile>
+            path /var/log/myapp/instance1-z3.log
+            </logfile>
+            </eventlog>
+            <product-config zc.z3monitor>
+            port 9089
+            </product-config>'},
+     'versions': {...}}
+    >>> os.chdir(macro)
 
 
-This results in parts equivalent to the buildout::
+This results in parts equivalent to the buildout:
 
     >>> os.chdir(here)
+    >>> rmdir(sample_buildout)
+    >>> sample_buildout = tmpdir(sample_buildout)
     >>> write(sample_buildout, "buildout.cfg",
     ... """
     ... [buildout]
@@ -173,48 +184,128 @@
     ...     </product-config>
     ... """)
     >>> os.chdir(sample_buildout)
-    >>> print system(buildout)
-    Updating instance0.
-        address: 8080
-        application: application
-        monitor-port: 8089
-        recipe: zc.recipe.macro:test
-        zope.conf: 
+    >>> buildout.install([])
+    >>> buildout_pprint(dict(buildout))
+    {'buildout': {...},
+     'instance-macro': {'application': 'application',
+                        'zope.conf': '
             <eventlog>
-                <logfile>
-                    path /var/log/myapp/instance0-z3.log
-                </logfile>
+            <logfile>
+            path /var/log/myapp/$${:__name__}-z3.log
+            </logfile>
             </eventlog>
             <product-config zc.z3monitor>
-                port 8089
-            </product-config>
-    Updating instance1.
-        address: 9080
-        application: application
-        monitor-port: 9089
-        recipe: zc.recipe.macro:test
-        zope.conf: 
+            port $${:monitor-port}
+            </product-config>'},
+     'instance0': {'address': '8080',
+                   'application': 'application',
+                   'monitor-port': '8089',
+                   'recipe': 'zc.recipe.macro:test',
+                   'zope.conf': '
             <eventlog>
-                <logfile>
-                    path /var/log/myapp/instance1-z3.log
-                </logfile>
+            <logfile>
+            path /var/log/myapp/instance0-z3.log
+            </logfile>
             </eventlog>
             <product-config zc.z3monitor>
-                port 9089
-            </product-config>
-    <BLANKLINE>
+            port 8089
+            </product-config>'},
+     'instance1': {'address': '9080',
+                   'application': 'application',
+                   'monitor-port': '9089',
+                   'recipe': 'zc.recipe.macro:test',
+                   'zope.conf': '
+            <eventlog>
+            <logfile>
+            path /var/log/myapp/instance1-z3.log
+            </logfile>
+            </eventlog>
+            <product-config zc.z3monitor>
+            port 9089
+            </product-config>'},
+     'versions': {...}}
+    >>> os.chdir(macro)
 
 Note that the options from the invocation are used both to perform
 substitutions and as additional options in the expansion.  The result-recipe
 option is used to determine the recipe used on the resulting part.
 
+Default values in macros
+------------------------
+
+It is possible to make default values in macros.
+
+    >>> buildout = setupBuildout(sample_buildout, "buildout.cfg",
+    ... """
+    ... [buildout]
+    ... parts = instance0
+    ... versions = versions
+    ...
+    ... [versions]
+    ... zc.recipe.egg = 1.0.0
+    ... setuptools = 0.6c8
+    ... zc.recipe.testrunner = 1.0.0
+    ... zc.buildout = 1.0.0
+    ... zope.testing = 3.5.0
+    ...
+    ... [instance-macro]
+    ... application = application
+    ... zope.conf =
+    ...     <eventlog>
+    ...         <logfile>
+    ...             path /var/log/myapp/$${:__name__}-z3.log
+    ...         </logfile>
+    ...     </eventlog>
+    ...     <product-config zc.z3monitor>
+    ...         port $${:monitor-port}
+    ...     </product-config>
+    ... address = 8080
+    ... monitor-port = 8089
+    ...
+    ... [instance0]
+    ... recipe = zc.recipe.macro
+    ... result-recipe = zc.recipe.macro:test
+    ... macro = instance-macro
+    ... """)
+    >>> os.chdir(sample_buildout)
+    >>> buildout.install([])
+    >>> buildout_pprint(dict(buildout))
+    {'buildout': {...},
+     'instance-macro': {'address': '8080',
+                        'application': 'application',
+                        'monitor-port': '8089',
+                        'zope.conf': '
+            <eventlog>
+            <logfile>
+            path /var/log/myapp/$${:__name__}-z3.log
+            </logfile>
+            </eventlog>
+            <product-config zc.z3monitor>
+            port $${:monitor-port}
+            </product-config>'},
+     'instance0': {'address': '8080',
+                   'application': 'application',
+                   'monitor-port': '8089',
+                   'recipe': 'zc.recipe.macro:test',
+                   'zope.conf': '
+            <eventlog>
+            <logfile>
+            path /var/log/myapp/instance0-z3.log
+            </logfile>
+            </eventlog>
+            <product-config zc.z3monitor>
+            port 8089
+            </product-config>'},
+     'versions': {...}}
+    >>> os.chdir(macro)
+
+
 Macro invocation without a result-recipe
 ----------------------------------------
 
 Sometimes it is good to have a macro that does not result in a part.
 
-    >>> os.chdir(here)
-    >>> write(sample_buildout, "buildout.cfg",
+    >>> buildout = setupBuildout(sample_buildout, "buildout.cfg",
     ... """
     ... [buildout]
     ... parts = instance0 instance1
@@ -251,82 +342,55 @@
     ... address = 9080
     ... monitor-port = 9089
     ... """)
-
     >>> os.chdir(sample_buildout)
-    >>> buildout = os.path.join(sample_buildout, 'bin', 'buildout')
-    >>> print system(buildout + ' -vv')
-    Installing 'zc.buildout', 'setuptools'.
-    ...
-    <BLANKLINE>
-    Configuration data:
-    [instance-macro]
-    application = application
-    zope.conf = %(__buildout_space_n__)s<eventlog>
-        <logfile>
-        path /var/log/myapp/$${:__name__}-z3.log
-        </logfile>
-        </eventlog>
-        <product-config zc.z3monitor>
-        port $${:monitor-port}
-        </product-config>
-    [instance0]
-    address = 8080
-    application = application
-    monitor-port = 8089
-    recipe = zc.recipe.macro:empty
-    zope.conf = %(__buildout_space_n__)s<eventlog>
-        <logfile>
-        path /var/log/myapp/instance0-z3.log
-        </logfile>
-        </eventlog>
-        <product-config zc.z3monitor>
-        port 8089
-        </product-config>
-    [instance1]
-    address = 9080
-    application = application
-    monitor-port = 9089
-    recipe = zc.recipe.macro:empty
-    zope.conf = %(__buildout_space_n__)s<eventlog>
-        <logfile>
-        path /var/log/myapp/instance1-z3.log
-        </logfile>
-        </eventlog>
-        <product-config zc.z3monitor>
-        port 9089
-        </product-config>
-    [buildout]
-    bin-directory = /sample-buildout/bin
-    develop-eggs-directory = /sample-buildout/develop-eggs
-    directory = /sample-buildout
-    eggs-directory = /sample-buildout/eggs
-    executable = .../local/bin/python...
-    installed = /sample-buildout/.installed.cfg
-    log-format =
-    log-level = INFO
-    newest = true
-    offline = false
-    parts = instance0 instance1
-    parts-directory = /sample-buildout/parts
-    python = buildout
-    verbosity = 20
-    versions = versions
-    [versions]
-    setuptools = 0.6c8
-    zc.buildout = 1.0.0
-    zc.recipe.egg = 1.0.0
-    zc.recipe.testrunner = 1.0.0
-    zope.testing = 3.5.0
-    <BLANKLINE>
-    ...
+    >>> buildout.install([])
+    >>> buildout_pprint(buildout)
+    {'buildout': {...},
+     'instance-macro': {'application': 'application',
+                        'zope.conf': '
+            <eventlog>
+            <logfile>
+            path /var/log/myapp/$${:__name__}-z3.log
+            </logfile>
+            </eventlog>
+            <product-config zc.z3monitor>
+            port $${:monitor-port}
+            </product-config>'},
+     'instance0': {'address': '8080',
+                   'application': 'application',
+                   'monitor-port': '8089',
+                   'recipe': 'zc.recipe.macro:empty',
+                   'zope.conf': '
+            <eventlog>
+            <logfile>
+            path /var/log/myapp/instance0-z3.log
+            </logfile>
+            </eventlog>
+            <product-config zc.z3monitor>
+            port 8089
+            </product-config>'},
+     'instance1': {'address': '9080',
+                   'application': 'application',
+                   'monitor-port': '9089',
+                   'recipe': 'zc.recipe.macro:empty',
+                   'zope.conf': '
+            <eventlog>
+            <logfile>
+            path /var/log/myapp/instance1-z3.log
+            </logfile>
+            </eventlog>
+            <product-config zc.z3monitor>
+            port 9089
+            </product-config>'},
+     'versions': {...}}
+    >>> os.chdir(sample_buildout)
 
 In this case, the zc.recipe.macro recipe is used, with its Empty entry point.
 This entry point doesn't do anything, but we have to have a recipe to use,
 since the macro recipe has declared this to be a part.  The same sort of output
 will come from an empty result-recipe option.
 
-    >>> os.chdir(here)
-    >>> write(sample_buildout, "buildout.cfg",
+    >>> buildout = setupBuildout(sample_buildout, "buildout.cfg",
     ... """
     ... [buildout]
     ... parts = instance0 instance1
@@ -365,75 +429,47 @@
     ... address = 9080
     ... monitor-port = 9089
     ... """)
+    >>> buildout.install([])
+    >>> buildout_pprint(buildout)
+    {'buildout': {...},
+     'instance-macro': {'application': 'application',
+                        'zope.conf': '
+            <eventlog>
+            <logfile>
+            path /var/log/myapp/$${:__name__}-z3.log
+            </logfile>
+            </eventlog>
+            <product-config zc.z3monitor>
+            port $${:monitor-port}
+            </product-config>'},
+     'instance0': {'address': '8080',
+                   'application': 'application',
+                   'monitor-port': '8089',
+                   'recipe': 'zc.recipe.macro:empty',
+                   'zope.conf': '
+            <eventlog>
+            <logfile>
+            path /var/log/myapp/instance0-z3.log
+            </logfile>
+            </eventlog>
+            <product-config zc.z3monitor>
+            port 8089
+            </product-config>'},
+     'instance1': {'address': '9080',
+                   'application': 'application',
+                   'monitor-port': '9089',
+                   'recipe': 'zc.recipe.macro:empty',
+                   'zope.conf': '
+            <eventlog>
+            <logfile>
+            path /var/log/myapp/instance1-z3.log
+            </logfile>
+            </eventlog>
+            <product-config zc.z3monitor>
+            port 9089
+            </product-config>'},
+     'versions': {...}}
 
-    >>> os.chdir(sample_buildout)
-    >>> buildout = os.path.join(sample_buildout, 'bin', 'buildout')
-    >>> print system(buildout + ' -vv')
-    Installing 'zc.buildout', 'setuptools'.
-    ...
-    <BLANKLINE>
-    Configuration data:
-    [instance-macro]
-    application = application
-    zope.conf = %(__buildout_space_n__)s<eventlog>
-        <logfile>
-        path /var/log/myapp/$${:__name__}-z3.log
-        </logfile>
-        </eventlog>
-        <product-config zc.z3monitor>
-        port $${:monitor-port}
-        </product-config>
-    [instance0]
-    address = 8080
-    application = application
-    monitor-port = 8089
-    recipe = zc.recipe.macro:empty
-    zope.conf = %(__buildout_space_n__)s<eventlog>
-        <logfile>
-        path /var/log/myapp/instance0-z3.log
-        </logfile>
-        </eventlog>
-        <product-config zc.z3monitor>
-        port 8089
-        </product-config>
-    [instance1]
-    address = 9080
-    application = application
-    monitor-port = 9089
-    recipe = zc.recipe.macro:empty
-    zope.conf = %(__buildout_space_n__)s<eventlog>
-        <logfile>
-        path /var/log/myapp/instance1-z3.log
-        </logfile>
-        </eventlog>
-        <product-config zc.z3monitor>
-        port 9089
-        </product-config>
-    [buildout]
-    bin-directory = /sample-buildout/bin
-    develop-eggs-directory = /sample-buildout/develop-eggs
-    directory = /sample-buildout
-    eggs-directory = /sample-buildout/eggs
-    executable = .../local/bin/python...
-    installed = /sample-buildout/.installed.cfg
-    log-format =
-    log-level = INFO
-    newest = true
-    offline = false
-    parts = instance0 instance1
-    parts-directory = /sample-buildout/parts
-    python = buildout
-    verbosity = 20
-    versions = versions
-    [versions]
-    setuptools = 0.6c8
-    zc.buildout = 1.0.0
-    zc.recipe.egg = 1.0.0
-    zc.recipe.testrunner = 1.0.0
-    zope.testing = 3.5.0
-    <BLANKLINE>
-    ...
-
 And of course they are the same as explicitly declaring and empty result.
 
 Targets for Macro Invocation
@@ -447,11 +483,10 @@
 sections are just like any other section, so other sections can refer to their
 options, and they can be used as parts.
 
-    >>> os.chdir(here)
-    >>> write(sample_buildout, "buildout.cfg",
+    >>> buildout = setupBuildout(sample_buildout, "buildout.cfg",
     ... """
     ... [buildout]
-    ... parts = invoker0 invoker1
+    ... parts = invoker
     ... versions = versions
     ...
     ... [versions]
@@ -462,76 +497,89 @@
     ... zope.testing = 3.5.0
     ...
     ... [macro]
-    ... output = I was invoked by $${:__name__}
+    ... output = I was invoked on $${:__name__}
     ...
-    ... [invoker0]
+    ... [invoker]
     ... recipe = zc.recipe.macro
     ... macro = macro
-    ... targets = zero
+    ... targets =
+    ...     zero
+    ...     one
+    ... """)
+    >>> buildout.install([])
+    >>> buildout_pprint(buildout)
+    {'buildout': {...},
+     'invoker': {'recipe': 'zc.recipe.macro:empty'},
+     'macro': {'output': 'I was invoked on $${:__name__}'},
+     'one': {'output': 'I was invoked on one'},
+     'versions': {...},
+     'zero': {'output': 'I was invoked on zero'}}
+
+It is possible, and much more useful, to provide parameters by specifying other
+sections.
+
+    >>> buildout = setupBuildout(sample_buildout, "buildout.cfg",
+    ... """
+    ... [buildout]
+    ... parts = invoker
+    ... versions = versions
     ...
-    ... [invoker1]
+    ... [versions]
+    ... zc.recipe.egg = 1.0.0
+    ... setuptools = 0.6c8
+    ... zc.recipe.testrunner = 1.0.0
+    ... zc.buildout = 1.0.0
+    ... zope.testing = 3.5.0
+    ...
+    ... [macro]
+    ... output = $${:subject} was invoked on $${:__name__}
+    ...
+    ... [one-parameters]
+    ... subject = Fred
+    ...
+    ... [zero-parameters]
+    ... subject = Benji
+    ...
+    ... [invoker]
     ... recipe = zc.recipe.macro
     ... macro = macro
-    ... targets = one
+    ... targets =
+    ...     zero:zero-parameters
+    ...     one:one-parameters
     ... """)
+    >>> buildout.install([])
+    >>> buildout_pprint(buildout)
+    {'buildout': {...},
+     'invoker': {'recipe': 'zc.recipe.macro:empty'},
+     'macro': {'output': '$${:subject} was invoked on $${:__name__}'},
+     'one': {'output': 'Fred was invoked on one'},
+     'one-parameters': {'subject': 'Fred'},
+     'versions': {...},
+     'zero': {'output': 'Benji was invoked on zero'},
+     'zero-parameters': {'subject': 'Benji'}}
 
-    >>> os.chdir(sample_buildout)
-    >>> buildout = os.path.join(sample_buildout, 'bin', 'buildout')
-    >>> print system(buildout + ' -vv')
-    Installing 'zc.buildout', 'setuptools'.
-    ...
-    <BLANKLINE>
-    Configuration data:
-    [buildout]
-    bin-directory = /sample-buildout/bin
-    develop-eggs-directory = /sample-buildout/develop-eggs
-    directory = /sample-buildout
-    eggs-directory = /sample-buildout/eggs
-    executable = .../local/bin/python...
-    installed = /sample-buildout/.installed.cfg
-    log-format =
-    log-level = INFO
-    newest = true
-    offline = false
-    parts = invoker0 invoker1
-    parts-directory = /sample-buildout/parts
-    python = buildout
-    verbosity = 20
-    versions = versions
-    [versions]
-    setuptools = 0.6c8
-    zc.buildout = 1.0.0
-    zc.recipe.egg = 1.0.0
-    zc.recipe.testrunner = 1.0.0
-    zope.testing = 3.5.0
-    [macro]
-    output = I was invoked by $${:__name__}
-    [invoker0]
-    recipe = zc.recipe.macro:empty
-    [invoker1]
-    recipe = zc.recipe.macro:empty
-    [zero]
-    output = I was invoked by zero
-    [one]
-    output = I was invoked by one
-    <BLANKLINE>
-    ...
 
+Edge Case Tests
+---------------
 
-Providing Parameters to Named Macros
-------------------------------------
+It used to cause errors when default macro variables referred to one another
+and the invoker targetted itself.  This test will prevent regression.  The bug
+is dependant on the iteration order of a dictionaryish object, and so a
+subclass will be created that returns it's keys in a particular order.
 
-Another thing that is necesary to being able to use a macro twice in the same
-section is the ability to specify a mapping between the options of the invoker
-and the options in the scope.  Without this, no matter how many times one ran
-the macro, the results would all be the same.  This is done by naming an
-existing section, which will be used as source of values.
+    >>> import zc.recipe.macro.recipe
+    >>> class OrderedOptions(zc.buildout.buildout.Options):
+    ...     def keys(self):
+    ...         return list(
+    ...             reversed(sorted(zc.buildout.buildout.Options.keys(self))))
+    >>> zc.recipe.macro.recipe.Options = OrderedOptions
 
-    >>> os.chdir(here)
-    >>> write(sample_buildout, "buildout.cfg",
+Now we'll make the buildout in memory, so that our monkeypatch will be effective:
+
+    >>> buildout = setupBuildout(sample_buildout, "buildout.cfg",
     ... """
     ... [buildout]
-    ... parts = invoker0
+    ... parts = instance0
     ... versions = versions
     ...
     ... [versions]
@@ -541,60 +589,56 @@
     ... zc.buildout = 1.0.0
     ... zope.testing = 3.5.0
     ...
-    ... [macro]
-    ... output = I was invoked by $${:name}
-    ... name = $${:__name__}
+    ... [instance-macro]
+    ... address = 8080
+    ... application = application
+    ... monitor-port = 8089
+    ... zope.conf =
+    ...     <eventlog>
+    ...         <logfile>
+    ...             path /var/log/myapp/$${:__name__}-z3.log
+    ...         </logfile>
+    ...     </eventlog>
+    ...     <product-config zc.z3monitor>
+    ...         port $${:monitor-port}
+    ...     </product-config>
     ...
-    ... [invoker0]
+    ... [instance0]
     ... recipe = zc.recipe.macro
-    ... result-recipe =
-    ... macro = macro
-    ... targets = zero:zero-parameters
-    ...
-    ... [zero-parameters]
-    ... name = Otto von Bismark
+    ... result-recipe = zc.recipe.macro:test
+    ... macro = instance-macro
     ... """)
+    >>> buildout.install([])
+    >>> buildout_pprint(buildout)
+    {'buildout': {...},
+     'instance-macro': {'address': '8080',
+                        'application': 'application',
+                        'monitor-port': '8089',
+                        'zope.conf': '
+            <eventlog>
+            <logfile>
+            path /var/log/myapp/$${:__name__}-z3.log
+            </logfile>
+            </eventlog>
+            <product-config zc.z3monitor>
+            port $${:monitor-port}
+            </product-config>'},
+     'instance0': {'address': '8080',
+                   'application': 'application',
+                   'monitor-port': '8089',
+                   'recipe': 'zc.recipe.macro:test',
+                   'zope.conf': '
+            <eventlog>
+            <logfile>
+            path /var/log/myapp/instance0-z3.log
+            </logfile>
+            </eventlog>
+            <product-config zc.z3monitor>
+            port 8089
+            </product-config>'},
+     'versions': {...}}
 
-    >>> os.chdir(sample_buildout)
-    >>> buildout = os.path.join(sample_buildout, 'bin', 'buildout')
-    >>> print system(buildout + ' -vv')
-    Installing 'zc.buildout', 'setuptools'.
-    ...
-    <BLANKLINE>
-    Configuration data:
-    [zero-parameters]
-    name = Otto von Bismark
-    [versions]
-    setuptools = 0.6c8
-    zc.buildout = 1.0.0
-    zc.recipe.egg = 1.0.0
-    zc.recipe.testrunner = 1.0.0
-    zope.testing = 3.5.0
-    [macro]
-    name = $${:__name__}
-    output = I was invoked by $${:name}
-    [invoker0]
-    recipe = zc.recipe.macro:empty
-    [zero]
-    name = Otto von Bismark
-    output = I was invoked by Otto von Bismark
-    [buildout]
-    bin-directory = /sample-buildout/bin
-    develop-eggs-directory = /sample-buildout/develop-eggs
-    directory = /sample-buildout
-    eggs-directory = /sample-buildout/eggs
-    executable = .../local/bin/python...
-    installed = /sample-buildout/.installed.cfg
-    log-format =
-    log-level = INFO
-    newest = true
-    offline = false
-    parts = invoker0
-    parts-directory = /sample-buildout/parts
-    python = buildout
-    verbosity = 20
-    versions = versions
-    <BLANKLINE>
-    ...
+And we'll return to the old Options:
 
+    >>> zc.recipe.macro.recipe.Options = zc.buildout.buildout.Options
 

Modified: zc.recipe.macro/trunk/src/zc/recipe/macro/recipe.py
===================================================================
--- zc.recipe.macro/trunk/src/zc/recipe/macro/recipe.py	2008-07-18 19:49:05 UTC (rev 88538)
+++ zc.recipe.macro/trunk/src/zc/recipe/macro/recipe.py	2008-07-18 19:52:57 UTC (rev 88539)
@@ -15,6 +15,7 @@
 import os.path
 import zc.buildout.buildout
 import pprint
+from zc.buildout.buildout import Options
 
 
 def evaluate_macro(buildout, name, macro, input, recipe):
@@ -58,19 +59,19 @@
     macro_summation.update(dict(buildout[macro]))
 
     for output, input in (parse_target(name, target) for target in targets):
-        opt = zc.buildout.buildout.Options(
+        opt = Options(
                 buildout,
                 output,
                 evaluate_macro(
                     buildout, output, macro_summation, input, recipe))
         if output == name:
             # If we're targetting the invoker
-            options.update(opt)
+            options._raw.update(opt._raw)
             options['recipe'] = options.get('recipe', 'zc.recipe.macro:empty')
         else:
             # If we're targetting some other section
-            buildout._data[output] = opt
-            opt._initialize()
+            buildout._raw[output] = opt._raw
+            #opt._initialize()
 
     #Make sure we have a recipe for this part, even if it is only the empty
     #one.
@@ -108,8 +109,6 @@
         self.options = options
 
     def install(self):
-        print '\n'.join("%s: %s" % item for item in sorted(
-            self.options.iteritems()))
         return []
 
     update = install

Modified: zc.recipe.macro/trunk/src/zc/recipe/macro/tests.py
===================================================================
--- zc.recipe.macro/trunk/src/zc/recipe/macro/tests.py	2008-07-18 19:49:05 UTC (rev 88538)
+++ zc.recipe.macro/trunk/src/zc/recipe/macro/tests.py	2008-07-18 19:52:57 UTC (rev 88539)
@@ -12,10 +12,16 @@
 #
 ##############################################################################
 
+import logging
 import os
+import os.path
+import pprint
 import re
+import zc.buildout.buildout
 import zc.buildout.testing
 import zc.buildout.tests
+import StringIO
+import sys
 
 import unittest
 import zc.recipe.egg
@@ -25,15 +31,64 @@
 import zope.testing.doctest
 import zope.testing.renormalizing
 
+
+here = os.path.abspath(os.path.dirname(__file__))
+
+def buildout_pprint(buildout):
+    b_dict = dict((key, dict(value)) for (key, value) in buildout.iteritems())
+    string = pprint.pformat(b_dict).replace('\\n', '\n')
+    print string
+
+def setupBuildout(test, *args):
+    tmpdir, rmdir, write, sample_buildout = (
+        test.globs['tmpdir'],
+        test.globs['rmdir'],
+        test.globs['write'],
+        test.globs['sample_buildout'],)
+
+    args = list(args)
+    cfg = args.pop()
+    filename = args.pop()
+    directory = os.path.join(*args)
+    eggs = os.path.join(os.path.join(directory, 'eggs'))
+    path = os.path.join(directory, filename)
+    rmdir(directory)
+    test.globs['sample_buildout'] = sample_buildout = tmpdir(sample_buildout)
+    write(path, cfg)
+    os.chdir(sample_buildout)
+    buildout = zc.buildout.buildout.Buildout(
+        path,
+        [# trick bootstrap into putting the buildout develop egg
+         # in the eggs dir.
+         ('buildout', 'develop-eggs-directory', 'eggs'),
+         ],
+        user_defaults=False
+        )
+    logger = logging.getLogger('zc.buildout')
+    logger.removeHandler(logger.handlers[0])
+    logging.getLogger('zc.buildout').setLevel(99999)
+    buildout.bootstrap([])
+    zc.buildout.testing.install('zope.testing', eggs)
+    zc.buildout.testing.install('zc.recipe.testrunner', eggs)
+    zc.buildout.testing.install('zc.recipe.egg', eggs)
+    zc.buildout.testing.install('zc.recipe.macro', eggs)
+    return buildout
+
+
 def setUp(test):
     zc.buildout.testing.buildoutSetUp(test)
 
-    zc.buildout.testing.install('zope.testing', test)
-    zc.buildout.testing.install('zc.recipe.testrunner', test)
-    zc.buildout.testing.install('zc.recipe.egg', test)
-    zc.buildout.testing.install('zc.recipe.macro', test)
+    test.globs['here'] = here
+    test.globs['macro'] = os.path.join('../../../..', here)
+    test.globs['setupBuildout'] = (lambda *args: setupBuildout(test, *args))
+    test.globs['buildout_pprint'] = buildout_pprint
+    os.chdir(test.globs['macro'])
     return test
 
+def tearDown(test):
+    zc.buildout.testing.rmdir(test.globs['sample_buildout'])
+    zc.buildout.testing.buildoutTearDown(test)
+
 def test_suite():
     optionflags = (zope.testing.doctest.NORMALIZE_WHITESPACE
                    | zope.testing.doctest.ELLIPSIS
@@ -42,7 +97,7 @@
     suite.addTest(
         zope.testing.doctest.DocFileSuite(
             'README.txt',
-            setUp=setUp, tearDown=zc.buildout.testing.buildoutTearDown,
+            setUp=setUp, tearDown=tearDown,
             checker=zope.testing.renormalizing.RENormalizing([
                zc.buildout.testing.normalize_path,
                zc.buildout.testing.normalize_script,



More information about the Checkins mailing list