Skip to content

Commit 33f74f6

Browse files
committed
Fix comment indent bug; bump version
1 parent 3d5c12c commit 33f74f6

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [1.2.1] - 2019-10-29
11+
12+
- Fix comment indentation bug in rendered gRPC methods.
13+
1014
## [1.2.0] - 2019-10-28
1115

1216
- Generated code output auto-formatting via [Black](https://github.com/psf/black)
@@ -29,7 +33,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2933

3034
- Initial release
3135

32-
[unreleased]: https://github.com/danielgtaylor/python-betterproto/compare/v1.2.0...HEAD
36+
[unreleased]: https://github.com/danielgtaylor/python-betterproto/compare/v1.2.1...HEAD
37+
[1.2.1]: https://github.com/danielgtaylor/python-betterproto/compare/v1.2.0...v1.2.1
3338
[1.2.0]: https://github.com/danielgtaylor/python-betterproto/compare/v1.1.0...v1.2.0
3439
[1.1.0]: https://github.com/danielgtaylor/python-betterproto/compare/v1.0.1...v1.1.0
3540
[1.0.1]: https://github.com/danielgtaylor/python-betterproto/compare/v1.0.0...v1.0.1

betterproto/plugin.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,25 +142,26 @@ def _traverse(path, items):
142142
)
143143

144144

145-
def get_comment(proto_file, path: List[int]) -> str:
145+
def get_comment(proto_file, path: List[int], indent: int = 4) -> str:
146+
pad = " " * indent
146147
for sci in proto_file.source_code_info.location:
147148
# print(list(sci.path), path, file=sys.stderr)
148149
if list(sci.path) == path and sci.leading_comments:
149150
lines = textwrap.wrap(
150-
sci.leading_comments.strip().replace("\n", ""), width=75
151+
sci.leading_comments.strip().replace("\n", ""), width=79 - indent
151152
)
152153

153154
if path[-2] == 2 and path[-4] != 6:
154155
# This is a field
155-
return " # " + "\n # ".join(lines)
156+
return f"{pad}# " + f"\n{pad}# ".join(lines)
156157
else:
157158
# This is a message, enum, service, or method
158-
if len(lines) == 1 and len(lines[0]) < 70:
159+
if len(lines) == 1 and len(lines[0]) < 79 - indent - 6:
159160
lines[0] = lines[0].strip('"')
160-
return f' """{lines[0]}"""'
161+
return f'{pad}"""{lines[0]}"""'
161162
else:
162-
joined = "\n ".join(lines)
163-
return f' """\n {joined}\n """'
163+
joined = f"\n{pad}".join(lines)
164+
return f'{pad}"""\n{pad}{joined}\n{pad}"""'
164165

165166
return ""
166167

@@ -371,7 +372,7 @@ def generate_code(request, response):
371372
{
372373
"name": method.name,
373374
"py_name": stringcase.snakecase(method.name),
374-
"comment": get_comment(proto_file, [6, i, 2, j]),
375+
"comment": get_comment(proto_file, [6, i, 2, j], indent=8),
375376
"route": f"/{package}.{service.name}/{method.name}",
376377
"input": get_ref_type(
377378
package, output["imports"], method.input_type

betterproto/templates/template.py

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)