Skip to content

Commit

Permalink
feat(buf): pass input argument through to buf
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud committed Apr 2, 2022
1 parent f62cdb6 commit aacae63
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
5 changes: 3 additions & 2 deletions protoletariat/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,10 @@ def protoc(
show_envvar=True,
help="Path to the `buf` executable",
)
@click.argument("input", type=str, default=os.curdir)
@click.pass_context
def buf(ctx: click.Context, buf_path: str) -> None:
Buf(buf_path=os.fsdecode(buf_path)).fix_imports(**ctx.obj)
def buf(ctx: click.Context, buf_path: str, input: str) -> None:
Buf(buf_path=os.fsdecode(buf_path), input=os.fsdecode(input)).fix_imports(**ctx.obj)


@main.command(help="Rewrite imports using FileDescriptorSet bytes from a file or stdin")
Expand Down
6 changes: 5 additions & 1 deletion protoletariat/fdsetgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,18 @@ def generate_file_descriptor_set_bytes(self) -> bytes:
class Buf(FileDescriptorSetGenerator):
"""Generate the FileDescriptorSet using `buf`."""

def __init__(self, *, buf_path: str) -> None:
def __init__(self, *, buf_path: str, input: str) -> None:
"""Construct a `buf`-based `FileDescriptorSetGenerator`.
Parameters
----------
buf_path
Path to buf executable
input
The source or module to build
"""
self.buf_path = buf_path
self.input = input

def generate_file_descriptor_set_bytes(self) -> bytes:
return subprocess.check_output(
Expand All @@ -155,6 +158,7 @@ def generate_file_descriptor_set_bytes(self) -> bytes:
"build",
"--as-file-descriptor-set",
"--exclude-source-info",
self.input,
"--output",
"-",
]
Expand Down
2 changes: 1 addition & 1 deletion protoletariat/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def do_generate(self, cli: CliRunner, *, args: Iterable[str] = ()) -> Result:
else:
return cli.invoke(
main,
["--python-out", str(self.package_dir), *args, "buf"],
["--python-out", str(self.package_dir), *args, "buf", os.getcwd()],
catch_exceptions=False,
)

Expand Down

0 comments on commit aacae63

Please sign in to comment.