PJ Eby | 27 Mar 2013 18:41
Gravatar

Re: Re: RuleDispatch incompatible with python2.6

On Wed, Mar 27, 2013 at 1:21 AM, alexander smishlajev <alex@...> wrote:
>Starting with python2.6, "as" is keywords of the language, and cannot be
>used as ordinary identifier.  The dispatch module cannot be imported:

This is now fixed in SVN for both legacy PEAK and RuleDispatch - the
tests for both now run fully on Python 2.7, at least for me on
Windows.

As you said in private email, your earlier email did not get through
to the list; you might try resubscribing if you didn't get a bounce
message or anything.
PJ Eby | 27 Mar 2013 18:03
Gravatar

Re: trying to run peak-rules on python3

On Wed, Mar 27, 2013 at 9:07 AM, Hervé Coatanhay
<herve.coatanhay@...> wrote:
> Ok so I had to remove Predicates.txt form the list of files in
> test_rules.py.

Looks like you've got a lot of work ahead of you.  Lots of stuff is
shallow failures due to reprs, tests not being in Python 3 syntax
(e.g. "print" statements), sorting issues in Python 3 (you can't
compare None to other types), lack of "long" type, set repr being {}
instead of ([]) as in Python 2, etc.

The good news is that a few small changes will fix a lot of errors in
that log.  The bad news is that you must make the changes first,
because these shallow problems are preventing the tests from showing
us what the *real* problems are.

I did however spot one thing that looks like a real problem: it
appears that BytecodeAssembler's use of .tostring() calls should
change to .tobytes(), because the __code__ attribute in Python 3 is a
bytestring.  I think this is causing most of the errors in
Code-Generation.txt.

A few other things I found:

* It appears the codegen module isn't fully importing; it should
export a Repr, but doesn't.  It'd be good to get the actual error
message, if any.
* It appears that certain SLICE_* opcodes have gone away in Python 3;
don't know what they're replaced with.
* Don't bother trying to fix the README and DESIGN errors, or the ones
(Continue reading)

Hervé Coatanhay | 18 Mar 2013 18:56
Picon

trying to run peak-rules on python3

Hi,

I'm trying to port nagare to python3. I managed to run a simple application but I had to make some changes in few PEAK packages.

Here is how I proceeded:
1) run 2to3 on these packages
2) fix remaining "obvious" issue (no more `file` builtin, package renaming, ...)
3) fix types/new/ast changes made in python3
4) remove rules on old-style classes

Here is the code produced by this very naive approach https://bitbucket.org/Alzakath/peak-py3.

As a result, PEAK-Rules seems to work when I only use dispatch on type. But it seems predicate dispatch is not working, for example:

from peak.rules import when

def f(x):
    print('default')

<at> when(f, 'x == 3')
def f(x):
    print("I'm an integer")

f('test')
f(3)


Traceback (most recent call last):
  File "peak-rules_test_ko.py", line 6, in <module>
    <at> when(f, 'x == 3')
  File "/Users/herve/Documents/workspace/nagare/python3-ports/peak-py3/DecoratorTools-1.8/peak/util/decorators.py", line 644, in do_decorate
    frame, getattr(f,'__name__',None), f, frame.f_locals
  File "/Users/herve/Documents/workspace/nagare/python3-ports/peak-py3/PEAK-Rules-0.5a1.dev-r2713/peak/rules/core.py", line 278, in callback
    register_for_class(None)
  File "/Users/herve/Documents/workspace/nagare/python3-ports/peak-py3/PEAK-Rules-0.5a1.dev-r2713/peak/rules/core.py", line 272, in register_for_class
    _register_rule(f, pred, context, cls)
  File "/Users/herve/Documents/workspace/nagare/python3-ports/peak-py3/PEAK-Rules-0.5a1.dev-r2713/peak/rules/core.py", line 398, in _register_rule
    rules.add(parse_rule(Dispatching(gf).engine, pred, context, cls))
  File "/Users/herve/Documents/workspace/nagare/python3-ports/peak-py3/PEAK-Rules-0.5a1.dev-r2713/peak/rules/core.py", line 689, in parse_rule
    def parse_rule(engine, predicate, context, cls):
  File "/Users/herve/Documents/workspace/nagare/python3-ports/peak-py3/PEAK-Rules-0.5a1.dev-r2713/peak/rules/core.py", line 592, in callback
    return f(*args, **kw)
  File "/Users/herve/Documents/workspace/nagare/python3-ports/peak-py3/PEAK-Rules-0.5a1.dev-r2713/peak/rules/core.py", line 952, in parse_upgrade
    from peak.rules.predicates import IndexedEngine
  File "/Users/herve/Documents/workspace/nagare/python3-ports/peak-py3/PEAK-Rules-0.5a1.dev-r2713/peak/rules/predicates.py", line 4, in <module>
    from .criteria import *
  File "/Users/herve/Documents/workspace/nagare/python3-ports/peak-py3/PEAK-Rules-0.5a1.dev-r2713/peak/rules/criteria.py", line 145, in <module>
    inequalities = {
TypeError: nonempty __slots__ not supported for subtype of 'int'

Does anyone tried to port peak-rules to python3 ? Do you have any advice on the right way to do it ? Or even hints on what I'm missing ?

Cheers,
Herve
_______________________________________________
PEAK mailing list
PEAK@...
http://www.eby-sarna.com/mailman/listinfo/peak
Sylvain Prat | 1 Feb 2013 19:19
Picon
Gravatar

Missing pickling support for generic methods

Hello,

I recently encountered a pickling problem with peak.rules. The generic methods do not pickle: they raise a "TypeError: can't pickle lock objects". I've dugg into the code with a colleague and we found that the Dispatching object that registers the implementations of the method is pickled and since it contains a lock, the pickling fails.

It's a little annoying because it prevents us from using generic methods as action callbacks (actions performed when e.g. we click on a link in a web page) in Nagare Web applications because Nagare pickles them in the user session.

I'm not sure how the problem can be fixed. I'm wondering if the Dispatching object should be pickled (or not) and if regenerations have to be triggered on pickling/depickling.

Can someone help? Thanks in advance!

Here is a test case that triggers the problem:

-----

from peak.rules import when
import cPickle as pickle


class Test(object):
    def run(self, arg):
        return 42

    <at> when(run, 'arg == 0')
    def run_3(self, arg):
        return 0


if __name__ == '__main__':
    run = Test().run

    assert run(3) == 42
    assert run(0) == 0

    s = pickle.dumps(run)  # raises a "TypeError: can't pickle lock objects"
    run = pickle.loads(s)

    assert run(3) == 42
    assert run(0) == 0


--
Sylvain PRAT

_______________________________________________
PEAK mailing list
PEAK@...
http://www.eby-sarna.com/mailman/listinfo/peak
Evaldo Gardenali | 7 Dec 2012 16:34
Picon
Favicon

Re: Licensing for DecoratorTools 1.8

Hello,

I am re-sending my request now that I joined the mailing list. Please
advise on licensing.

Regards

Evaldo Gardenali

On Thu, Nov 29, 2012 at 4:03 PM, Evaldo Gardenali
<gardenali@...> wrote:
> Hello Phillip,
>
> I want to use DecoratorTools 1.8, but I cannot find a LICENSE file or
> equivalent in the package. The metadata suggests it is available in
> PSF or ZPL, but does not mention the version of these licenses.
>
> Can you please confirm which licensing terms and which versions of
> those apply to the code?
>
> Regards
>
> Evaldo Gardenali
Alain Poirier | 18 Oct 2012 00:13
Favicon
Gravatar

Re: PEAK-Rules and PyPy

Le 17 oct. 2012 à 00:59, PJ Eby <pje@...> a écrit :

> On Tue, Oct 16, 2012 at 12:48 PM, Alain Poirier
> <alain.poirier@...> wrote:
>> Le 16 oct. 2012 à 18:26, Marcin Tustin <marcin.tustin@...> a
écrit :
>> 
>>> Please see: http://docs.python.org/library/__builtin__.html?highlight=__builtins__
>> 
>> Thanks Marcin. I see from the 'CPython implementation detail' note, '__builtins__'
>> can be a module or a dict. Ok, so I added a check to use '__builtins__.__dict__' if
>> '__builtins__' is a module and now I've got:
>> 
>>>>>> from peak.rules import predicates
>> Traceback (most recent call last):
>>  File "<console>", line 1, in <module>
>>  File "/private/tmp/p/site-packages/DecoratorTools-1.8-py2.7.egg/peak/util/decorators.py",
line 617, in tracer
>>    frm.f_locals[k] = callback(frm,k,v,old_locals)
>>  File "/private/tmp/PEAK-Rules-0.5a1.dev-r2707/peak/rules/core.py", line 276, in callback
>>    register_for_class(None)
>>  File "/private/tmp/PEAK-Rules-0.5a1.dev-r2707/peak/rules/core.py", line 270, in register_for_class
>>    _register_rule(f, pred, context, cls)
>>  File "/private/tmp/PEAK-Rules-0.5a1.dev-r2707/peak/rules/core.py", line 395, in _register_rule
>>    rules.add(parse_rule(Dispatching(gf).engine, pred, context, cls))
>>  File "/private/tmp/PEAK-Rules-0.5a1.dev-r2707/peak/rules/core.py", line 685, in parse_rule
>>    def parse_rule(engine, predicate, context, cls):
>>  File "/private/tmp/PEAK-Rules-0.5a1.dev-r2707/peak/rules/core.py", line 953, in parse_upgrade
>>    predicate, context, cls
>>  File "/private/tmp/PEAK-Rules-0.5a1.dev-r2707/peak/rules/core.py", line 685, in parse_rule
>>    def parse_rule(engine, predicate, context, cls):
>>  File "/private/tmp/PEAK-Rules-0.5a1.dev-r2707/peak/rules/predicates.py", line 606, in _parse_string
>>    maybe_bind(ctx.body, bindings), expr, ctx.actiontype, ctx.sequence
>> UnboundLocalError: local variable 'expr' referenced before assignment
>> 
>> which is strange because 'expr' is just defined some lines above.
>> 
>>> CPython implementation detail: Most modules have the name __builtins__ (note the 's') made available
as part of their globals. The value of__builtins__ is normally either this module or the value of this
modules’s __dict__ attribute. Since this is an implementation detail, it may not be used by alternate
implementations of Python.
>>> 
>>> On Tue, Oct 16, 2012 at 12:22 PM, PJ Eby <pje@...> wrote:
>>> On Tue, Oct 16, 2012 at 11:18 AM, Alain Poirier
>>> <alain.poirier@...> wrote:
>>>>  File "/private/tmp/PEAK-Rules-0.5a1.dev-r2707/peak/rules/predicates.py", line 595, in _parse_string
>>>>    b = CriteriaBuilder(engine.arguments, ctx.localdict, ctx.globaldict, __builtins__)
>>>>  File "/private/tmp/PEAK-Rules-0.5a1.dev-r2707/peak/rules/codegen.py", line 334, in __init__
>>>>    dict([(k,self.Const(v)) for k,v in ns.iteritems()]) for ns in namespaces
>>>> AttributeError: 'module' object has no attribute 'iteritems'
>>>> 
>>>> 
>>>> Do you think it could be possible to have a working PyPy version of Peak Rules?
>>> 
>>> It depends. It looks like the problem above is that __builtins__ in
>>> PyPy might be a module instead of a dictionary?  If so, that's
>>> probably a bug in PyPy that needs to be fixed.
>>> 
>>> There are likely to be other problems besides this one, but let's take
>>> them one at a time.  ;-)
> 
> 
> There are bigger fish to fry - the AddOns package (which is a
> dependency) fails all its tests because PyPy doesn't support
> non-string keys in type dictionaries.  DecoratorTools' test suite also
> fails, but AFAICT it's all due to changes in repr() of various
> built-in types (unless PyPy doesn't support classic classes), and
> should be shallow.  AddOns, however, is quite heavily used by
> PEAK-Rules.
> 
> An important BytecodeAssembler test also fails: PyPy has a
> slightly-incompatible bytecode interpreter, and PEAK-Rules abuses a
> weak link in CPython's bytecode to implement a "computed goto"
> operation in generated bytecode.  My guess is that the UnboundLocal
> errors are being caused by how PyPy handles (or more precisely,
> doesn't handle) the computed goto.
> 
> The specific issue is this: in CPython, the END_FINALLY bytecode takes
> a "why" value on top of the stack, plus an extra value as a jump
> offset.  PyPy, however, wants one value on the stack: a special
> interpreter-owned value (that's AFAICT can't be created directly in
> Python) that wraps the reason and the jump offset together.
> 
> Unless there's some way to create these special SContinueLoop objects
> from Python (and I'm guessing there's not), I'd have to write a
> replacement code generator for PyPy that uses a linear search instead
> -- which ironically may make PyPy's predicate dispatch slower than
> CPython's in some cases, unless the JIT can optimize it out enough.
> 
> [pause for some hacking]
> 
> After hacking around a bit, I have a quick and dirty patch (attached)
> that makes most of the tests pass, by fixing up the __builtins__, and
> handling the END_FINALLY issue by using a linear search in the
> innermost dispatch loops.  It isn't suitable for release at the
> moment, because it doesn't check for whether it's running under PyPy,
> and there are still some tests that fail due to shallow minor issues
> like the PyPy repr() differences and hash iteration differences.  Let
> me know if it works for you, and maybe I'll clean it up for release.

I tested today several applications with predicates dispatch rules, for
web stuffs and complex business workflows and they all ran fine, without
any problem (I didn't yet benchmark them). That's really great, thanks.

Now I can only hope for an official release ;)

> Technically, AddOns and BytecodeAssembler need some fixes too, but the
> parts of them that don't work the same under PyPy don't actually get
> used by PEAK-Rules, at least not in the test suite.

Best regards,
Alain
Alain Poirier | 16 Oct 2012 17:18
Favicon
Gravatar

PEAK-Rules and PyPy

Hi Philip,

Our web framework depends a lot on predicates dispatch (URL routing,
security rules, model/views associations ...). Sadly, trying to run
it on PyPy, it appears Peak Rules is the last dependency not working:

Python 2.7.2 (341e1e3821ff, Jun 07 2012, 15:42:54)
[PyPy 1.9.0 with GCC 4.2.1] on darwin
Type "help", "copyright", "credits" or "license" for more information.
And now for something completely different: ``<arigato> (not thread-safe, but
well, nothing is)''
>>>> from peak.rules import predicates
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/private/tmp/PEAK-Rules-0.5a1.dev-r2707/peak/rules/predicates.py", line 694, in <module>
    when(expressionSignature, "isinstance(expr, Const) and isinstance(expr.value,priority)")
  File "/private/tmp/p/site-packages/DecoratorTools-1.8-py2.7.egg/peak/util/decorators.py",
line 617, in tracer
    frm.f_locals[k] = callback(frm,k,v,old_locals)
  File "/private/tmp/PEAK-Rules-0.5a1.dev-r2707/peak/rules/core.py", line 276, in callback
    register_for_class(None)
  File "/private/tmp/PEAK-Rules-0.5a1.dev-r2707/peak/rules/core.py", line 270, in register_for_class
    _register_rule(f, pred, context, cls)
  File "/private/tmp/PEAK-Rules-0.5a1.dev-r2707/peak/rules/core.py", line 395, in _register_rule
    rules.add(parse_rule(Dispatching(gf).engine, pred, context, cls))
  File "/private/tmp/PEAK-Rules-0.5a1.dev-r2707/peak/rules/core.py", line 685, in parse_rule
    def parse_rule(engine, predicate, context, cls):
  File "/private/tmp/PEAK-Rules-0.5a1.dev-r2707/peak/rules/core.py", line 685, in parse_rule
    def parse_rule(engine, predicate, context, cls):
  File "/private/tmp/PEAK-Rules-0.5a1.dev-r2707/peak/rules/core.py", line 589, in callback
    return f(*args, **kw)
  File "/private/tmp/PEAK-Rules-0.5a1.dev-r2707/peak/rules/core.py", line 953, in parse_upgrade
    predicate, context, cls
  File "/private/tmp/PEAK-Rules-0.5a1.dev-r2707/peak/rules/core.py", line 685, in parse_rule
    def parse_rule(engine, predicate, context, cls):
  File "/private/tmp/PEAK-Rules-0.5a1.dev-r2707/peak/rules/core.py", line 589, in callback
    return f(*args, **kw)
  File "/private/tmp/PEAK-Rules-0.5a1.dev-r2707/peak/rules/predicates.py", line 595, in _parse_string
    b = CriteriaBuilder(engine.arguments, ctx.localdict, ctx.globaldict, __builtins__)
  File "/private/tmp/PEAK-Rules-0.5a1.dev-r2707/peak/rules/codegen.py", line 334, in __init__
    dict([(k,self.Const(v)) for k,v in ns.iteritems()]) for ns in namespaces
AttributeError: 'module' object has no attribute 'iteritems'

Do you think it could be possible to have a working PyPy version of Peak Rules?

Best regards,
Alain
Athanasios Anastasiou | 16 Jul 2012 18:56
Picon
Favicon

Inheritance and <at> when from PEAK-rules

Hello everyone

I have been using PEAK-rules with functions but i came across some 
strange behaviour when it came to using it with classes and inherited 
methods.

The problem (in one line) is that i find it difficult to get  <at> when to 
call the "right" (overriden) function.

I wish to define an abstract class with a number of calls depending on 
the type of the parameters once and then modify the functionality of 
derived handlers later depending on what each handler is supposed to be 
doing.

What i am doing at the time is roughly this:

class someAbstractClass(object):
	def theFunPrototype(self,p1,p2,p3):
		print "Abstract call - unhandled %s %s %s" % (type(p1),type(p2),type(p3))

	 <at> when(theFunPrototype, (int,int,int))
	def _theFunProtoForInts(self,p1,p2,p3):
		print "All three parameters are integers"

	 <at> when(theFunPrototype, (int,int,str))
	def _theFunProtoForIntStr(self,p1,p2,p3):
		print "Two integers and one string"

class someConcreteClass(someAbstractClass):
	def _theFunProtoForInts(self,p1,p2,p3):
		print "Overriden handler %s %s %s" % (p1,p2,p3)

someConcreteClass().theFunPrototype(5,6,7) will execute the 
someAbstractClass' method. If i wanted this thing to work as expected, i 
would have to override a "dummy" theFunPrototype which would call its 
corresponding "super" and add a  <at> when on the derived 
"_theFunProtoForInts" but this seems a bit like duplicating the exact 
same thing on the derived class without any reason...Since both classes 
share a _theFunPrototypeForInts, the right behaviour would be to call 
the derived class....(or maybe not? :-) ).

Any ideas about where i could be going wrong?

Looking forward to hearing from you
Athanasios Anastasiou
Marcin Tustin | 23 May 2012 16:39
Picon
Gravatar

ObjectWrapper subclasses always callable

I've found that instances of ObjectWrapper (and any subclasses) are always callable (the callable function returns True), notwithstanding that the __subject__ is not callable. Is there a way to remedy this?


I've tried deleting the __call__ method, creating empty slots, creating my own call method, then trying to delete, using del or delattr on the subclass object, and creating a custom __getattribute__, all to no avail. 


--
Marcin Tustin
Tel: 07773 787 105

_______________________________________________
PEAK mailing list
PEAK@...
http://www.eby-sarna.com/mailman/listinfo/peak
nicky van foreest | 23 Oct 2011 23:34
Picon

peak/utils/addons import problem

Hi,

I updated my ubuntu version just now, and it broke my working trellis
installation. Yesterday everything worked just fine. Does anybody have
an idea what might be wrong? I did not change my pythonpath, or
anything else. I also tried reinstalling trellis, but to no avail.

Thanks in advance

Nicky

PS. Some things I checked:

in ipython the auto-completion on from peak.events works. Apparently,
python can find peak.events. However, from peak.utils fails.

nicky <at> chuck:~/lib/python$ cat easy-install.pth
import sys; sys.__plen = len(sys.path)
./Trellis-0.7a2
./Contextual-0.7a1.dev_r2695-py2.7.egg
./DecoratorTools-1.8-py2.7.egg
./AddOns-0.7-py2.7.egg
./SymbolType-1.0-py2.7.egg
import sys; new=sys.path[sys.__plen:]; del sys.path[sys.__plen:];
p=getattr(sys,'__egginsert',0); sys.path[p:p]=new; sys.__egginsert =
p+len(new)

nicky <at> chuck:~/lib/python$ env |grep PY
PYTHONPATH=/home/nicky/myprogs/python/:/home/nicky/lib/python/:.

nicky <at> chuck:~/lib/python$ python
Python 2.7.2+ (default, Oct  4 2011, 20:06:09)
[GCC 4.6.1] on linux2
nicky van foreest | 2 Oct 2011 20:17
Picon

Re: trellis attrs

Thanks for the ref.

NIcky

On 2 October 2011 07:50, Jean Jordaan <jean.jordaan@...> wrote:
>> I never read about python descriptors before, and even didn't know
>> such a thing exists. Do you perhaps of one particular book/source that
>> can be of help in this direction?
>
> This is probably a good start:
>  http://docs.python.org/howto/descriptor.html
>
> --
> jean                                              . .. .... //\\\oo///\\
>

Gmane