Conversation
8261434 to
137c429
Compare
It is capable of fetching UASTs
bblfsh/channel.py
Outdated
| self._channel = grpc.insecure_channel(endpoint) | ||
| self._stub = ProtocolServiceStub(self._channel) | ||
|
|
||
| def fetch_uast(self, file_path, language, contents=None): |
There was a problem hiding this comment.
Note that language could also be None by default for autodetection.
bblfsh/__main__.py
Outdated
| help="bblfsh gRPC endpoint.") | ||
| parser.add_argument("-f", "--file", required=True, | ||
| help="File to parse.") | ||
| parser.add_argument("-l", "--language", required=True, |
There was a problem hiding this comment.
This could be optional for autodetection
| -I github.com/bblfsh/sdk/protocol -I $(makefile_dir) \ | ||
| github.com/bblfsh/sdk/protocol/generated.proto | ||
|
|
||
| %/__init__.py: |
There was a problem hiding this comment.
(non blocking) another option would be to add a first level __init__ with an import hook that knows how to do the rest, but this does the job perfectly too.
There was a problem hiding this comment.
This is very hacky too.
There was a problem hiding this comment.
It is but done well it could be more generic/automatic for other use cases of this gRPC module.
bblfsh/test.py
Outdated
| self.client = BblfshClient("0.0.0.0:9432") | ||
|
|
||
| def testUAST(self): | ||
| uast = self.client.fetch_uast(__file__, "Python") |
There was a problem hiding this comment.
uast in this case is a response object more than a UAST that would be part of it, I'm right? In that case it should probably check for errors in the response (response.errors and/or response.status).
bblfsh/test.py
Outdated
| @classmethod | ||
| def setUpClass(cls): | ||
| subprocess.check_call( | ||
| "docker run --privileged -p 9432:9432 --name bblfsh -d " |
There was a problem hiding this comment.
Ideally we would have to mock the server to avoid this external dependency on the test, but this should serve for now.
|
Update: now it launches the Babelfish server if it is not running (can be disabled). |
bblfsh/client.py
Outdated
| self._channel = grpc.insecure_channel(endpoint) | ||
| self._stub = ProtocolServiceStub(self._channel) | ||
|
|
||
| def fetch_uast(self, file_path, language=None, contents=None): |
There was a problem hiding this comment.
Please, call this parse_uast so that it matches the protocol as much as possible.
There was a problem hiding this comment.
Also rename file_path to filename so it matches too.
| from bblfsh.github.com.bblfsh.sdk.protocol.generated_pb2_grpc import ProtocolServiceStub | ||
|
|
||
|
|
||
| class BblfshClient(object): |
There was a problem hiding this comment.
I think this should have a method to close the client and the underlying connection.
Maybe close()? I'm not sure that's Python's convention. Also, __enter__ and __exit__ so it works with with?
There was a problem hiding this comment.
There is no close(). Python does it automatically without ResourceWarning-s. Even the Python grpc primer does not close anything: http://www.grpc.io/docs/tutorials/basic/python.html
There was a problem hiding this comment.
|
@smola Fixed! |
It is capable of fetching UASTs