Fix comment indent bug; bump version
This commit is contained in:
		| @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 | |||||||
|  |  | ||||||
| ## [Unreleased] | ## [Unreleased] | ||||||
|  |  | ||||||
|  | ## [1.2.1] - 2019-10-29 | ||||||
|  |  | ||||||
|  | - Fix comment indentation bug in rendered gRPC methods. | ||||||
|  |  | ||||||
| ## [1.2.0] - 2019-10-28 | ## [1.2.0] - 2019-10-28 | ||||||
|  |  | ||||||
| - Generated code output auto-formatting via [Black](https://github.com/psf/black) | - 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 | |||||||
|  |  | ||||||
| - Initial release | - Initial release | ||||||
|  |  | ||||||
| [unreleased]: https://github.com/danielgtaylor/python-betterproto/compare/v1.2.0...HEAD | [unreleased]: https://github.com/danielgtaylor/python-betterproto/compare/v1.2.1...HEAD | ||||||
|  | [1.2.1]: https://github.com/danielgtaylor/python-betterproto/compare/v1.2.0...v1.2.1 | ||||||
| [1.2.0]: https://github.com/danielgtaylor/python-betterproto/compare/v1.1.0...v1.2.0 | [1.2.0]: https://github.com/danielgtaylor/python-betterproto/compare/v1.1.0...v1.2.0 | ||||||
| [1.1.0]: https://github.com/danielgtaylor/python-betterproto/compare/v1.0.1...v1.1.0 | [1.1.0]: https://github.com/danielgtaylor/python-betterproto/compare/v1.0.1...v1.1.0 | ||||||
| [1.0.1]: https://github.com/danielgtaylor/python-betterproto/compare/v1.0.0...v1.0.1 | [1.0.1]: https://github.com/danielgtaylor/python-betterproto/compare/v1.0.0...v1.0.1 | ||||||
|   | |||||||
| @@ -142,25 +142,26 @@ def traverse(proto_file): | |||||||
|     ) |     ) | ||||||
|  |  | ||||||
|  |  | ||||||
| def get_comment(proto_file, path: List[int]) -> str: | def get_comment(proto_file, path: List[int], indent: int = 4) -> str: | ||||||
|  |     pad = " " * indent | ||||||
|     for sci in proto_file.source_code_info.location: |     for sci in proto_file.source_code_info.location: | ||||||
|         # print(list(sci.path), path, file=sys.stderr) |         # print(list(sci.path), path, file=sys.stderr) | ||||||
|         if list(sci.path) == path and sci.leading_comments: |         if list(sci.path) == path and sci.leading_comments: | ||||||
|             lines = textwrap.wrap( |             lines = textwrap.wrap( | ||||||
|                 sci.leading_comments.strip().replace("\n", ""), width=75 |                 sci.leading_comments.strip().replace("\n", ""), width=79 - indent | ||||||
|             ) |             ) | ||||||
|  |  | ||||||
|             if path[-2] == 2 and path[-4] != 6: |             if path[-2] == 2 and path[-4] != 6: | ||||||
|                 # This is a field |                 # This is a field | ||||||
|                 return "    # " + "\n    # ".join(lines) |                 return f"{pad}# " + f"\n{pad}# ".join(lines) | ||||||
|             else: |             else: | ||||||
|                 # This is a message, enum, service, or method |                 # This is a message, enum, service, or method | ||||||
|                 if len(lines) == 1 and len(lines[0]) < 70: |                 if len(lines) == 1 and len(lines[0]) < 79 - indent - 6: | ||||||
|                     lines[0] = lines[0].strip('"') |                     lines[0] = lines[0].strip('"') | ||||||
|                     return f'    """{lines[0]}"""' |                     return f'{pad}"""{lines[0]}"""' | ||||||
|                 else: |                 else: | ||||||
|                     joined = "\n    ".join(lines) |                     joined = f"\n{pad}".join(lines) | ||||||
|                     return f'    """\n    {joined}\n    """' |                     return f'{pad}"""\n{pad}{joined}\n{pad}"""' | ||||||
|  |  | ||||||
|     return "" |     return "" | ||||||
|  |  | ||||||
| @@ -371,7 +372,7 @@ def generate_code(request, response): | |||||||
|                         { |                         { | ||||||
|                             "name": method.name, |                             "name": method.name, | ||||||
|                             "py_name": stringcase.snakecase(method.name), |                             "py_name": stringcase.snakecase(method.name), | ||||||
|                             "comment": get_comment(proto_file, [6, i, 2, j]), |                             "comment": get_comment(proto_file, [6, i, 2, j], indent=8), | ||||||
|                             "route": f"/{package}.{service.name}/{method.name}", |                             "route": f"/{package}.{service.name}/{method.name}", | ||||||
|                             "input": get_ref_type( |                             "input": get_ref_type( | ||||||
|                                 package, output["imports"], method.input_type |                                 package, output["imports"], method.input_type | ||||||
|   | |||||||
| @@ -15,8 +15,8 @@ import betterproto | |||||||
| {% if description.services %} | {% if description.services %} | ||||||
| import grpclib | import grpclib | ||||||
| {% endif %} | {% endif %} | ||||||
| {% for i in description.imports %} |  | ||||||
|  |  | ||||||
|  | {% for i in description.imports %} | ||||||
| {{ i }} | {{ i }} | ||||||
| {% endfor %} | {% endfor %} | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user