lanto03 / couchdb-python

Automatically exported from code.google.com/p/couchdb-python
Other
0 stars 0 forks source link

patch to use function objects in python views #44

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hi, I think it'd be useful if the TemporaryView and ViewDefinition classes 
could accept function 
objects for the map and reduce phases of a Python view.  I'm attaching a patch 
that uses 
inspect.getsource() to accomplish this.  Best,

Adam

Original issue reported on code.google.com by adam.kocoloski@gmail.com on 22 Dec 2008 at 5:08

Attachments:

GoogleCodeExporter commented 8 years ago
adam, thanks for your patch.
Unfortunately, there is a problem with the patch as it is.
inspect.getsource() only works for a function which is defined in a source file 
on
disk and just because isinstance(fun, FunctionType) is true doesn't mean 
getsource()
won't throw an exception.

However, I can't imagine a situation where practically speaking one would pass a
function object that wasn't from a source file. If you had the raw code to 
begin with
you could just pass it along without compiling it to a function object.

I'm accepting this and assigning it to myself. I'll play around with it.

In the meantime, a workaround if you want to run views which are defined in .py 
files
is to install your .py files into your python library for the environment the 
view
server runs in and pass the string "from module import map_fun" for the map 
function.

Original comment by randall....@gmail.com on 28 Feb 2009 at 4:48

GoogleCodeExporter commented 8 years ago
Randall, I have this patch integrated in my working copy already, and have even 
added some decorator fu. I'll 
check in after some more testing.

Original comment by cmlenz on 28 Feb 2009 at 12:18

GoogleCodeExporter commented 8 years ago
Patch plus decorator support checked in in r136.

Original comment by cmlenz on 9 Mar 2009 at 9:39