lookout.core.data_requests

Module Contents

exception lookout.core.data_requests.UnsatisfiedDriverVersionError(mismatched:Iterable[Tuple[str, str]])

Bases:Exception

Exception which is raised if there is a mismatching Babelfish driver version.

class lookout.core.data_requests.DataService(address:str)

Retrieves UASTs/files from the Lookout server.

get_data(self)

Return a DataStub for the current thread.

get_bblfsh(self)

Return a Babelfish ProtocolServiceStub for the current thread.

check_bblfsh_driver_versions(self, versions:Iterable[str])

Ensure that the Babelfish drivers match the required versions.

The check is performed by packaging.version.

Parameters:versions – setup.py-like version specifiers, e.g. “javascript==1.3.0”.
Returns:Nothing
Raises:UnsatisfiedDriverVersionError – if there is one or more mismatches.
shutdown(self)

Close all the open network connections.

close_channel(self)

Close the current channel and free all the associated resources.

lookout.core.data_requests.handle_analyze_rpc_errors(func)

Decorator to properly handle rps errors that is close related DataService channel before pass the exception.

Parameters:func – Method to decorate.
Returns:The decorated method.
lookout.core.data_requests.with_changed_uasts(unicode:bool)

Decorator to provide “changes” keyword argument to **data in Analyzer.analyze().

“changes” contain the list of Change - see lookout/core/server/sdk/service_data.proto. The changes will have only UASTs, no raw file contents. Decorated method should have a signature compatible with Analyzer.analyze().

Parameters:unicode – Value indicating whether content and UAST positions should be converted to Unicode. False keeps DataService response untouched.
Returns:The decorated method.
lookout.core.data_requests.with_changed_contents(unicode:bool)

Decorator to provide “changes” keyword argument to **data in Analyzer.analyze().

“changes” contain the list of Change - see lookout/core/server/sdk/service_data.proto. The changes will have only raw file contents, no UASTs. Decorated method should have a signature compatible with Analyzer.analyze().

Parameters:unicode – Value indicating whether content and UAST positions should be converted to Unicode. False keeps DataService response untouched.
Returns:The decorated method.
lookout.core.data_requests.with_changed_uasts_and_contents(unicode:bool)

Decorator to provide “changes” keyword argument to **data in Analyzer.analyze().

“changes” contain the list of Change - see lookout/core/server/sdk/service_data.proto. The changes will have both UASTs and raw file contents. Decorated method should have a signature compatible with Analyzer.analyze().

Parameters:unicode – Value indicating whether content and UAST positions should be converted to Unicode. False keeps DataService response untouched.
Returns:The decorated method.
lookout.core.data_requests.with_uasts(unicode:bool)

Decorator to provide “files” keyword argument to **data in Analyzer.train(). They only contain the UASTs.

“files” are the list of File-s with all the data for the passed Git repository URL and revision, see lookout/core/server/sdk/service_data.proto. Decorated method should have a signature compatible with Analyzer.train().

Parameters:unicode – Value indicating whether content and UAST positions should be converted to Unicode. False keeps DataService response untouched.
Returns:The decorated method.
lookout.core.data_requests.with_contents(unicode:bool)

Decorator to provide “files” keyword argument to **data in Analyzer.train(). They only contain the raw file contents.

“files” are the list of File-s with all the data for the passed Git repository URL and revision, see lookout/core/server/sdk/service_data.proto. Decorated method should have a signature compatible with Analyzer.train().

Parameters:unicode – Value indicating whether content and UAST positions should be converted to Unicode. False keeps DataService response untouched.
Returns:The decorated method.
lookout.core.data_requests.with_uasts_and_contents(unicode:bool)

Decorator to provide “files” keyword argument to **data in Analyzer.train(). They contain both the raw file contents and the UASTs.

“files” are the list of File-s with all the UASTs and raw file contents for the passed Git repository URL and revision, see lookout/core/server/sdk/service_data.proto. Decorated method should have a signature compatible with Analyzer.train().

Parameters:unicode – Value indicating whether content and UAST positions should be converted to Unicode. False keeps DataService response untouched.
Returns:The decorated method.
lookout.core.data_requests.request_changes(stub:DataStub, ptr_from:ReferencePointer, ptr_to:ReferencePointer, contents:bool, uast:bool, unicode:bool)

Invoke GRPC API and get the changes. Used by with_changed_uasts() and Review events.

Returns:The stream of the gRPC invocation results. In theory, .result() would turn this into a synchronous call, but in practice, that function call hangs for some reason.
lookout.core.data_requests.request_files(stub:DataStub, ptr:ReferencePointer, contents:bool, uast:bool, unicode:bool)

Invoke GRPC API and get the files. Used by with_uasts() and Push events.

Returns:The stream of the gRPC invocation results.
lookout.core.data_requests.parse_uast(stub:bblfsh.aliases.ProtocolServiceStub, code:str, filename:str, unicode:bool, language:Optional[str]=None)

Return UAST for given file contents and name.

Parameters:
  • stub – The Babelfish protocol stub.
  • code – The contents of the file.
  • filename – The name of the file, can be a full path.
  • language – The name of the language. It is not required to set: Babelfish can autodetect it.
  • unicode – Set to True if UAST position information should be converted to unicode positions.
Returns:

The parsed UAST or undefined object if there was an error; the list of parsing errors.