-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'inject-build-subcommand'
- Loading branch information
Showing
15 changed files
with
135 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,15 @@ | ||
"""Setuptools grpc.""" | ||
|
||
from setuptools import Command, Distribution | ||
|
||
__version__ = "0.5" | ||
|
||
|
||
def has_grpc(build: Command) -> bool: | ||
build_grpc = build.get_finalized_command("build_grpc") | ||
return bool(build_grpc.proto_files + build_grpc.grpc_files) | ||
|
||
|
||
def inject_build(dist: Distribution) -> None: | ||
build = dist.get_command_class("build") | ||
build.sub_commands.insert(0, ("build_grpc", has_grpc)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[build-system] | ||
requires = ["setuptools"] | ||
build-backend = "setuptools.build_meta" | ||
|
||
[project] | ||
name = "example" | ||
version = "0" | ||
|
||
[tool.setuptools] | ||
packages = ["example"] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[build-system] | ||
requires = ["setuptools", "setuptools_grpc"] | ||
build-backend = "setuptools.build_meta" | ||
|
||
[project] | ||
name = "example" | ||
version = "0" | ||
|
||
[tool.setuptools] | ||
packages = ["example"] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
syntax = "proto3"; | ||
|
||
message Example {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[build-system] | ||
requires = ["setuptools", "setuptools_grpc"] | ||
build-backend = "setuptools.build_meta" | ||
|
||
[project] | ||
name = "example" | ||
version = "0" | ||
|
||
[tool.setuptools] | ||
packages = ["example"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[build_grpc] | ||
proto_files = **/*.proto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import shutil | ||
from pathlib import Path | ||
|
||
import pytest | ||
from build import ProjectBuilder | ||
from setuptools import Distribution | ||
from wheel_inspect import inspect_wheel | ||
|
||
from setuptools_grpc import has_grpc, inject_build | ||
|
||
|
||
@pytest.fixture | ||
def project_no_config(tmp_path): | ||
shutil.copytree(Path(__file__).parent / "project_no_config", tmp_path, dirs_exist_ok=True) | ||
builder = ProjectBuilder(tmp_path) | ||
yield builder.build("wheel", output_directory=tmp_path) | ||
|
||
|
||
@pytest.fixture | ||
def project_no_protos(tmp_path): | ||
shutil.copytree(Path(__file__).parent / "project_no_protos", tmp_path, dirs_exist_ok=True) | ||
builder = ProjectBuilder(tmp_path) | ||
yield builder.build("wheel", output_directory=tmp_path) | ||
|
||
|
||
@pytest.fixture | ||
def project_protos(tmp_path): | ||
shutil.copytree(Path(__file__).parent / "project_protos", tmp_path, dirs_exist_ok=True) | ||
builder = ProjectBuilder(tmp_path) | ||
yield builder.build("wheel", output_directory=tmp_path) | ||
|
||
|
||
def test_no_config(project_no_config): | ||
output = inspect_wheel(project_no_config) | ||
assert output["derived"]["modules"] == ["example"] | ||
|
||
|
||
def test_no_protos(project_no_protos): | ||
output = inspect_wheel(project_no_protos) | ||
assert output["derived"]["modules"] == ["example"] | ||
|
||
|
||
def test_protos(project_protos): | ||
output = inspect_wheel(project_protos) | ||
assert output["derived"]["modules"] == ["example", "example.service_pb2"] | ||
|
||
|
||
def test_inject_build(): | ||
dist = Distribution() | ||
build_cls = dist.get_command_class("build") | ||
sub_commands = list(build_cls.sub_commands) | ||
inject_build(dist) | ||
assert build_cls.sub_commands == [("build_grpc", has_grpc)] + sub_commands |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters