Skip to content

Remove grpc imports from init and add pb package #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 5, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
18 changes: 7 additions & 11 deletions language-analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@

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 import pb
from lookout.sdk.grpc import to_grpc_address, create_channel

from bblfsh import filter as filter_uast
Expand All @@ -23,15 +19,15 @@
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)
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 +43,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
13 changes: 13 additions & 0 deletions python/lookout/sdk/pb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""
Re-exporting all grpc related classes/functions for cleaner API
"""

from .service_analyzer_pb2_grpc import \
add_AnalyzerServicer_to_server as add_analyzer_to_server

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