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

Conversation

@manucorporat
Copy link
Contributor

No description provided.

parser = argparse.ArgumentParser(
description="Query for a UAST to Babelfish and dump it to stdout."
)
parser.add_argument('filename', type=str,
Copy link
Contributor

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,
Copy link
Contributor

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.

print(client.parse(args.file, args.language))

client = BblfshClient(args.endpoint)
root = client.parse_uast(args.filename, args.language)
Copy link
Contributor

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)

Copy link
Contributor

@juanjux juanjux Jul 26, 2017

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
Copy link
Contributor

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).

Copy link
Contributor

@juanjux juanjux left a 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.

{
return NULL;
}
printf("BEFORE FIND!! %p\n", obj);
Copy link
Contributor

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

@juanjux
Copy link
Contributor

juanjux commented Aug 1, 2017

Travis still failing ^^^^^^^

#include <libuast/uast.h>
#include <Python.h>

#ifdef __cplusplus
Copy link
Contributor

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

extern "C" {
#endif

static const char *
Copy link
Contributor

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.

@@ -0,0 +1,117 @@
#include <libuast/uast.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#include <stdint.h>

return NULL;
}
printf("BEFORE FIND!! %p\n", obj);
auto results = api.find(obj, std::string(query));
Copy link
Contributor

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
Copy link
Contributor

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?

Copy link
Contributor

@juanjux juanjux Aug 2, 2017

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()
Copy link
Contributor

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?


#ifdef __cplusplus
}
#endif No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Newline missing

@manucorporat manucorporat force-pushed the add-libuast branch 4 times, most recently from 353f43b to 611635f Compare August 8, 2017 16:27
@manucorporat manucorporat force-pushed the add-libuast branch 7 times, most recently from 6397d05 to 4b2c003 Compare August 23, 2017 14:54
@manucorporat manucorporat changed the title [WIP] feat: add xpath api feat: add find api Aug 23, 2017
@@ -0,0 +1,30 @@
{
Copy link
Contributor

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"
Copy link
Contributor

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.

Copy link
Contributor

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);
Copy link
Contributor

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
Copy link
Contributor

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']
Copy link
Contributor

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

Copy link
Contributor

@juanjux juanjux Sep 1, 2017

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.

@juanjux
Copy link
Contributor

juanjux commented Sep 6, 2017

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 find(), debugging it right now.

@juanjux
Copy link
Contributor

juanjux commented Sep 6, 2017

To have both PRs linked, the new (unfinished) one is /pull/23

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants