merlimat closed pull request #1375: Moved Python Api to a functions module 
inside pulsar client python module
URL: https://github.com/apache/incubator-pulsar/pull/1375
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/pulsar-functions/api-python/__init__.py 
b/pulsar-client-cpp/python/functions/__init__.py
similarity index 96%
rename from pulsar-functions/api-python/__init__.py
rename to pulsar-client-cpp/python/functions/__init__.py
index d70b15fbd..b14a93244 100644
--- a/pulsar-functions/api-python/__init__.py
+++ b/pulsar-client-cpp/python/functions/__init__.py
@@ -18,4 +18,4 @@
 # under the License.
 #
 
-# -*- encoding: utf-8 -*-
\ No newline at end of file
+# -*- encoding: utf-8 -*-
diff --git a/pulsar-functions/api-python/context.py 
b/pulsar-client-cpp/python/functions/context.py
similarity index 100%
rename from pulsar-functions/api-python/context.py
rename to pulsar-client-cpp/python/functions/context.py
diff --git a/pulsar-functions/api-python/pulsar_function.py 
b/pulsar-client-cpp/python/functions/function.py
similarity index 93%
rename from pulsar-functions/api-python/pulsar_function.py
rename to pulsar-client-cpp/python/functions/function.py
index 1226dd4c0..dde92b8a5 100644
--- a/pulsar-functions/api-python/pulsar_function.py
+++ b/pulsar-client-cpp/python/functions/function.py
@@ -37,15 +37,15 @@
 # specific language governing permissions and limitations
 # under the License.
 #
-"""pulsar_function.py: This is the core interface of the function api.
+"""function.py: This is the core interface of the function api.
 # The process method is called for every message of the input topic of the
 # function. The incoming input bytes are deserialized using the serde.
 # The process function can optionally emit an output
 """
 from abc import abstractmethod
 
-class PulsarFunction(object):
-  """Interface for Heron Metric"""
+class Function(object):
+  """Interface for Pulsar Function"""
   @abstractmethod
   def process(self, input, context):
     """Process input message"""
diff --git a/pulsar-functions/api-python/serde.py 
b/pulsar-client-cpp/python/functions/serde.py
similarity index 100%
rename from pulsar-functions/api-python/serde.py
rename to pulsar-client-cpp/python/functions/serde.py
diff --git a/pulsar-client-cpp/python/pulsar.py 
b/pulsar-client-cpp/python/pulsar.py
index a4c6c8798..b6e5faf2b 100644
--- a/pulsar-client-cpp/python/pulsar.py
+++ b/pulsar-client-cpp/python/pulsar.py
@@ -103,6 +103,9 @@ def send_callback(res, msg):
 
 from _pulsar import Result, CompressionType, ConsumerType, 
PartitionsRoutingMode  # noqa: F401
 
+from functions.function import Function
+from functions.context import Context
+from functions.serde import SerDe, IdentitySerDe, PickleSerDe
 
 class MessageId:
     """
diff --git a/pulsar-functions/instance/src/main/python/contextimpl.py 
b/pulsar-functions/instance/src/main/python/contextimpl.py
index b02142150..6a3a5dae2 100644
--- a/pulsar-functions/instance/src/main/python/contextimpl.py
+++ b/pulsar-functions/instance/src/main/python/contextimpl.py
@@ -26,7 +26,7 @@
 import time
 import os
 
-from pulsarfunction import context
+import pulsar
 import util
 import InstanceCommunication_pb2
 
@@ -46,7 +46,7 @@ def record(self, value):
     if value < self.min:
       self.min = value
 
-class ContextImpl(context.Context):
+class ContextImpl(pulsar.Context):
   def __init__(self, instance_config, logger, pulsar_client, user_code, 
consumers):
     self.instance_config = instance_config
     self.log = logger
diff --git a/pulsar-functions/instance/src/main/python/python_instance_main.py 
b/pulsar-functions/instance/src/main/python/python_instance_main.py
index 4fe164196..0bf02b072 100644
--- a/pulsar-functions/instance/src/main/python/python_instance_main.py
+++ b/pulsar-functions/instance/src/main/python/python_instance_main.py
@@ -51,7 +51,7 @@ def main():
   signal.signal(signal.SIGHUP, atexit_function)
   signal.signal(signal.SIGINT, atexit_function)
 
-  parser = argparse.ArgumentParser(description='Heron Python Instance')
+  parser = argparse.ArgumentParser(description='Pulsar Functions Python 
Instance')
   parser.add_argument('--function_classname', required=True, help='Function 
Class Name')
   parser.add_argument('--py', required=True, help='Full Path of Function Code 
File')
   parser.add_argument('--name', required=True, help='Function Name')
diff --git a/pulsar-functions/instance/src/main/python/util.py 
b/pulsar-functions/instance/src/main/python/util.py
index efa238dee..643cbacc7 100644
--- a/pulsar-functions/instance/src/main/python/util.py
+++ b/pulsar-functions/instance/src/main/python/util.py
@@ -29,7 +29,7 @@
 import log
 
 Log = log.Log
-PULSARFUNCTIONAPIROOT = 'pulsarfunction'
+PULSARFUNCTIONAPIROOT = 'functions'
 
 def import_class(from_path, full_class_name):
   kclass = import_class_from_path(from_path, full_class_name)
diff --git a/pulsar-functions/python-examples/exclamation.py 
b/pulsar-functions/python-examples/exclamation.py
index d67ede9b1..d8a14f76f 100755
--- a/pulsar-functions/python-examples/exclamation.py
+++ b/pulsar-functions/python-examples/exclamation.py
@@ -19,9 +19,9 @@
 #
 
 
-from pulsarfunction import pulsar_function
+from pulsar import Function
 
-class Exclamation(pulsar_function.PulsarFunction):
+class Exclamation(Function):
   def __init__(self):
     pass
 
diff --git a/pulsar-functions/python-examples/logfunction.py 
b/pulsar-functions/python-examples/logfunction.py
index 4c59124c6..504cdc521 100755
--- a/pulsar-functions/python-examples/logfunction.py
+++ b/pulsar-functions/python-examples/logfunction.py
@@ -19,9 +19,9 @@
 #
 
 
-from pulsarfunction import pulsar_function
+from pulsar import Function
 
-class LogFunction(pulsar_function.PulsarFunction):
+class LogFunction(Function):
   def __init__(self):
     pass
 
diff --git a/pulsar-functions/python-examples/thumbnailer.py 
b/pulsar-functions/python-examples/thumbnailer.py
index f5124cacb..3448aac0e 100755
--- a/pulsar-functions/python-examples/thumbnailer.py
+++ b/pulsar-functions/python-examples/thumbnailer.py
@@ -18,10 +18,10 @@
 # under the License.
 #
 
-from pulsarfunction import pulsar_function
+from pulsar import Function
 from PIL import Image
 
-class Thumbnailer(pulsar_function.PulsarFunction):
+class Thumbnailer(Function):
 
   def process(self, input, context):
     im = Image.frombytes(input)
diff --git a/pulsar-functions/runtime/pom.xml b/pulsar-functions/runtime/pom.xml
index b67118252..4b2f16f12 100644
--- a/pulsar-functions/runtime/pom.xml
+++ b/pulsar-functions/runtime/pom.xml
@@ -70,9 +70,8 @@
               <tasks>
                 <echo>building python instance</echo>
                 <mkdir dir="${basedir}/target/python-instance"/>
-                <mkdir dir="${basedir}/target/python-instance/pulsarfunction"/>
                 <copydir src="${basedir}/../instance/src/main/python" 
dest="${basedir}/target/python-instance"/>
-                <copydir src="${basedir}/../api-python" 
dest="${basedir}/target/python-instance/pulsarfunction"/>
+                <copydir src="${basedir}/../../pulsar-client-cpp/python" 
dest="${basedir}/target/python-instance"/>
               </tasks>
             </configuration>
           </execution>


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to