Skip to content

Commit bc825ef

Browse files
committed
Use Ruff on generated code
1 parent 704e64c commit bc825ef

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

src/betterproto/plugin/compiler.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os.path
22
import sys
3+
import subprocess
34

45
from .module_validation import ModuleValidator
56

@@ -40,22 +41,17 @@ def outputfile_compiler(output_file: OutputTemplate) -> str:
4041

4142
code = body_template.render(output_file=output_file)
4243
code = header_template.render(output_file=output_file) + code
43-
code = isort.api.sort_code_string(
44-
code=code,
45-
show_diff=False,
46-
py_version=37,
47-
profile="black",
48-
combine_as_imports=True,
49-
lines_after_imports=2,
50-
quiet=True,
51-
force_grid_wrap=2,
52-
known_third_party=["grpclib", "betterproto"],
53-
)
54-
code = black.format_str(
55-
src_contents=code,
56-
mode=black.Mode(),
44+
45+
# Sort imports, delete unused ones
46+
code = subprocess.check_output(
47+
["ruff", "check", "--select", "I,F401", "--fix", "--silent", "-"],
48+
input=code,
49+
encoding="utf-8",
5750
)
5851

52+
# Format the code
53+
code = subprocess.check_output(["ruff", "format", "-"], input=code, encoding="utf-8")
54+
5955
# Validate the generated code.
6056
validator = ModuleValidator(iter(code.splitlines()))
6157
if not validator.validate():

0 commit comments

Comments
 (0)