Note: This was previously filed as SeattleTestbed/repy_v2#70, but is not a problem of Repy. I slightly update / summarize the description here.
Calls can be added to the RepyV2 API by editing namespace.py. Unfortunately, libraries that are dylinked in do not get immediate access to new API calls unless dylink.r2py is also modified so that its understanding of STOCK_API includes the added call's name. Otherwise, a NameError is raised.
# Assume that your Repy API defines the call below.
# Importing this program as a library in another
# program causes a NameError.
new_repy_api_function_that_is_not_in_dylink_stock_api()
To confuse matters, the NameError is only present when that code is dylinked in from another program. You can directly run it just fine, and it's also fine to run it as the main program under dylink, i.e. repy.py restrictionsfile dylink.r2py that_code.r2py.
Instead of requiring manual changes triggered by peculiar-to-obscure error conditions, we can change dylink to just introspect its execution context (_context) and recreate STOCK_API from all the objects of type 'instancemethod'.
The reason for this seemingly weird type is that the Repy API functions are not visible as Python function types, but bound methods NamespaceAPIFunctionWrapper.wrapped_function. A template method for comparison may be created like so:
class A():
def b():
pass
a = A()
type(a.b) # <type 'instancemethod'>
Note: This was previously filed as SeattleTestbed/repy_v2#70, but is not a problem of Repy. I slightly update / summarize the description here.
Calls can be added to the RepyV2 API by editing
namespace.py. Unfortunately, libraries that aredylinked in do not get immediate access to new API calls unlessdylink.r2pyis also modified so that its understanding ofSTOCK_APIincludes the added call's name. Otherwise, aNameErroris raised.To confuse matters, the
NameErroris only present when that code isdylinked in from another program. You can directly run it just fine, and it's also fine to run it as the main program underdylink, i.e.repy.py restrictionsfile dylink.r2py that_code.r2py.Instead of requiring manual changes triggered by peculiar-to-obscure error conditions, we can change
dylinkto just introspect its execution context (_context) and recreateSTOCK_APIfrom all the objects oftype 'instancemethod'.The reason for this seemingly weird type is that the Repy API functions are not visible as Python
functiontypes, but bound methodsNamespaceAPIFunctionWrapper.wrapped_function. A template method for comparison may be created like so: