compiler: Run isort on compiled code (#355)
This commit is contained in:
committed by
GitHub
parent
70310c9e8c
commit
1aaf7728cc
@@ -4,6 +4,7 @@ import os.path
|
||||
try:
|
||||
# betterproto[compiler] specific dependencies
|
||||
import black
|
||||
import isort.api
|
||||
import jinja2
|
||||
except ImportError as err:
|
||||
print(
|
||||
@@ -32,7 +33,19 @@ def outputfile_compiler(output_file: OutputTemplate) -> str:
|
||||
)
|
||||
template = env.get_template("template.py.j2")
|
||||
|
||||
code = template.render(output_file=output_file)
|
||||
code = isort.api.sort_code_string(
|
||||
code=code,
|
||||
show_diff=False,
|
||||
py_version=37,
|
||||
profile="black",
|
||||
combine_as_imports=True,
|
||||
lines_after_imports=2,
|
||||
quiet=True,
|
||||
force_grid_wrap=2,
|
||||
known_third_party=["grpclib", "betterproto"],
|
||||
)
|
||||
return black.format_str(
|
||||
template.render(output_file=output_file),
|
||||
src_contents=code,
|
||||
mode=black.Mode(),
|
||||
)
|
||||
|
||||
@@ -16,6 +16,9 @@ from typing import {% for i in output_file.typing_imports|sort %}{{ i }}{% if no
|
||||
|
||||
import betterproto
|
||||
from betterproto.grpc.grpclib_server import ServiceBase
|
||||
{% for i in output_file.imports|sort %}
|
||||
{{ i }}
|
||||
{% endfor %}
|
||||
{% if output_file.services %}
|
||||
import grpclib
|
||||
{% endif %}
|
||||
@@ -216,7 +219,3 @@ class {{ service.py_name }}Base(ServiceBase):
|
||||
}
|
||||
|
||||
{% endfor %}
|
||||
|
||||
{% for i in output_file.imports|sort %}
|
||||
{{ i }}
|
||||
{% endfor %}
|
||||
|
||||
Reference in New Issue
Block a user