Skip to content

Commit aab90dd

Browse files
committed
Remove submodule libgraphqlparser move everything we need into scripts.
1 parent 3bd0eb5 commit aab90dd

File tree

6 files changed

+109
-6
lines changed

6 files changed

+109
-6
lines changed

.gitmodules

Lines changed: 0 additions & 3 deletions
This file was deleted.

libgraphqlparser

Lines changed: 0 additions & 1 deletion
This file was deleted.

scripts/casing.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright (c) 2015, Facebook, Inc.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree. An additional grant
6+
# of patent rights can be found in the PATENTS file in the same directory.
7+
8+
def title(s):
9+
'''Capitalize the first character of s.'''
10+
return s[0].capitalize() + s[1:]
11+
12+
13+
def camel(s):
14+
'''Lowercase the first character of s.'''
15+
return s[0].lower() + s[1:]
16+
17+
18+
def snake(s):
19+
'''Convert from title or camelCase to snake_case.'''
20+
if len(s) < 2:
21+
return s.lower()
22+
out = s[0].lower()
23+
for c in s[1:]:
24+
if c.isupper():
25+
out += '_'
26+
c = c.lower()
27+
out += c
28+
return out

scripts/fb_ast.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/usr/bin/env python
2+
# Copyright (c) 2015, Facebook, Inc.
3+
# All rights reserved.
4+
#
5+
# This source code is licensed under the BSD-style license found in the
6+
# LICENSE file in the root directory of this source tree. An additional grant
7+
# of patent rights can be found in the PATENTS file in the same directory.
8+
9+
from importlib import import_module
10+
11+
12+
def load_lang(lang):
13+
return import_module(lang).Printer()
14+
15+
16+
def print_ast(lang_module, input_file):
17+
lang_module.start_file()
18+
line = input_file.readline()
19+
20+
while line:
21+
line = line.strip()
22+
if line.startswith('#') or not line:
23+
line = input_file.readline()
24+
continue
25+
26+
code, rest = line.split(None, 1)
27+
28+
if code[0] == 'T':
29+
lang_module.start_type(rest)
30+
field_line = input_file.readline().strip()
31+
while field_line:
32+
if field_line.startswith('#'):
33+
field_line = input_file.readline().strip()
34+
continue
35+
36+
field_kind, field_type, field_name = field_line.split()
37+
nullable = len(field_kind) > 1 and field_kind[1] == '?'
38+
39+
if field_kind[0] == 'S':
40+
plural = False
41+
42+
elif field_kind[0] == 'P':
43+
plural = True
44+
45+
else:
46+
raise Exception('Unknown field kind: ' + field_kind)
47+
48+
lang_module.field(field_type, field_name, nullable, plural)
49+
field_line = input_file.readline().strip()
50+
51+
lang_module.end_type(rest)
52+
53+
elif code[0] == 'U':
54+
lang_module.start_union(rest)
55+
field_line = input_file.readline().strip()
56+
while field_line:
57+
option_code, option_type = field_line.split()
58+
if option_code != 'O':
59+
raise Exception('Unknown code in union: ' + option_code)
60+
61+
lang_module.union_option(option_type)
62+
field_line = input_file.readline().strip()
63+
64+
lang_module.end_union(rest)
65+
66+
line = input_file.readline()
67+
68+
lang_module.end_file()
69+
70+
71+
if __name__ == '__main__':
72+
import sys
73+
74+
lang = sys.argv[1]
75+
filename = sys.argv[2]
76+
77+
lang_module = load_lang(lang)
78+
79+
print_ast(lang_module, open(filename, 'r'))

scripts/generate_ast.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
project_root = os.path.join(os.path.dirname(__file__), '..')
66
with open(os.path.join(project_root, 'graphql/core/language/ast.py'), 'w') as fp:
77
process = subprocess.Popen(
8-
['python', '../libgraphqlparser/ast/ast.py', 'generate_ast', './ast.ast'],
8+
['python', './fb_ast.py', 'generate_ast', './ast.ast'],
99
stdout=fp,
1010
cwd=os.path.join(project_root, 'scripts'),
1111
env={'PYTHONPATH': '.'}

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
url='https://github.com/graphql-python/graphql-core',
99

10-
author='GraphQL Python ',
10+
author='GraphQL Python',
1111
author_email='me' '@' 'jh.gg',
1212

1313
license='MIT',

0 commit comments

Comments
 (0)