bblfsh / python-client

Babelfish Python client
https://doc.bblf.sh/using-babelfish/clients.html
Apache License 2.0
16 stars 20 forks source link

Client hangs with no error message, potential alternative to build-essentials for windows #199

Open invertednz opened 4 years ago

invertednz commented 4 years ago

Currently the python client does not work for me it just hangs on attempting to parse a file.

I am only running the following: client = bblfsh.BblfshClient("localhost:9432") print("parsing") ctx = client.parse("ast.py")

I realized it maybe because I haven't installed the required dependencies:

"Dependencies You also will need a curl cli tool to dowload libuast, and a g++ for building libuast Python bindings. The command for Debian and derived distributions would be:

sudo apt install curl build-essential"

Is there a windows alternative for this?

Just as an FYI I get the following in the docker server log

time="2020-01-03T11:22:58.3367974Z" level=info msg="python-driver version: v2.10.3 (build: 2019-10-25T13:40:25Z)" id=01dxnj9snfwpjbr0yq8v7g0t0t language=python time="2020-01-03T11:22:58.3413548Z" level=info msg="server listening in /tmp/rpc.sock (unix)" id=01dxnj9snfwpjbr0yq8v7g0t0t language=python time="2020-01-03T11:22:59.2967131Z" level=info msg="new driver instance started bblfsh/python-driver:latest (01dxnj9snfwpjbr0yq8v7g0t0t)" time="2020-01-03T11:22:59.3601263Z" level=info msg="request processed content 913 bytes" elapsed=1.3212179s filename=ast.py githash=5ca83c1f3e6f816ab3df6e5e4452fd8c4f85e6e7 language=python sha1=a011fd51d314e1e4e4a2fa3cc771a432e21760b1

invertednz commented 4 years ago

I tried installing https://nuwen.net/mingw.html but still no error, the command just hangs with no output.

kuba-- commented 4 years ago

Have you installed python driver on bblfsh server? Is (bblfshd) running locally or inside a docker container?

invertednz commented 4 years ago

Hey Kuba,

I have the bblfshd running in a docker container.

And these are my drivers. If I try to update the python one it says this is already the latest.

PS C:\Users\james> docker exec -it bblfshd bblfshctl driver list +------------+------------------------------------------+---------+--------+----------+----+--------+ | LANGUAGE | IMAGE | VERSION | STATUS | CREATED | GO | NATIVE | +------------+------------------------------------------+---------+--------+----------+----+--------+ | python | docker://bblfsh/python-driver:latest | v2.10.3 | beta | 2 months | | | | cpp | docker://bblfsh/cpp-driver:latest | v1.5.0 | beta | 3 months | | | | java | docker://bblfsh/java-driver:latest | v2.7.5 | beta | 2 months | | | | javascript | docker://bblfsh/javascript-driver:latest | v2.10.2 | beta | 2 months | | | | bash | docker://bblfsh/bash-driver:latest | v2.7.2 | beta | 2 months | | | | ruby | docker://bblfsh/ruby-driver:latest | v2.9.6 | beta | 2 months | | | | go | docker://bblfsh/go-driver:latest | v2.7.3 | beta | 2 months | | | | csharp | docker://bblfsh/csharp-driver:latest | v1.7.1 | beta | 2 months | | | | php | docker://bblfsh/php-driver:latest | v2.8.3 | beta | 2 months | | | +------------+------------------------------------------+---------+--------+----------+----+--------+ Response time 5.6423ms

kuba-- commented 4 years ago

ok, could you give me your python file, so I'll try to reproduce it?

invertednz commented 4 years ago

Sure, although it happens with every file that I've tried and I managed to get everything working with ubuntu, so I think it is the windows setup.

ast.py

import bblfsh

client = bblfsh.BblfshClient("localhost:9432")
print("parsing")
ctx = client.parse("ast.py")
print("printing ctx")
print(ctx)

I was wondering is it possible to query on a line number? And is it possible to go from a node up to the parent node? Or can you only iterate like -

ast = ctx.root
it = ast.iterate(bblfsh.TreeOrder.POSITION_ORDER)
for node in it:
    print(node)
kuba-- commented 4 years ago

Ohh, ok - in my opinion it can't work well on windows (where bblfshd internally creates subcontainers with communicates over grpc on top of std. IO).

Regarding query -you can filter with xpath whatever you want, e.g. next(ctx.filter("boolean(//*[@startOffset or @endOffset])")) Every position is a tuple (Type, Col, Line, Offset), so in theory it should be doable.