Skip to content
This repository was archived by the owner on Mar 8, 2020. It is now read-only.

Commit 350a18a

Browse files
kuba--ncordon
authored andcommitted
Add supported languages with aliases
Signed-off-by: kuba-- <kuba@sourced.tech>
1 parent 1078cf5 commit 350a18a

5 files changed

Lines changed: 98 additions & 22 deletions

File tree

bblfsh/aliases.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"bblfsh.gopkg.in.bblfsh.sdk.v2.protocol.generated_pb2")
1010
protocol_grpc_v2_module = importlib.import_module(
1111
"bblfsh.gopkg.in.bblfsh.sdk.v2.protocol.generated_pb2_grpc")
12+
1213
protocol_v1_module = importlib.import_module(
1314
"bblfsh.gopkg.in.bblfsh.sdk.v1.protocol.generated_pb2")
1415
protocol_grpc_v1_module = importlib.import_module(
@@ -20,7 +21,7 @@
2021
ParseError = protocol_v2_module.ParseError
2122
Mode = protocol_v2_module.Mode
2223
ModeType = google.protobuf.internal.enum_type_wrapper.EnumTypeWrapper
23-
24+
Manifest = protocol_v2_module.Manifest
2425

2526
class Modes:
2627
pass
@@ -30,10 +31,16 @@ class Modes:
3031
setattr(Modes, k, v.number)
3132

3233
DriverStub = protocol_grpc_v2_module.DriverStub
33-
DriverServicer = protocol_grpc_v2_module.DriverServicer
34+
DriverHostStub = protocol_grpc_v2_module.DriverHostStub
35+
36+
ProtocolServiceStub = protocol_grpc_v1_module.ProtocolServiceStub
3437

3538
VersionRequest = protocol_v1_module.VersionRequest
3639
VersionResponse = protocol_v1_module.VersionResponse
3740
SupportedLanguagesRequest = protocol_v1_module.SupportedLanguagesRequest
3841
SupportedLanguagesResponse = protocol_v1_module.SupportedLanguagesResponse
39-
ProtocolServiceStub = protocol_grpc_v1_module.ProtocolServiceStub
42+
43+
VersionRequestV2 = protocol_v2_module.VersionRequest
44+
VersionResponseV2 = protocol_v2_module.VersionResponse
45+
SupportedLanguagesRequestV2 = protocol_v2_module.SupportedLanguagesRequest
46+
SupportedLanguagesResponseV2 = protocol_v2_module.SupportedLanguagesResponse

bblfsh/client.py

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,21 @@
33

44
import grpc
55

6-
from bblfsh.aliases import (ParseRequest, DriverStub, ProtocolServiceStub,
7-
VersionRequest, SupportedLanguagesRequest, ModeType,
8-
VersionResponse)
6+
from bblfsh.aliases import (
7+
ParseRequest,
8+
DriverStub,
9+
DriverHostStub,
10+
ProtocolServiceStub,
11+
VersionRequest,
12+
VersionRequestV2,
13+
SupportedLanguagesRequest,
14+
SupportedLanguagesRequestV2,
15+
ModeType,
16+
VersionResponse,
17+
VersionResponseV2,
18+
Manifest
19+
)
20+
921
from bblfsh.result_context import ResultContext
1022

1123

@@ -34,6 +46,7 @@ def __init__(self, endpoint: Union[str, grpc.Channel]) -> None:
3446

3547
self._stub_v1 = ProtocolServiceStub(self._channel)
3648
self._stub_v2 = DriverStub(self._channel)
49+
self._hoststub_v2 = DriverHostStub(self._channel)
3750

3851
@staticmethod
3952
def _ensure_utf8(text: bytes) -> str:
@@ -91,6 +104,10 @@ def supported_languages(self) -> List[str]:
91104
sup_response = self._stub_v1.SupportedLanguages(SupportedLanguagesRequest())
92105
return sup_response.languages
93106

107+
def supported_language_manifests(self) -> List[Manifest]:
108+
sup_response = self._hoststub_v2.SupportedLanguages(SupportedLanguagesRequestV2())
109+
return sup_response.languages
110+
94111
def version(self) -> VersionResponse:
95112
"""
96113
Queries the Babelfish server for version and runtime information.
@@ -100,6 +117,16 @@ def version(self) -> VersionResponse:
100117
"""
101118
return self._stub_v1.Version(VersionRequest())
102119

120+
def server_version(self) -> VersionResponseV2:
121+
"""
122+
Queries the Babelfish server for version information.
123+
124+
:return: A VersionResponse class contains a "version" dictionary
125+
with the keys "version" for the semantic version
126+
and "build" for the build timestamp.
127+
"""
128+
return self._hoststub_v2.ServerVersion(VersionRequestV2())
129+
103130
@staticmethod
104131
def _scramble_language(lang: Optional[str]) -> Optional[str]:
105132
# TODO: remove once aliases are integrated
@@ -117,4 +144,4 @@ def close(self) -> None:
117144
not supported.
118145
"""
119146
self._channel.close()
120-
self._channel = self._stub_v1 = self._stub_v2 = None
147+
self._channel = self._stub_v1 = self._stub_v2 = self._hoststub_v2 = None

bblfsh/test.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,19 @@ def _parse_fixture(self) -> ResultContext:
4141

4242
def testVersion(self) -> None:
4343
version = self.client.version()
44+
4445
self.assertTrue(hasattr(version, "version"))
4546
self.assertTrue(version.version)
4647
self.assertTrue(hasattr(version, "build"))
4748
self.assertTrue(version.build)
4849

50+
def testServerVersion(self) -> None:
51+
version = self.client.server_version().version
52+
53+
self.assertTrue(hasattr(version, "version"))
54+
self.assertTrue(version.version)
55+
self.assertTrue(hasattr(version, "build"))
56+
4957
def testNativeParse(self) -> None:
5058
ctx = self.client.parse(self.fixtures_pyfile, mode=Modes.NATIVE)
5159
self._validate_ctx(ctx)
@@ -405,6 +413,18 @@ def testSupportedLanguages(self) -> None:
405413
self.assertTrue(hasattr(l, key))
406414
self.assertIsNotNone(getattr(l, key))
407415

416+
def testSupportedLanguageManifests(self) -> None:
417+
langs_with_aliases = {'csharp', 'cpp', 'javascript', 'bash'}
418+
res = self.client.supported_language_manifests()
419+
self.assertGreater(len(res), 0)
420+
for l in res:
421+
for key in ('name', 'language', 'version', 'status', 'features'):
422+
self.assertTrue(hasattr(l, key))
423+
self.assertIsNotNone(getattr(l, key))
424+
if getattr(l, 'language') in langs_with_aliases:
425+
self.assertTrue(hasattr(l, 'aliases'))
426+
self.assertGreater(len(getattr(l, 'aliases')), 0)
427+
408428
def testEncode(self) -> None:
409429
ctx = self._parse_fixture()
410430
# This test is here for backward compatibility purposes,

proto/github.com/gogo/protobuf/gogoproto/gogo.proto

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import "google/protobuf/descriptor.proto";
3333

3434
option java_package = "com.google.protobuf";
3535
option java_outer_classname = "GoGoProtos";
36+
option go_package = "github.com/gogo/protobuf/gogoproto";
3637

3738
extend google.protobuf.EnumOptions {
3839
optional bool goproto_enum_prefix = 62001;
@@ -78,10 +79,14 @@ extend google.protobuf.FileOptions {
7879
optional bool gogoproto_import = 63027;
7980
optional bool protosizer_all = 63028;
8081
optional bool compare_all = 63029;
81-
optional bool typedecl_all = 63030;
82-
optional bool enumdecl_all = 63031;
82+
optional bool typedecl_all = 63030;
83+
optional bool enumdecl_all = 63031;
8384

8485
optional bool goproto_registration = 63032;
86+
optional bool messagename_all = 63033;
87+
88+
optional bool goproto_sizecache_all = 63034;
89+
optional bool goproto_unkeyed_all = 63035;
8590
}
8691

8792
extend google.protobuf.MessageOptions {
@@ -114,6 +119,11 @@ extend google.protobuf.MessageOptions {
114119
optional bool compare = 64029;
115120

116121
optional bool typedecl = 64030;
122+
123+
optional bool messagename = 64033;
124+
125+
optional bool goproto_sizecache = 64034;
126+
optional bool goproto_unkeyed = 64035;
117127
}
118128

119129
extend google.protobuf.FieldOptions {
@@ -129,4 +139,6 @@ extend google.protobuf.FieldOptions {
129139

130140
optional bool stdtime = 65010;
131141
optional bool stdduration = 65011;
132-
}
142+
optional bool wktpointer = 65012;
143+
144+
}

setup.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,22 @@
1515
# The VERSION line is edited automatically during deployments.
1616
# You may change the contents of the string, but do not otherwise edit the line.
1717
VERSION = "3.x.x-dev"
18+
19+
# LIBUAST_URL is a format url which points to the libuast package
20+
# (see LIBUAST_VERSION and get_libuast_arch()). The url is used to download
21+
# and install uast library.
22+
LIBUAST_URL = "https://github.com/bblfsh/libuast/releases/download/{version}/libuast-{arch}.tar.gz"
1823
LIBUAST_VERSION = "v3.4.2"
24+
1925
SDK_V1_VERSION = "v1.17.0"
2026
SDK_V1_MAJOR = SDK_V1_VERSION.split('.')[0]
21-
SDK_V2_VERSION = "v2.16.4"
22-
SDK_V2_MAJOR = SDK_V2_VERSION.split('.')[0]
27+
28+
# SDK_URL is a format url which points to the sdk package.
29+
# The url is used to download and install python bindings for bblfsh sdk.
30+
SDK_URL = "https://github.com/bblfsh/sdk/archive/{version}.tar.gz"
31+
SDK_V3_VERSION = "v3.3.0"
32+
SDK_V3_PROTOCOL = "v2" # package gopkg.in.bblfsh.sdk.v2.protocol
33+
2334

2435
FORMAT_ARGS = globals()
2536

@@ -152,8 +163,7 @@ def get_libuast():
152163
mkdir(local_libuast)
153164

154165
# Retrieve libuast
155-
untar_url("https://github.com/bblfsh/libuast/releases/download/%s/libuast-%s.tar.gz" % (
156-
LIBUAST_VERSION, get_libuast_arch()))
166+
untar_url(LIBUAST_URL.format(version=LIBUAST_VERSION, arch=get_libuast_arch()))
157167
mv(get_libuast_arch(), local_libuast)
158168

159169

@@ -170,10 +180,10 @@ def proto_download_v1():
170180

171181

172182
def proto_download_v2():
173-
untar_url("https://github.com/bblfsh/sdk/archive/%s.tar.gz"
174-
% SDK_V2_VERSION)
175-
sdkdir = "sdk-" + SDK_V2_VERSION[1:]
176-
destdir = j("proto", "gopkg.in", "bblfsh", "sdk.{SDK_V2_MAJOR}")
183+
untar_url(SDK_URL.format(version=SDK_V3_VERSION))
184+
sdkdir = "sdk-" + SDK_V3_VERSION[1:]
185+
destdir = j("proto", "gopkg.in", "bblfsh", "sdk.{SDK_V3_PROTOCOL}")
186+
177187
cp(j(sdkdir, "protocol", "driver.proto"),
178188
j(destdir, "protocol", "generated.proto"))
179189
cp(j(sdkdir, "uast", "role", "generated.proto"),
@@ -261,18 +271,18 @@ def importlib_import_replacer(match):
261271
protoc(j("gopkg.in", "bblfsh", "sdk." + SDK_V1_MAJOR, "protocol", "generated.proto"), True)
262272
protoc(j("gopkg.in", "bblfsh", "sdk." + SDK_V1_MAJOR, "uast", "generated.proto"))
263273

264-
protoc(j("gopkg.in", "bblfsh", "sdk." + SDK_V2_MAJOR, "uast", "generated.proto"))
265-
protoc(j("gopkg.in", "bblfsh", "sdk." + SDK_V2_MAJOR, "protocol", "generated.proto"), True)
274+
protoc(j("gopkg.in", "bblfsh", "sdk." + SDK_V3_PROTOCOL, "uast", "generated.proto"))
275+
protoc(j("gopkg.in", "bblfsh", "sdk." + SDK_V3_PROTOCOL, "protocol", "generated.proto"), True)
266276

267277

268278
def do_get_deps():
269279
get_libuast()
270280

271281
create_dirs(SDK_V1_MAJOR)
272-
create_dirs(SDK_V2_MAJOR)
282+
create_dirs(SDK_V3_PROTOCOL)
273283

274284
create_inits(SDK_V1_MAJOR)
275-
create_inits(SDK_V2_MAJOR)
285+
create_inits(SDK_V3_PROTOCOL)
276286

277287
proto_download_v1()
278288
proto_download_v2()

0 commit comments

Comments
 (0)