-
Notifications
You must be signed in to change notification settings - Fork 20
feat: add find api #16
Conversation
bblfsh/__main__.py
Outdated
| parser = argparse.ArgumentParser( | ||
| description="Query for a UAST to Babelfish and dump it to stdout." | ||
| ) | ||
| parser.add_argument('filename', type=str, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change seems to be unrelated with the usage of libuast. Was it requested by the machine learning team?
bblfsh/client.py
Outdated
| return response | ||
| return self._stub.Parse(request, timeout=timeout) | ||
|
|
||
| def parse_uast(self, filename, language=None, contents=None, timeout=None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be def parse( as in ~master.
bblfsh/__main__.py
Outdated
| print(client.parse(args.file, args.language)) | ||
|
|
||
| client = BblfshClient(args.endpoint) | ||
| root = client.parse_uast(args.filename, args.language) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
root = client.parse(...
bblfsh/test.py
Outdated
| node8 = NodeNative("loop") | ||
|
|
||
| root.add_child(node1) | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spurious whitespace?, probably all the add_child statements would be better on a single logical paragraph (without whitespace between them).
Makefile
Outdated
| cd libuast && cmake . && make && make install | ||
|
|
||
| bblfsh/pyuast.py: libuast | ||
| cd bblfsh && swig -c++ -python -I/usr/local/include uast.i |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So swig is needed, at least for make. Since the .i and pyuast.py files are included, couldn't we remove the all: target dependency on this one? (but keeping this in the Makefile just in case we want to regenerate pyuast.py).
0a794ce to
617c4dc
Compare
617c4dc to
6e540f2
Compare
juanjux
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check the failing Travis build, maybe you need to install gcc or something like that.
bblfsh/pyuast.cpp
Outdated
| { | ||
| return NULL; | ||
| } | ||
| printf("BEFORE FIND!! %p\n", obj); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These things usually go inside an #ifdef DEBUG
|
Travis still failing ^^^^^^^ |
bblfsh/pyuast.cpp
Outdated
| #include <libuast/uast.h> | ||
| #include <Python.h> | ||
|
|
||
| #ifdef __cplusplus |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no need for this file being C++, it should be a C file and these lines become unnecessary
bblfsh/pyuast.cpp
Outdated
| extern "C" { | ||
| #endif | ||
|
|
||
| static const char * |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to split these in 2 lines, it should be consistent everywhere and it's not wide enough to split it.
bblfsh/pyuast.cpp
Outdated
| @@ -0,0 +1,117 @@ | |||
| #include <libuast/uast.h> | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#include <stdint.h>
bblfsh/pyuast.cpp
Outdated
| return NULL; | ||
| } | ||
| printf("BEFORE FIND!! %p\n", obj); | ||
| auto results = api.find(obj, std::string(query)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be C code.
| import argparse | ||
| import sys | ||
|
|
||
| from bblfsh._pyuast import find |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think pyuast should be a private module, should it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if there is specified in PEP8 but there is an old convention in Python of using a leading underline for binary modules.
PS: forget it, it's only when the pure Python module has the same name.
bblfsh/client.py
Outdated
| for example "0.0.0.0:9432" | ||
| :type endpoint: str | ||
| """ | ||
| Node.initialize() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think a libuast Node should be initialized in a GRPC client, why is it this way?
bblfsh/pyuast.cpp
Outdated
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Newline missing
353f43b to
611635f
Compare
611635f to
2469036
Compare
6397d05 to
4b2c003
Compare
4b2c003 to
e55d61d
Compare
e55d61d to
c26ba6f
Compare
.vscode/settings.json
Outdated
| @@ -0,0 +1,30 @@ | |||
| { | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this file should not be here
| @@ -0,0 +1,119 @@ | |||
| #include "uast.h" | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a code style for python modules? If not, I guess we should follow Google C++ code style, which is not been followed here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not that I know for - or resulted from a quick search. Since @manucorporat probably won't be working on this anymore I'll change it soon.
| { | ||
| PyObject *node = (PyObject *)data; | ||
| PyObject *attribute = PyObject_GetAttrString(node, prop); | ||
| const char *a = PyUnicode_AsUTF8(attribute); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return PyUnicode_AsUTF8(attribute)
| return PyModule_Create(&moduledef); | ||
| } | ||
|
|
||
| #ifdef __cplusplus |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be removed
| from setuptools import setup, find_packages, Extension | ||
|
|
||
| LIBRARIES = ['xml2'] | ||
| SOURCES = ['bblfsh/pyuast.c'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are not constants, they shouldn't be upcase
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've frequently seen some uppercased module-globals on Python code that were not constants but it doesn't seem to be a consensus, PEP8 says that constants are uppercase but doesn't say anything about module (mutable) globals but I think that making them lowercase avoids confusion, yes.
|
Closing it because I'll reopen this PR from my branch - I already implemented all the suggested changes, but found a crashing bug with some parameters for |
|
To have both PRs linked, the new (unfinished) one is /pull/23 |
No description provided.