Skip to content

Commit c935d27

Browse files
authored
Merge pull request #2 from elastic-coders/release_0.0.4
Release 0.0.4
2 parents b34d0a2 + b46fc76 commit c935d27

16 files changed

+119
-17
lines changed

.circleci/config.yml

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
version: 2
2+
3+
jobs:
4+
build:
5+
working_directory: ~/py-graphqlparser
6+
docker:
7+
- image: ubuntu:16.04
8+
steps:
9+
- checkout
10+
- run:
11+
name: apt update
12+
command: apt-get -q update
13+
- run:
14+
name: apt required packages
15+
command: apt-get install -qy build-essential python python3 python3-pip python3-dev git cmake bison flex pkg-config
16+
- run:
17+
name: install cython
18+
command: pip3 install -q cython==0.27.3
19+
- run:
20+
name: git submodules
21+
command: |
22+
mkdir -p -m 700 ~/.ssh
23+
ssh-keyscan github.com >> ~/.ssh/known_hosts
24+
git submodule -q sync
25+
git submodule -q update -f --init
26+
- run:
27+
name: build libgraphqlparser
28+
command: |
29+
cd libgraphqlparser
30+
cmake .
31+
make
32+
- run:
33+
name: ast
34+
command: python2 ast/build_ast.py
35+
- run:
36+
name: build ext
37+
command: LDFLAGS="-L./libgraphqlparser" CFLAGS="-Ilibgraphqlparser/c -Ilibgraphqlparser" python3 setup.py build_ext
38+
- run:
39+
name: install package
40+
command: pip3 install -e .
41+
- run:
42+
name: install pytest
43+
command: pip3 install pytest
44+
- run:
45+
name: test
46+
command: python3 -m pytest
47+
environment:
48+
LD_LIBRARY_PATH: "./libgraphqlparser"

.dockerignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
**/.git/
2+
**/__pycache__/
3+
.circleci/
4+
.pytest_cache/
5+
.tox/
6+
.wheelhouse/
7+
**/CMakeCache.txt

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ __pycache__
99
/.cache
1010
/dist/
1111
/*.egg-info
12+
.pytest_cache

Dockerfile

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
FROM ubuntu:16.04
2+
3+
RUN apt-get update -qy
4+
RUN apt-get install -qy build-essential python python3 python3-pip python3-dev git cmake bison flex pkg-config
5+
RUN pip3 install cython
6+
7+
RUN mkdir /tmp/build
8+
COPY libgraphqlparser /tmp/build/libgraphqlparser
9+
COPY ast /tmp/build/ast
10+
COPY examples /tmp/build/examples
11+
COPY graphql_parser /tmp/build/graphql_parser
12+
COPY setup.py *.rst /tmp/build/
13+
14+
15+
RUN cd /tmp/build/libgraphqlparser && \
16+
cmake . && \
17+
make && \
18+
cp libgraphqlparser.so /usr/local/lib
19+
RUN cd /tmp/build && \
20+
python2 ast/build_ast.py && \
21+
LDFLAGS="-L./libgraphqlparser" CFLAGS="-Ilibgraphqlparser/c -Ilibgraphqlparser" \
22+
python3 setup.py build_ext && \
23+
pip3 install .
24+
ENV LD_LIBRARY_PATH=/usr/local/lib
25+
26+
ENTRYPOINT ["python3", "/tmp/build/examples/visitor_example.py"]

NEWS.rst

+7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
News
22
----
33

4+
v0.0.4
5+
------
6+
7+
- compatible with latest libgraphqlparser 0.7.0
8+
- built wheels for python 3.6
9+
10+
411
v0.0.3
512
------
613

README.rst

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
Graphql parser based on libgraphqlparser
22
=========================================
33

4+
.. image:: https://circleci.com/gh/elastic-coders/py-graphqlparser.svg?style=svg
5+
:target: https://circleci.com/gh/elastic-coders/py-graphqlparser
6+
47
Python2.7+ Python3.4+ class-based bindings to libgraphqlparser; just a thin layer on top of ``libgraphqlparser`` C API.
58

69
Still **EXPERIMENTAL**
@@ -16,7 +19,7 @@ on `graphqlparser github releases`_
1619

1720
Pick the right wheel for your platform and python version, then install it using pip::
1821

19-
pip install https://github.com/elastic-coders/py-graphqlparser/releases/download/v0.0.3/graphqlparser-0.0.3-cp27-none-linux_x86_64.whl
22+
pip install https://github.com/elastic-coders/py-graphqlparser/releases/download/v0.0.4/graphqlparser-0.0.4-cp36-cp36m-linux_x86_64.whl
2023

2124

2225
As an alternative you can install ``graphqlparser`` from source distribution:

ast/ast_cython.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ def start_type(self, name):
3636
print '''
3737
cdef class %(name)s(GraphQLAst):
3838
39-
cdef %(cmodule)s.%(name)s* _wrapped
39+
cdef const %(cmodule)s.%(name)s* _wrapped
4040
4141
@staticmethod
42-
cdef create(cGraphQLAst.%(name)s *thing)
42+
cdef create(const cGraphQLAst.%(name)s *thing)
4343
4444
''' % {'name': st_name, 'cmodule': ast_cython_c.CMODULE_NAME}
4545
self._current_type = name

ast/ast_cython_impl.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def get_%(snake)s(self):
5555
# python object return type
5656
return '''
5757
def get_%(snake)s(self):
58-
cdef %(cmodule)s.%(return_st)s *next
58+
cdef const %(cmodule)s.%(return_st)s *next
5959
next = %(cmodule)s.%(owning_st)s_get_%(snake)s(self._wrapped)
6060
if next is NULL:
6161
return None
@@ -88,7 +88,7 @@ def start_type(self, name):
8888
cdef class %(name)s(GraphQLAst):
8989
9090
@staticmethod
91-
cdef create(%(cmodule)s.%(name)s *thing):
91+
cdef create(const %(cmodule)s.%(name)s *thing):
9292
node = %(name)s()
9393
node._wrapped = thing
9494
return node

ast/ast_cython_visitor.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def end_file(self):
5050

5151
print '''
5252
void graphql_node_visit(GraphQLAstNode *node,
53-
GraphQLAstVisitorCallbacks *callbacks,
53+
const GraphQLAstVisitorCallbacks *callbacks,
5454
void *userData)
5555
'''
5656

ast/ast_cython_visitor_impl.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def end_file(self):
5555
_map = {'snake': snake(type), 'name': type, 'cmodule': CMODULE_NAME}
5656
print '''
5757
58-
cdef int _visit_%(snake)s(%(cmodule)s.GraphQLAst%(name)s* node, void* userData, int end):
58+
cdef int _visit_%(snake)s(const %(cmodule)s.GraphQLAst%(name)s* node, void* userData, int end):
5959
cdef GraphQLAstVisitor visitor
6060
ast = GraphQLAst.GraphQLAst%(name)s.create(node)
6161
if userData is not NULL:
@@ -66,10 +66,10 @@ def end_file(self):
6666
retval = fun(ast)
6767
return 0 if retval is None else retval
6868
69-
cdef int visit_%(snake)s(%(cmodule)s.GraphQLAst%(name)s* node, void* userData):
69+
cdef int visit_%(snake)s(const %(cmodule)s.GraphQLAst%(name)s* node, void* userData):
7070
return _visit_%(snake)s(node, userData, 0)
7171
72-
cdef void end_visit_%(snake)s(%(cmodule)s.GraphQLAst%(name)s* node, void* userData):
72+
cdef void end_visit_%(snake)s(const %(cmodule)s.GraphQLAst%(name)s* node, void* userData):
7373
_visit_%(snake)s(node, userData, 1)
7474
''' % _map
7575

examples/visitor_example.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def visit_document(self, node):
1414
return 1
1515

1616
def visit_operation_definition(self, node):
17-
print(node.__class__, node.get_operation(), node.get_name().get_value())
17+
print(node.__class__, node.get_operation())
1818
return 1
1919

2020
def visit_variable_definition(self, node):
@@ -65,7 +65,14 @@ def visit_int_value(self, node):
6565
print(node.__class__, node.get_value())
6666
return 1
6767

68+
def visit_string_value(self, node):
69+
print(node.__class__, node.get_value())
70+
return 1
71+
6872
if __name__ == '__main__':
69-
query = sys.argv[1]
70-
node = GraphQLParser.graphql_parse_string(query)
73+
import argparse
74+
parser = argparse.ArgumentParser(description='GraphQL parser example')
75+
parser.add_argument('query')
76+
args = parser.parse_args()
77+
node = GraphQLParser.graphql_parse_string(args.query)
7178
Visitor().visit_node(node)

graphql_parser/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ GraphQLAstVisitor.pyx
66
*~
77
*.c
88
.python-version
9+
*.so
10+
*.html
11+
.pytest_cache

graphql_parser/GraphQLParser.pyx

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ class GraphQLParseError(Exception):
99

1010

1111
def graphql_parse_string(text):
12-
cdef char* error_c = NULL
13-
cdef char* text_c
12+
cdef const char* error_c = NULL
13+
cdef const char* text_c
1414
cdef cGraphQLAstNode.GraphQLAstNode* node_c
1515
byte_string = text.encode()
1616
text_c = byte_string

graphql_parser/cGraphQLParser.pxd

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ cdef extern from "GraphQLParser.h":
22
struct GraphQLAstNode:
33
pass
44

5-
GraphQLAstNode* graphql_parse_string(char* text, char** error)
5+
GraphQLAstNode* graphql_parse_string(const char* text, const char** error)

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
setup(
1717
name='graphqlparser',
18-
version='0.0.3',
18+
version='0.0.4',
1919
author='Marco Paolini',
2020
author_email='markopaolini@gmail.com',
2121
description='Python bindings for libgraphqlparser (Cython-based)',

0 commit comments

Comments
 (0)