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

Commit 421878f

Browse files
author
Juanjo Alvarez
committed
Update to SDK.v2
Update integration tests Fixed build with v2 Signed-off-by: Juanjo Alvarez <[email protected]>
1 parent 8bca174 commit 421878f

24 files changed

+104
-137
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ services:
77
- docker
88

99
before_script:
10-
- go get -v gopkg.in/bblfsh/sdk.v1/...
10+
- go get -v gopkg.in/bblfsh/sdk.v2/...
1111
- bblfsh-sdk prepare-build .
1212
- go get -v -t ./driver/...
1313

Dockerfile.build.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ FROM alpine:3.7
33
RUN mkdir -p /opt/driver/src && \
44
adduser $BUILD_USER -u $BUILD_UID -D -h /opt/driver/src
55

6-
RUN apk add --no-cache --update python python3 git make
6+
RUN apk add --no-cache --update python python3 py-pip py2-pip git make
77

88
WORKDIR /opt/driver/src

Dockerfile.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ MAINTAINER source{d}
33

44
ARG DEVDEPS=native/dev_deps
55
ARG CONTAINER_DEVDEPS=/tmp/dev_deps
6-
ARG PYDETECTOR_VER=0.14.2
6+
ARG PYDETECTOR_VER=0.14.3
77

88
RUN apk add --no-cache --update python python3 py-pip py2-pip git
99

Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ DEV_DEPS ?= native/dev_deps
22

33
test-native-internal:
44
pip3 install --user ${DEV_DEPS}/python-pydetector/ || pip3 install --user pydetector-bblfsh
5+
pip2 install --user ${DEV_DEPS}/python-pydetector/ || pip2 install --user pydetector-bblfsh
56
cd native/python_package/test && \
67
python3 -m unittest discover
78

89
build-native-internal:
910
pip3 install --user ${DEV_DEPS}/python-pydetector/ || pip3 install --user pydetector-bblfsh
10-
cd native/python_package/ && \
11-
pip3 install -U --user .
11+
pip2 install --user ${DEV_DEPS}/python-pydetector/ || pip2 install --user pydetector-bblfsh
12+
cd native/python_package/ && pip3 install -U --user .
1213
cp native/sh/native.sh $(BUILD_PATH)/bin/native;
1314
chmod +x $(BUILD_PATH)/bin/native
14-
15+
cat $(BUILD_PATH)/bin/native
1516

1617
include .sdk/Makefile

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Development Environment
77

88
Requirements:
99
- `docker`
10-
- [`bblfsh-sdk`](https://github.com/bblfsh/sdk) _(go get -u gopkg.in/bblfsh/sdk.v1/...)_
10+
- [`bblfsh-sdk`](https://github.com/bblfsh/sdk) _(go get -u gopkg.in/bblfsh/sdk.v2/...)_
1111
- UAST converter dependencies _(go get -t -v ./...)_
1212

1313
To initialize the build system execute: `bblfsh-sdk prepare-build`, at the root of the project. This will install the SDK at `.sdk` for this driver.

driver/fixtures/fixtures_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
"testing"
66

77
"github.com/bblfsh/python-driver/driver/normalizer"
8-
"gopkg.in/bblfsh/sdk.v1/sdk/driver"
9-
"gopkg.in/bblfsh/sdk.v1/sdk/driver/fixtures"
8+
"gopkg.in/bblfsh/sdk.v2/sdk/driver"
9+
"gopkg.in/bblfsh/sdk.v2/sdk/driver/fixtures"
1010
)
1111

1212
const projectRoot = "../../"

driver/impl/impl.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package impl
22

3-
import "gopkg.in/bblfsh/sdk.v1/sdk/driver"
3+
import "gopkg.in/bblfsh/sdk.v2/sdk/driver"
44

55
func init() {
66
// Can be overridden to link a native driver into a Go driver server.

driver/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
_ "github.com/bblfsh/python-driver/driver/impl"
55
"github.com/bblfsh/python-driver/driver/normalizer"
66

7-
"gopkg.in/bblfsh/sdk.v1/sdk/driver"
7+
"gopkg.in/bblfsh/sdk.v2/sdk/driver"
88
)
99

1010
func main() {

driver/normalizer/annotation.go

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package normalizer
22

33
import (
4-
"gopkg.in/bblfsh/sdk.v1/uast"
5-
"gopkg.in/bblfsh/sdk.v1/uast/role"
6-
. "gopkg.in/bblfsh/sdk.v1/uast/transformer"
7-
"gopkg.in/bblfsh/sdk.v1/uast/transformer/positioner"
4+
"gopkg.in/bblfsh/sdk.v2/uast"
5+
"gopkg.in/bblfsh/sdk.v2/uast/role"
6+
. "gopkg.in/bblfsh/sdk.v2/uast/transformer"
7+
"gopkg.in/bblfsh/sdk.v2/uast/transformer/positioner"
88
)
99

1010
var Native = Transformers([][]Transformer{
@@ -22,7 +22,7 @@ var Code = []CodeTransformer{
2222
}
2323

2424
func annotateTypeToken(typ, token string, roles ...role.Role) Mapping {
25-
return AnnotateTypeFields(typ,
25+
return AnnotateType(typ,
2626
FieldRoles{
2727
uast.KeyToken: {Add: true, Op: String(token)},
2828
}, roles...)
@@ -185,9 +185,9 @@ var Annotations = []Mapping{
185185
annotateTypeToken("Pass", "pass", role.Noop, role.Statement),
186186
annotateTypeToken("Assert", "assert", role.Assert, role.Statement),
187187

188-
AnnotateTypeFields("Name", FieldRoles{"id": {Rename: uast.KeyToken}},
188+
AnnotateType("Name", FieldRoles{"id": {Rename: uast.KeyToken}},
189189
role.Identifier, role.Expression),
190-
AnnotateTypeFields("Attribute", FieldRoles{"attr": {Rename: uast.KeyToken}},
190+
AnnotateType("Attribute", FieldRoles{"attr": {Rename: uast.KeyToken}},
191191
role.Identifier, role.Expression),
192192

193193
// Binary Expressions
@@ -198,20 +198,20 @@ var Annotations = []Mapping{
198198
}, role.Expression, role.Binary),
199199

200200
// Primitive Literals
201-
AnnotateTypeFields("Str", FieldRoles{"s": {Rename: uast.KeyToken}},
201+
AnnotateType("Str", FieldRoles{"s": {Rename: uast.KeyToken}},
202202
role.Literal, role.String, role.Expression, role.Primitive),
203-
AnnotateTypeFields("Bytes", FieldRoles{"s": {Rename: uast.KeyToken}},
203+
AnnotateType("Bytes", FieldRoles{"s": {Rename: uast.KeyToken}},
204204
role.Literal, role.ByteString, role.Expression, role.Primitive),
205-
AnnotateTypeFields("StringLiteral", FieldRoles{"s": {Rename: uast.KeyToken}},
205+
AnnotateType("StringLiteral", FieldRoles{"s": {Rename: uast.KeyToken}},
206206
role.Literal, role.String, role.Expression, role.Primitive),
207-
AnnotateTypeFields("BoolLiteral", FieldRoles{"LiteralValue": {Rename: uast.KeyToken}},
207+
AnnotateType("BoolLiteral", FieldRoles{"LiteralValue": {Rename: uast.KeyToken}},
208208
role.Literal, role.Boolean, role.Expression, role.Primitive),
209209
annotateTypeToken("NoneLiteral", "None", role.Literal, role.Null, role.Expression, role.Primitive),
210-
AnnotateTypeFields("Num", FieldRoles{"n": {Rename: uast.KeyToken}},
210+
AnnotateType("Num", FieldRoles{"n": {Rename: uast.KeyToken}},
211211
role.Expression, role.Literal, role.Number, role.Primitive),
212-
AnnotateTypeFields("BoolLiteral", FieldRoles{"LiteralValue": {Rename: uast.KeyToken}},
212+
AnnotateType("BoolLiteral", FieldRoles{"LiteralValue": {Rename: uast.KeyToken}},
213213
role.Expression, role.Literal, role.Boolean, role.Primitive),
214-
AnnotateTypeFields("Dict", FieldRoles{
214+
AnnotateType("Dict", FieldRoles{
215215
"keys": {Arr: true, Roles: role.Roles{role.Map, role.Key}},
216216
"values": {Arr: true, Roles: role.Roles{role.Map, role.Value}},
217217
}, role.Expression, role.Literal, role.Primitive, role.Map),
@@ -225,7 +225,7 @@ var Annotations = []Mapping{
225225
// targets[] => Left
226226
// value => Right
227227
//
228-
AnnotateTypeFields("Assign", FieldRoles{
228+
AnnotateType("Assign", FieldRoles{
229229
"targets": {Arr: true, Roles: role.Roles{role.Left}},
230230
"value": {Roles: role.Roles{role.Right}},
231231
}, role.Binary, role.Expression, role.Assignment),
@@ -271,12 +271,12 @@ var Annotations = []Mapping{
271271

272272
// python 2 exception handling
273273
AnnotateType("TryExcept", nil, role.Try, role.Catch, role.Statement),
274-
AnnotateTypeFields("ExceptHandler", FieldRoles{"name": {Rename: uast.KeyToken}},
274+
AnnotateType("ExceptHandler", FieldRoles{"name": {Rename: uast.KeyToken}},
275275
role.Try, role.Catch, role.Identifier),
276276
AnnotateType("TryFinally", nil, role.Try, role.Finally, role.Statement),
277277
AnnotateType("Raise", nil, role.Throw),
278278

279-
AnnotateTypeFields("Raise",
279+
AnnotateType("Raise",
280280
FieldRoles{
281281
"exc": {Opt: true, Roles: role.Roles{role.Call}},
282282
uast.KeyToken: {Add: true, Op: String("raise")},
@@ -296,7 +296,7 @@ var Annotations = []Mapping{
296296
AnnotateType("SetComp", nil, role.Set, role.For, role.Expression),
297297

298298
// FIXME: once we have an async Role we should interpret the is_async property
299-
AnnotateTypeFields("comprehension", FieldRoles{
299+
AnnotateType("comprehension", FieldRoles{
300300
"ifs": {Arr: true, Roles: role.Roles{role.If, role.Condition}},
301301
"iter": {Roles: role.Roles{role.For, role.Update, role.Statement}},
302302
"target": {Roles: role.Roles{role.For, role.Expression}},
@@ -327,7 +327,7 @@ var Annotations = []Mapping{
327327

328328
// Formal Arguments
329329
// FIXME: opt: true + arr: true seems to cause a crash in the SDK
330-
AnnotateTypeFields("arguments", FieldRoles{
330+
AnnotateType("arguments", FieldRoles{
331331
"args": {Arr: true, Roles: role.Roles{role.Function, role.Declaration, role.Argument, role.Name, role.Identifier}},
332332
"defaults": {Arr: true, Roles: role.Roles{role.Function, role.Declaration, role.ArgsList, role.Value, role.Default}},
333333
// Default arguments: Python's AST puts default arguments on a sibling list to the one of
@@ -341,48 +341,48 @@ var Annotations = []Mapping{
341341
"vararg": {Opt: true, Roles: role.Roles{role.Function, role.Declaration, role.ArgsList, role.Name, role.Identifier}},
342342
}, role.Function, role.Declaration, role.Argument, role.Incomplete),
343343

344-
AnnotateTypeFields("arguments", FieldRoles{
344+
AnnotateType("arguments", FieldRoles{
345345
"args": {Arr: true, Roles: role.Roles{role.Function, role.Declaration, role.Argument, role.Name, role.Identifier}},
346346
"defaults": {Arr: true, Roles: role.Roles{role.Function, role.Declaration, role.ArgsList, role.Value, role.Default}},
347347
"kwarg": {Opt: true, Roles: role.Roles{role.Function, role.Declaration, role.ArgsList, role.Map, role.Name, role.Identifier}},
348348
"vararg": {Opt: true, Roles: role.Roles{role.Function, role.Declaration, role.ArgsList, role.Name, role.Identifier}},
349349
}, role.Function, role.Declaration, role.Argument, role.Incomplete),
350350

351351
// Function Calls
352-
AnnotateTypeFields("Call", FieldRoles{
352+
AnnotateType("Call", FieldRoles{
353353
"args": {Arr: true, Roles: role.Roles{role.Function, role.Call, role.Positional, role.Argument, role.Name}},
354354
"func": {Roles: role.Roles{role.Call, role.Callee}},
355355
"keywords": {Arr: true, Roles: role.Roles{role.Function, role.Call, role.Argument}},
356356
}, role.Function, role.Call, role.Expression),
357357

358358
// Keywords are additionally annotated in FunctionDef and ClassDef
359-
AnnotateTypeFields("keyword", FieldRoles{
359+
AnnotateType("keyword", FieldRoles{
360360
"value": {Roles: role.Roles{role.Argument, role.Value}},
361361
"arg": {Rename: uast.KeyToken},
362362
}, role.Name),
363363

364364
// Comments and non significative whitespace
365365
AnnotateType("SameLineNoops", nil, role.Comment),
366366

367-
AnnotateTypeFields("PreviousNoops", FieldRoles{
367+
AnnotateType("PreviousNoops", FieldRoles{
368368
"lines": {Arr: true, Roles: role.Roles{role.Noop}},
369369
}, role.Noop),
370370

371-
AnnotateTypeFields("RemainderNoops", FieldRoles{
371+
AnnotateType("RemainderNoops", FieldRoles{
372372
"lines": {Arr: true, Roles: role.Roles{role.Noop}},
373373
}, role.Noop),
374374

375-
AnnotateTypeFields("NoopLine", FieldRoles{
375+
AnnotateType("NoopLine", FieldRoles{
376376
"noop_line": {Rename: uast.KeyToken},
377377
}, role.Noop, role.Comment),
378378

379-
AnnotateTypeFields("NoopSameLine", FieldRoles{
379+
AnnotateType("NoopSameLine", FieldRoles{
380380
"s": {Rename: uast.KeyToken},
381381
}, role.Noop, role.Comment),
382382

383383
// Qualified Identifiers
384384
// a.b.c ("a" and "b" will be Qualified+Identifier, "c" will be just Identifier)
385-
AnnotateTypeFields("Attribute", FieldRoles{
385+
AnnotateType("Attribute", FieldRoles{
386386
"value": {Arr: true, Roles: role.Roles{role.Qualified}},
387387
}),
388388

@@ -458,20 +458,20 @@ var Annotations = []Mapping{
458458
},
459459
}, role.Type, role.Declaration, role.Identifier, role.Statement),
460460

461-
AnnotateTypeFields("ClassDef", FieldRoles{
461+
AnnotateType("ClassDef", FieldRoles{
462462
"keywords": {Arr: true, Roles: role.Roles{role.Incomplete}},
463463
}),
464464

465465
// These two (exec & print) are AST nodes in Python2 but we convert them to functions
466466
// in the UAST like they are in Python3
467-
AnnotateTypeFields("Exec", FieldRoles{
467+
AnnotateType("Exec", FieldRoles{
468468
"body": {Roles: role.Roles{role.Call, role.Argument, role.Positional}},
469469
"globals": {Roles: role.Roles{role.Call, role.Argument, role.Positional}},
470470
"locals": {Roles: role.Roles{role.Call, role.Argument, role.Positional}},
471471
uast.KeyToken: {Add: true, Op: String("exec")},
472472
}, role.Function, role.Call, role.Expression),
473473

474-
AnnotateTypeFields("Print", FieldRoles{
474+
AnnotateType("Print", FieldRoles{
475475
"values": {Arr: true, Roles: role.Roles{role.Call, role.Argument, role.Positional}},
476476
uast.KeyToken: {Add: true, Op: String("print")},
477477
}, role.Function, role.Call, role.Callee, role.Identifier, role.Expression),

fixtures/empty.py

Whitespace-only changes.

0 commit comments

Comments
 (0)