Hi all,

I've just checked in code to support SCA clients written in Python and
references in Python components.

The updated PythonCalculator sample under
http://svn.apache.org/repos/asf/incubator/tuscany/cpp/sca/samples/PythonCalculator<http://svn.apache.org/repos/asf/incubator/tuscany/cpp/sca/samples/RubyCalculator/sample.calculator/>
shows the programming model:

- A client can get a proxy to a service with:
import TuscanySCA
and
calculator = TuscanySCA.locateService
("CalculatorComponent/CalculatorService")

- You then simply call a business method on "calculator", like this:
x = calculator.add(1, 2)

- References are automatically added to your Python component implementation
when the runtime loads the implementation script, so they can be used like
so:

# The module-level div function
def div(val1, val2):
   # Use the divideService reference
   result = divideService.divide(val1, val2)
   return result

and in your composite file:
 <component name="CalculatorComponent">
    <implementation.python module="CalculatorImpl" scope="composite"/>
    <reference
name="divideService">DivideComponent/DivideService</reference>
</component>

- Due to the current requirement of a componentType file, I have implemented
an empty interface.python interface extension (rather than expecting people
to use interface.cpp or something. So a .componentType file would look like:

<componentType xmlns="http://www.osoa.org/xmlns/sca/1.0";>
   <service name="CalculatorService">
       <interface.python/>
   </service>
   <reference name="divideService">
       <interface.python/>
   </reference>
</componentType>

- The client and reference support comes from a Python extension package
that is installed into the Python environment, making the TuscanySCA and
TuscanySCAProxy modules available for all python scripts.

- Next up is properties support - this should be pretty easy.

- Further work would be to look at annotations, to avoid the need for the
.componentType files at all.

The code for the Tuscany/C++ Python extension is here:
http://svn.apache.org/repos/asf/incubator/tuscany/cpp/sca/runtime/extensions/python<http://svn.apache.org/repos/asf/incubator/tuscany/cpp/sca/runtime/extensions/ruby/>

It builds and runs fine on Windows (remember to have the PYTHON_HOME env
variable set to your Python insallation dir), but hasn't been tested or
built on Linux. I have updated the automake files but I don't know how to
add in the commands to build and install the Python extension into Python.
The commands required are:

cd tuscany/cpp/sca/runtime/extensions/python/src/tuscany/sca/python
python TuscanySCASetup.py build
python TuscanySCASetup.py install

If someone who knows automake could add these in and test it out that would
be great!

Cheers

Andy

Reply via email to