Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions language-analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,24 @@

import time
import grpc

from lookout.sdk import AnalyzerServicer, add_analyzer_to_server
from lookout.sdk import service_analyzer_pb2
from lookout.sdk import service_data_pb2_grpc
from lookout.sdk import service_data_pb2
from lookout.sdk.grpc import to_grpc_address, create_channel
from lookout.sdk import pb

from bblfsh import filter as filter_uast

port_to_listen = 2021
data_srv_addr = to_grpc_address("ipv4://localhost:10301")
data_srv_addr = pb.to_grpc_address("ipv4://localhost:10301")
version = "alpha"


class Analyzer(AnalyzerServicer):
class Analyzer(pb.AnalyzerServicer):
def NotifyReviewEvent(self, request, context):
print("got review request {}".format(request))

# client connection to DataServe
channel = create_channel(data_srv_addr)
stub = service_data_pb2_grpc.DataStub(channel)
channel = pb.create_channel(data_srv_addr)
stub = pb.DataStub(channel)
changes = stub.GetChanges(
service_data_pb2.ChangesRequest(
pb.ChangesRequest(
head=request.commit_revision.head,
base=request.commit_revision.base,
want_contents=False,
Expand All @@ -47,19 +42,19 @@ def NotifyReviewEvent(self, request, context):
change.head.path, change.head.language))
fns = list(filter_uast(change.head.uast, "//*[@roleFunction]"))
comments.append(
service_analyzer_pb2.Comment(
pb.Comment(
file=change.head.path,
line=0,
text="language: {}, functions: {}".format(change.head.language, len(fns))))
return service_analyzer_pb2.EventResponse(analyzer_version=version, comments=comments)
return pb.EventResponse(analyzer_version=version, comments=comments)

def NotifyPushEvent(self, request, context):
pass


def serve():
server = grpc.server(thread_pool=ThreadPoolExecutor(max_workers=10))
add_analyzer_to_server(Analyzer(), server)
pb.add_analyzer_to_server(Analyzer(), server)
server.add_insecure_port("0.0.0.0:{}".format(port_to_listen))
server.start()

Expand Down
3 changes: 0 additions & 3 deletions python/lookout/sdk/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
# re-export using pythonic names
from lookout.sdk.service_analyzer_pb2_grpc import \
AnalyzerServicer, add_AnalyzerServicer_to_server as add_analyzer_to_server
14 changes: 14 additions & 0 deletions python/lookout/sdk/pb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""
Re-exporting all grpc related classes/functions for cleaner API
"""

from .service_analyzer_pb2_grpc import \
AnalyzerServicer, add_AnalyzerServicer_to_server as add_analyzer_to_server
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AnalyzerServicer does not need to be imported here. Sorry - I should have spotted this earlier!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. Leftover after copy-past. Thank you!


from .event_pb2_grpc import *
from .event_pb2 import *
from .grpc import *
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we separate our code from autogenerated one? I would rather explicitly import this:

from lookout.sdk.pb import AnalyzerServicer
from lookout.sdk.grpc import to_grpc_address

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in 03c4166

from .service_analyzer_pb2_grpc import *
from .service_analyzer_pb2 import *
from .service_data_pb2_grpc import *
from .service_data_pb2 import *