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

Commit 79f11b2

Browse files
authored
Merge pull request #63 from juanjux/fix/issue60
Test for issue 60 + bblfshd/libuast update
2 parents a85d54f + 8c7a2a7 commit 79f11b2

File tree

5 files changed

+64
-13
lines changed

5 files changed

+64
-13
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
## client-python [![Build Status](https://travis-ci.org/bblfsh/client-python.svg?branch=master)](https://travis-ci.org/bblfsh/client-python) [![PyPI](https://img.shields.io/pypi/v/bblfsh.svg)](https://pypi.python.org/pypi/bblfsh)
22

33
[Babelfish](https://doc.bblf.sh) Python client library provides functionality to both
4-
connect to the Babelfish server to parse code
4+
connect to the Babelfish bblfshd to parse code
55
(obtaining an [UAST](https://doc.bblf.sh/uast/specification.html) as a result)
66
and to analyse UASTs with the functionality provided by [libuast](https://github.com/bblfsh/libuast).
77

@@ -37,10 +37,11 @@ A small example of how to parse a Python file and extract the import declaration
3737
If you don't have a bblfsh server running you can execute it using the following command:
3838

3939
```sh
40-
docker run --privileged --rm -it -p 9432:9432 --name bblfsh bblfsh/server
40+
docker run --privileged --rm -it -p 9432:9432 -v bblfsh_cache:/var/lib/bblfshd --name bblfshd bblfsh/bblfshd
41+
docker exec -it bblfshd bblfshctl driver install python bblfsh/python-driver:latest
4142
```
4243

43-
Please, read the [getting started](https://doc.bblf.sh/user/getting-started.html) guide to learn more about how to use and deploy a bblfsh server.
44+
Please, read the [getting started](https://doc.bblf.sh/user/getting-started.html) guide to learn more about how to use and deploy a bblfshd.
4445

4546
```python
4647
from bblfsh import BblfshClient, filter

bblfsh/fixtures/issue60.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from setuptools import setup, find_packages
2+
3+
setup(
4+
name="apollo",
5+
description="source{d} Gemini's evil twin which runs everything using Python.",
6+
version="0.1.0",
7+
license="Apache 2.0",
8+
author="source{d}",
9+
author_email="machine-learning@sourced.tech",
10+
url="https://github.com/src-d/gemini",
11+
download_url="https://github.com/src-d/gemini",
12+
packages=find_packages(exclude=("gemini.tests",)),
13+
entry_points={
14+
"console_scripts": ["gemini=gemini.__main__:main"],
15+
},
16+
keywords=["machine learning on source code", "weighted minhash", "minhash",
17+
"bblfsh", "babelfish"],
18+
install_requires=["cassandra_driver >= 3.12.0, <4.0",
19+
"libMHCUDA >= 1.1.5, <2.0"],
20+
# "sourcedml >= 0.4.0, <1.0"],
21+
package_data={"": ["LICENSE", "README.md"]},
22+
classifiers=[
23+
"Development Status :: 3 - Alpha",
24+
"Environment :: Console",
25+
"Intended Audience :: Developers",
26+
"License :: OSI Approved :: Apache Software License",
27+
"Operating System :: POSIX",
28+
"Programming Language :: Python :: 3.4",
29+
"Programming Language :: Python :: 3.5",
30+
"Programming Language :: Python :: 3.6",
31+
"Topic :: Software Development :: Libraries"
32+
]
33+
)

bblfsh/launcher.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,24 @@ def ensure_bblfsh_is_running():
1616

1717
def after_start(container):
1818
log.warning(
19-
"Launched the Babelfish server (name bblfsh, id %s).\nStop it "
20-
"with: docker rm -f bblfsh", container.id)
19+
"Launched the Babelfish server (name bblfshd, id %s).\nStop it "
20+
"with: docker rm -f bblfshd", container.id)
2121
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
2222
result = -1
2323
while result != 0:
2424
time.sleep(0.1)
2525
result = sock.connect_ex(("0.0.0.0", 9432))
2626
log.warning("Babelfish server is up and running.")
27+
log.info("Installing Python driver")
28+
container.exec_run("bblfshctl driver install python bblfsh/python-driver:latest")
2729

2830
try:
29-
container = client.containers.get("bblfsh")
31+
container = client.containers.get("bblfshd")
3032
if container.status != "running":
3133
try:
3234
container.start()
3335
except Exception as e:
34-
log.warning("Failed to start the existing bblfsh container: "
36+
log.warning("Failed to start the existing bblfshd container: "
3537
"%s: %s", type(e).__name__, e)
3638
else:
3739
after_start(container)
@@ -44,7 +46,7 @@ def after_start(container):
4446
return False
4547
except docker.errors.NotFound:
4648
container = client.containers.run(
47-
"bblfsh/server", name="bblfsh", detach=True, privileged=True,
49+
"bblfsh/bblfshd", name="bblfshd", detach=True, privileged=True,
4850
ports={9432: 9432}
4951
)
5052
after_start(container)

bblfsh/test.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import unittest
23

34
import docker
@@ -17,7 +18,7 @@ def setUpClass(cls):
1718
def tearDownClass(cls):
1819
if not cls.BBLFSH_SERVER_EXISTED:
1920
client = docker.from_env(version="auto")
20-
client.containers.get("bblfsh").remove(force=True)
21+
client.containers.get("bblfshd").remove(force=True)
2122
client.api.close()
2223

2324
def setUp(self):
@@ -112,6 +113,18 @@ def testFilterEndCol(self):
112113
self.assertTrue(any(filter(node, "//*[@endCol=50]")))
113114
self.assertFalse(any(filter(node, "//*[@endCol=5]")))
114115

116+
def testFilterBadQuery(self):
117+
node = Node()
118+
self.assertRaises(RuntimeError, filter, node, "//*roleModule")
119+
120+
def testIssue60(self):
121+
fixtures_dir = os.path.join(
122+
os.path.dirname(os.path.realpath(__file__)),
123+
"fixtures")
124+
rep = self.client.parse(os.path.join(fixtures_dir, "issue60.py"))
125+
assert(rep.uast)
126+
self.assertFalse(any(filter(rep.uast, "//@roleLiteral")))
127+
115128
def testRoleIdName(sedlf):
116129
assert(role_id(role_name(1)) == 1)
117130
assert(role_name(role_id("IDENTIFIER")) == "IDENTIFIER")
@@ -129,6 +142,7 @@ def _validate_resp(self, resp):
129142

130143
def _validate_filter(self, resp):
131144
results = filter(resp.uast, "//Import[@roleImport and @roleDeclaration]//alias")
145+
self.assertEqual(next(results).token, "os")
132146
self.assertEqual(next(results).token, "unittest")
133147
self.assertEqual(next(results).token, "docker")
134148

setup.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
from setuptools import setup, find_packages, Extension
66
from setuptools.command.build_ext import build_ext
77

8-
LIBUAST_VERSION = "v1.4.1"
8+
LIBUAST_VERSION = "v1.5.1"
99
SDK_VERSION = "v1.8.0"
1010
SDK_MAJOR = SDK_VERSION.split('.')[0]
1111
PYTHON = "python3"
1212

13-
13+
os.environ["CC"] = "g++"
14+
os.environ["CXX"] = "g++"
1415
libraries = ['xml2']
1516
sources = ['bblfsh/pyuast.c']
1617

@@ -23,7 +24,7 @@ def run(self):
2324
if "--global-uast" in sys.argv:
2425
libraries.append('uast')
2526
else:
26-
sources.append('bblfsh/libuast/uast.c')
27+
sources.append('bblfsh/libuast/uast.cc')
2728
sources.append('bblfsh/libuast/roles.c')
2829

2930
getLibuast()
@@ -123,7 +124,7 @@ def main():
123124
'bblfsh.pyuast',
124125
libraries=libraries,
125126
library_dirs=['/usr/lib', '/usr/local/lib'],
126-
extra_compile_args=['-std=gnu99'],
127+
extra_compile_args=['-std=c++11'],
127128
include_dirs=['bblfsh/libuast/', '/usr/local/include', '/usr/local/include/libxml2',
128129
'/usr/include', '/usr/include/libxml2'], sources=sources)
129130

0 commit comments

Comments
 (0)