8000 Autoformat files after rendering · enixdark/python-betterproto@7e2dc59 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7e2dc59

Browse files
committed
Autoformat files after rendering
1 parent 6fd9612 commit 7e2dc59

File tree

4 files changed

+62
-18
lines changed

4 files changed

+62
-18
lines changed

Pipfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ protobuf = "*"
1515
jinja2 = "*"
1616
grpclib = "*"
1717
stringcase = "*"
18+
black = "*"
1819

1920
[requires]
2021
python_version = "3.7"
@@ -23,3 +24,6 @@ python_version = "3.7"
2324
plugin = "protoc --plugin=protoc-gen-custom=betterproto/plugin.py --custom_out=output"
2425
generate = "python betterproto/tests/generate.py"
2526
test = "pytest ./betterproto/tests"
27+
28+
[pipenv]
29+
allow_prereleases = true

Pipfile.lock

Lines changed: 49 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

betterproto/plugin.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99
from typing import Any, List, Tuple
1010

1111
try:
12-
import jinja2
12+
import black
1313
except ImportError:
1414
print(
15-
"Unable to import `jinja2`. Did you install the compiler feature with `pip install betterproto[compiler]`?"
15+
"Unable to import `black` formatter. Did you install the compiler feature with `pip install betterproto[compiler]`?"
1616
)
1717
raise SystemExit(1)
1818

19+
import jinja2
1920
import stringcase
2021

2122
from google.protobuf.compiler import plugin_pb2 as plugin
@@ -398,8 +399,11 @@ def generate_code(request, response):
398399
# print(filename, file=sys.stderr)
399400
f.name = filename.replace(".", os.path.sep) + ".py"
400401

401-
# f.content = json.dumps(output, indent=2)
402-
f.content = template.render(description=output).rstrip("\n") + "\n"
402+
# Render and then format the output file.
403+
f.content = black.format_str(
404+
template.render(description=output),
405+
mode=black.FileMode(target_versions=set([black.TargetVersion.PY37])),
406+
)
403407

404408
inits = set([""])
405409
for f in response.file:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919
package_data={"betterproto": ["py.typed", "templates/template.py"]},
2020
python_requires=">=3.7",
2121
install_requires=["grpclib", "stringcase"],
22-
extras_require={"compiler": ["jinja2", "protobuf"]},
22+
extras_require={"compiler": ["black", "jinja2", "protobuf"]},
2323
zip_safe=False,
2424
)

0 commit comments

Comments
 (0)
0