8000 More stuff · Gobot1234/python-betterproto@329d25d · GitHub
[go: up one dir, main page]

Skip to content

Commit 329d25d

Browse files
committed
More stuff
1 parent a72b907 commit 329d25d

File tree

2 files changed

+18
-22
lines changed

2 files changed

+18
-22
lines changed

src/betterproto/plugin/cli/commands.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import typer
1111
from rich.syntax import Syntax
1212

13+
from ... import __version__
1314
from ..models import monkey_patch_oneof_index
1415
from . import DEFAULT_LINE_LENGTH, VERBOSE, utils
1516
from .runner import compile_protobufs
@@ -25,6 +26,11 @@ def callback(ctx: typer.Context) -> None:
2526
rich.print(ctx.get_help())
2627

2728

29+
@app.command()
30+
def version(ctx: typer.Context) -> None:
31+
rich.print("betterproto version:", __version__)
32+
33+
2834
@app.command(context_settings={"help_option_names": ["-h", "--help"]})
2935
@utils.run_sync
3036
async def compile(
@@ -74,15 +80,14 @@ async def compile(
7480
)
7581

7682
for error in errors:
77-
if isinstance(error, SyntaxError):
83+
if isinstance(error, protobuf_parser.SyntaxError):
7884
rich.print(
7985
f"[red]File {str(error.file).strip()}:\n",
80-
Syntax(
81-
error.file.read_text(),
82-
"proto",
86+
Syntax.from_path(
87+
error.file,
8388
line_numbers=True,
8489
line_range=(max(error.lineno - 5, 0), error.lineno),
85-
), # TODO switch to .from_path but it appears to be bugged and doesnt render properly
90+
),
8691
f"{' ' * (error.offset + 3)}^\nSyntaxError: {error.msg}[red]",
8792
file=sys.stderr,
8893
)
@@ -92,7 +97,7 @@ async def compile(
9297
failed_files = "\n".join(f" - {file}" for file in protos)
9398
rich.print(
9499
f"[red]Protoc failed to generate outputs for:\n\n"
95-
f"{failed_files}\n\nSee the output for the issue:\n{' '.join(error.args)}[red]",
100+
f"{failed_files}\n\nSee the output for the issue:\n{error}[red]",
96101
file=sys.stderr,
97102
)
98103

src/betterproto/plugin/cli/runner.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
import asyncio
2-
import functools
3-
4-
from concurrent.futures import ProcessPoolExecutor
52
from typing import TYPE_CHECKING, Any, List
63

74
import protobuf_parser
@@ -35,17 +32,16 @@ async def compile_protobufs(
3532
3633
Parameters
3734
----------
38-
*files: :class:`.Path`
35+
*files
3936
The locations of the protobuf files to be generated.
40-
output: :class:`.Path`
37+
output
4138
The output directory.
4239
**kwargs:
4340
Any keyword arguments to pass to generate_code.
4441
4542
Returns
4643
-------
47-
List[:class:`CLIError`]
48-
A of exceptions from protoc.
44+
A of exceptions from protoc.
4945
"""
5046
loop = asyncio.get_event_loop()
5147

@@ -62,16 +58,11 @@ async def compile_protobufs(
6258
# Generate code
6359
response = await utils.to_thread(generate_code, request, **kwargs)
6460

65-
with ProcessPoolExecutor() as process_pool:
66-
# write multiple files concurrently
67-
await asyncio.gather(
68-
*(
69-
loop.run_in_executor(
70-
process_pool, functools.partial(write_file, output, file)
71-
)
72-
for file in response.file
73-
)
61+
await asyncio.gather(
62+
*(
63+
utils.to_thread(write_file(output, file) for file in response.file)
7464
)
65+
)
7566

7667
else:
7768
errors = await utils.to_thread(

0 commit comments

Comments
 (0)
0