merge script broken in Optik 1.5 (patches attached)

Andrea 'fwyzard' Bocci <[email protected]> Sun, 12 Dec 2004 00:11:52 +0100
Newsgroups gmane.comp.python.optik.user
Message-ID <[email protected]>
This is a multi-part message in MIME format.
--------------060603010005050900020700
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Hi Greg,
Well, nice work for this release, you really have my appreciation :-)

Alas (I've ALWAYS wanted to say that :-), I've found out that the merge
script is broken in Optik 1.5 (I have revision 473 from the repository).

	./merge optik.py /dev/null

would create a non working module.
I've found and fixed 3 bugs, after that the merged module seems to be
working fine.

1.) merge vs. lib/option.py
The starting merge line for option.py is wrong: merge is looking for
"_builtin_cvt", but that leaves out the definitions for "_parse_num" and
friends.
I've changed the starting line pattern to "_parse_num".
A patch is attached as merge.diff

2.) merge vs. lib/errors.py
Here I've found a similar problem, where the __all__ definition from
lib/errors.py gets actually included in the merged module, and so it
superseeds the explicit one from merge. As a result,

	import * from optik

would only import the names from errors.py.
I've just reordered the lines so that __revision__ and __all__ come
before the first try.
A patch is attached as errors.diff

3.) lib/option_parser.py vs. errors namespace
This is slightly more complex to deal with:
lib/option_parser.py uses lib/errors.py's exception classes directly
from the "errors" namespace, ie.

	from optik import errors
	from optik.errors import gettext as _
	...
	raise errors.OptionConflictError
	...

etc..
When the modules are merged together, there is no "errors" namespace any
more, so I get errors as soon as any exception is being raised or tested.
I've come out with two possible solutions, the first one being to simple
use those exception from the global namespace, ie.:

	from optik.errors import *
	from optik.errors import gettext as _
	...
	raise OptionConflictError
	...
etc.

The second way leaves lib/option_parser.py alone, the idea is to let
merge introduce a kinf of an alias for the global namespace and call it
errors:

	class __global__:
	  def __getattr__(self, name):
	      return globals()[name]
	
	errors = __global__()

Then, errors.anything returns anything from the global namespace.
A patch is attached as global.diff.

I actually like the other approach best, as it feels more clean, but
this hack might be usefull in case you want to keep everything in its
namespace in the "normal" distribution.

Hope this helps!

.Andrea.



--------------060603010005050900020700
Content-Type: text/plain;
 name="errors.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="errors.diff"

Index: lib/errors.py
===================================================================
--- lib/errors.py	(revision 473)
+++ lib/errors.py	(working copy)
@@ -6,6 +6,11 @@
 # Copyright (c) 2001-2004 Gregory P. Ward.  All rights reserved.
 # See the README.txt distributed with Optik for licensing terms.
 
+__revision__ = "$Id: errors.py 470 2004-12-07 01:39:56Z gward $"
+
+__all__ = ['OptikError', 'OptionError', 'OptionConflictError',
+           'OptionValueError', 'BadOptionError']
+
 try:
     from gettext import gettext
 except ImportError:
@@ -13,12 +18,7 @@
         return message
 _ = gettext
 
-__revision__ = "$Id: errors.py 470 2004-12-07 01:39:56Z gward $"
 
-__all__ = ['OptikError', 'OptionError', 'OptionConflictError',
-           'OptionValueError', 'BadOptionError']
-
-
 class OptikError (Exception):
     def __init__(self, msg):
         self.msg = msg



--------------060603010005050900020700
Content-Type: text/plain;
 name="global.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="global.diff"

Index: merge
===================================================================
--- merge	(revision 473)
+++ merge	(working copy)
@@ -119,6 +119,12 @@
 def _repr(self):
     return "<%s at 0x%x: %s>" % (self.__class__.__name__, id(self), self)
 
+class __global__:
+  def __getattr__(self, name):
+      return globals()[name]
+
+errors = __global__()
+
 '''
 
     # We'll process the modules in this order -- option_parser comes



--------------060603010005050900020700
Content-Type: text/plain;
 name="merge.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="merge.diff"

Index: merge
===================================================================
--- merge	(revision 473)
+++ merge	(working copy)
@@ -125,7 +125,7 @@
     # last because it depends on all the others.
     modules = [("errors",        "try:"),
                ("help",          "class HelpFormatter"),
-               ("option",        "_builtin_cvt"),
+               ("option",        "def _parse_num"),
                ("option_parser", "SUPPRESS_HELP")]
 
     contents = {}



--------------060603010005050900020700--



-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now. 
http://productguide.itmanagersjournal.com/