Skip to content

Commit f69dd34

Browse files
author
Karl Rieb
committed
Fixed generator to work for both Python2 and Python3.
1 parent d77a405 commit f69dd34

File tree

4 files changed

+27
-22
lines changed

4 files changed

+27
-22
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,7 @@ gradle.properties
1515
/ReadMe.html
1616

1717
# editor temp files
18-
*~
18+
*~
19+
20+
# pyc files from generator
21+
*.pyc

buildSrc/src/main/groovy/com/dropbox/stone/gradle/StoneTask.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ public class StoneTask extends DefaultTask {
245245
project.exec {
246246
environment PYTHONPATH: getStoneDir().absolutePath
247247
standardOutput = log
248-
commandLine "python3", "-m", "stone.cli"
248+
commandLine "python", "-m", "stone.cli"
249249
args "--clean-build"
250250

251251
for (String namespace : getWhitelistedNamespaces()) {

generator/java.stoneg.py

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,7 @@ def _as_java_class(self, name):
10681068
10691069
:rtype: :class:`JavaClass`
10701070
"""
1071-
assert isinstance(name, str), repr(name)
1071+
assert isinstance(name, six.text_type), repr(name)
10721072
package = self.java_package
10731073
# only add package if we don't have one already. use
10741074
# upper-casing of class names as indicator of whether this is
@@ -1939,8 +1939,8 @@ def __init__(self, ctx):
19391939
self._ctx = ctx
19401940

19411941
def lookup_stone_ref(self, tag, val, context=None):
1942-
assert isinstance(tag, str), repr(tag)
1943-
assert isinstance(val, str), repr(val)
1942+
assert isinstance(tag, six.text_type), repr(tag)
1943+
assert isinstance(val, six.text_type), repr(val)
19441944
assert context is None or isinstance(context, StoneWrapper), repr(context)
19451945

19461946
if tag == 'route':
@@ -2028,11 +2028,11 @@ def generate_javadoc(self, doc, context=None, fields=(), params=(), returns=None
20282028
doc = wrapper.stone_doc
20292029
context = context or wrapper
20302030

2031-
assert isinstance(doc, str), repr(doc)
2031+
assert isinstance(doc, six.text_type), repr(doc)
20322032
assert isinstance(context, StoneWrapper) or context is None, repr(context)
20332033
assert isinstance(fields, (Sequence, types.GeneratorType)), repr(fields)
20342034
assert isinstance(params, (Sequence, types.GeneratorType, OrderedDict)), repr(params)
2035-
assert isinstance(returns, (str, StoneWrapper)) or returns is None, repr(returns)
2035+
assert isinstance(returns, (six.text_type, StoneWrapper)) or returns is None, repr(returns)
20362036
assert isinstance(throws, (Sequence, types.GeneratorType, OrderedDict)), repr(throws)
20372037
assert isinstance(deprecated, (RouteWrapper, bool)) or deprecated is None, repr(deprecated)
20382038

@@ -2068,7 +2068,7 @@ def generate_javadoc(self, doc, context=None, fields=(), params=(), returns=None
20682068
)
20692069

20702070
def generate_javadoc_raw(self, doc, params=None, returns=None, throws=None, deprecated=None):
2071-
# deprecated can be an empty str, which means no doc
2071+
# deprecated can be an empty six.text_type, which means no doc
20722072
if not any((doc, params, returns, throws, deprecated is not None)):
20732073
return
20742074

@@ -2157,7 +2157,7 @@ def javadoc_params(self, fields, allow_defaults=True):
21572157

21582158
def javadoc_throws(self, field, value_name=None):
21592159
assert isinstance(field, FieldWrapper), repr(field)
2160-
assert value_name is None or isinstance(value_name, str), repr(value_name)
2160+
assert value_name is None or isinstance(value_name, six.text_type), repr(value_name)
21612161

21622162
reasons = self._field_validation_requirements(field, as_failure_reasons=True)
21632163
throws = OrderedDict()
@@ -2233,7 +2233,7 @@ def add_req(precondition, failure_reason):
22332233
return requirements
22342234

22352235
def _split_id(self, stone_id, max_parts):
2236-
assert isinstance(stone_id, str), repr(stone_id)
2236+
assert isinstance(stone_id, six.text_type), repr(stone_id)
22372237
assert max_parts > 0, "max_parts must be positive"
22382238

22392239
parts = stone_id.split('.')
@@ -2246,7 +2246,7 @@ def _split_id(self, stone_id, max_parts):
22462246
return filler + tuple(parts)
22472247

22482248
def _lookup_stone_namespace(self, namespace, context):
2249-
assert isinstance(namespace, str) or namespace is None, repr(namespace)
2249+
assert isinstance(namespace, six.text_type) or namespace is None, repr(namespace)
22502250
assert isinstance(context, StoneWrapper) or context is None, repr(context)
22512251

22522252
if namespace:
@@ -2259,7 +2259,7 @@ def _lookup_stone_namespace(self, namespace, context):
22592259
return None
22602260

22612261
def _lookup_route(self, namespace, route, context):
2262-
assert isinstance(route, str) or route is None, repr(route)
2262+
assert isinstance(route, six.text_type) or route is None, repr(route)
22632263
if namespace: assert route, "Cannot specify namespace name without route name"
22642264

22652265
stone_namespace = self._lookup_stone_namespace(namespace, context)
@@ -2277,7 +2277,7 @@ def _lookup_route(self, namespace, route, context):
22772277
return None
22782278

22792279
def _lookup_data_type(self, namespace, data_type, context):
2280-
assert isinstance(data_type, str) or data_type is None, repr(data_type)
2280+
assert isinstance(data_type, six.text_type) or data_type is None, repr(data_type)
22812281
if namespace: assert data_type, "Cannot specify namespace name without data_type name"
22822282

22832283
stone_namespace = self._lookup_stone_namespace(namespace, context)
@@ -2301,7 +2301,7 @@ def _lookup_data_type(self, namespace, data_type, context):
23012301
return None
23022302

23032303
def _lookup_field(self, namespace, data_type, field, context):
2304-
assert isinstance(field, str) or field is None, repr(data_type)
2304+
assert isinstance(field, six.text_type) or field is None, repr(data_type)
23052305
if data_type: assert field, "Cannot specify data_type name without field name"
23062306

23072307
data_type = self._lookup_data_type(namespace, data_type, context)
@@ -2872,7 +2872,7 @@ def generate_route_base(self, route, force_public=False):
28722872
returns=None
28732873

28742874
return_type = route.java_return_type
2875-
throws = ', '.join(map(str, route.java_throws))
2875+
throws = ', '.join(map(six.text_type, route.java_throws))
28762876
if route.has_arg:
28772877
method_arg_type = arg_type.java_type()
28782878
method_arg_name = arg_type.java_name
@@ -2935,7 +2935,7 @@ def generate_route(self, route, required_only=True):
29352935
arg_type = route.arg
29362936
result_type = route.result
29372937
return_type = route.java_return_type
2938-
throws = ', '.join(map(str, route.java_throws))
2938+
throws = ', '.join(map(six.text_type, route.java_throws))
29392939

29402940
assert arg_type.is_struct, repr(arg_type)
29412941

@@ -3074,7 +3074,7 @@ def translate_error_wrapper(self, route, error_wrapper_var):
30743074
ew=error_wrapper_var,
30753075
)
30763076

3077-
def generate_route_simple_call(self, route, arg_var, *other_args, before=''):
3077+
def generate_route_simple_call(self, route, arg_var, before, *other_args):
30783078
out = self.g.emit
30793079

30803080
with self.g.block('try'):
@@ -3100,20 +3100,22 @@ def generate_route_simple_call(self, route, arg_var, *other_args, before=''):
31003100
out('throw %s' % self.translate_error_wrapper(route, 'ex'))
31013101

31023102
def generate_route_rpc_call(self, route, arg_var):
3103+
# return value is optional
3104+
before = ('return ' if route.has_result else '') + 'client.rpcStyle'
31033105
self.generate_route_simple_call(
31043106
route,
31053107
arg_var,
3106-
# return value is optional
3107-
before=('return ' if route.has_result else '') + 'client.rpcStyle',
3108+
before,
31083109
)
31093110

31103111
def generate_route_download_call(self, route, arg_var, headers_var):
3112+
# always need to return a downloader
3113+
before = 'return client.downloadStyle'
31113114
self.generate_route_simple_call(
31123115
route,
31133116
arg_var,
3117+
before,
31143118
headers_var,
3115-
# always need to return a downloader
3116-
before='return client.downloadStyle',
31173119
)
31183120

31193121
def generate_route_upload_call(self, route, arg_var):

stone_legacy.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ project.sourceSets.all { SourceSet sourceSet ->
4747

4848
project.exec {
4949
standardOutput = new FileOutputStream(logFile)
50-
commandLine "python3", "-m", "stone.cli"
50+
commandLine "python", "-m", "stone.cli"
5151

5252
environment PYTHONPATH: file(stoneDir).absolutePath
5353
args "--clean-build"

0 commit comments

Comments
 (0)