Skip to content

Commit a0ba4d9

Browse files
committed
testing hatchling for easier protobuf shenanigans
1 parent 66dc096 commit a0ba4d9

14 files changed

+58
-1590
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ tests/mock/client.properties
2424
/.vscode
2525
.coverage*
2626
coverage.xml
27+
/src/dataclay/proto/

compile-protos.sh

Lines changed: 0 additions & 7 deletions
This file was deleted.

compile_protos.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env python3
2+
3+
from importlib import resources
4+
from typing import Any
5+
import grpc_tools.protoc
6+
7+
try:
8+
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
9+
except ModuleNotFoundError:
10+
if __name__ != "__main__":
11+
# If we are not being run interactively, then that is an error
12+
raise
13+
BuildHookInterface = object
14+
15+
16+
def run_protoc():
17+
grpc_tools_proto = (resources.files("grpc_tools") / "_proto").resolve()
18+
grpc_tools.protoc.main(
19+
[
20+
"grpc_tools.protoc",
21+
"--proto_path=dataclay-common",
22+
"--python_out=src",
23+
"--grpc_python_out=src",
24+
"dataclay-common/dataclay/proto/common/common.proto",
25+
"dataclay-common/dataclay/proto/backend/backend.proto",
26+
"dataclay-common/dataclay/proto/metadata/metadata.proto",
27+
f"-I{grpc_tools_proto}",
28+
]
29+
)
30+
31+
32+
class CustomBuildHook(BuildHookInterface):
33+
def initialize(self, version: str, build_data: dict[str, Any]) -> None:
34+
run_protoc()
35+
36+
def dependencies(self):
37+
return ["grpcio-tools==1.48.2"]
38+
39+
40+
if __name__ == "__main__":
41+
run_protoc()

pyproject.toml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[build-system]
2-
requires = ["setuptools"]
3-
build-backend = "setuptools.build_meta"
2+
requires = ["hatchling"]
3+
build-backend = "hatchling.build"
44

55
[project]
66
name = "dataclay"
@@ -73,9 +73,6 @@ telemetry = [
7373
[project.scripts]
7474
dataclayctl = "dataclay.control.ctl:run"
7575

76-
[tool.setuptools.dynamic]
77-
version = {attr = "dataclay.__version__"}
78-
7976
[tool.isort]
8077
profile = "black"
8178
extend_skip = "src/dataclay/proto"
@@ -106,3 +103,17 @@ filterwarnings = [
106103
"error",
107104
"ignore::UserWarning",
108105
]
106+
107+
[tool.hatch.build.targets.wheel]
108+
packages = ["src/dataclay", "src/storage"]
109+
dependencies = ["grpcio-tools==1.48.2"]
110+
111+
[tool.hatch.build.targets.sdist]
112+
include = ["src/dataclay", "src/storage", "dataclay-common"]
113+
114+
[tool.hatch.version]
115+
path = "src/dataclay/__init__.py"
116+
117+
[tool.hatch.build.hooks.custom]
118+
path = "compile_protos.py"
119+
dependencies = ["grpcio-tools==1.48.2"]

src/dataclay/proto/__init__.py

Whitespace-only changes.

src/dataclay/proto/backend/__init__.py

Whitespace-only changes.

src/dataclay/proto/backend/backend_pb2.py

Lines changed: 0 additions & 72 deletions
This file was deleted.

0 commit comments

Comments
 (0)