Skip to content

Commit

Permalink
testing hatchling for easier protobuf shenanigans
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbarcelo committed Feb 11, 2025
1 parent 66dc096 commit a0ba4d9
Show file tree
Hide file tree
Showing 14 changed files with 58 additions and 1,590 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ tests/mock/client.properties
/.vscode
.coverage*
coverage.xml
/src/dataclay/proto/
7 changes: 0 additions & 7 deletions compile-protos.sh

This file was deleted.

41 changes: 41 additions & 0 deletions compile_protos.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env python3

from importlib import resources
from typing import Any
import grpc_tools.protoc

try:
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
except ModuleNotFoundError:
if __name__ != "__main__":
# If we are not being run interactively, then that is an error
raise
BuildHookInterface = object


def run_protoc():
grpc_tools_proto = (resources.files("grpc_tools") / "_proto").resolve()
grpc_tools.protoc.main(
[
"grpc_tools.protoc",
"--proto_path=dataclay-common",
"--python_out=src",
"--grpc_python_out=src",
"dataclay-common/dataclay/proto/common/common.proto",
"dataclay-common/dataclay/proto/backend/backend.proto",
"dataclay-common/dataclay/proto/metadata/metadata.proto",
f"-I{grpc_tools_proto}",
]
)


class CustomBuildHook(BuildHookInterface):
def initialize(self, version: str, build_data: dict[str, Any]) -> None:
run_protoc()

def dependencies(self):
return ["grpcio-tools==1.48.2"]


if __name__ == "__main__":
run_protoc()
21 changes: 16 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "dataclay"
Expand Down Expand Up @@ -73,9 +73,6 @@ telemetry = [
[project.scripts]
dataclayctl = "dataclay.control.ctl:run"

[tool.setuptools.dynamic]
version = {attr = "dataclay.__version__"}

[tool.isort]
profile = "black"
extend_skip = "src/dataclay/proto"
Expand Down Expand Up @@ -106,3 +103,17 @@ filterwarnings = [
"error",
"ignore::UserWarning",
]

[tool.hatch.build.targets.wheel]
packages = ["src/dataclay", "src/storage"]
dependencies = ["grpcio-tools==1.48.2"]

[tool.hatch.build.targets.sdist]
include = ["src/dataclay", "src/storage", "dataclay-common"]

[tool.hatch.version]
path = "src/dataclay/__init__.py"

[tool.hatch.build.hooks.custom]
path = "compile_protos.py"
dependencies = ["grpcio-tools==1.48.2"]
Empty file removed src/dataclay/proto/__init__.py
Empty file.
Empty file.
72 changes: 0 additions & 72 deletions src/dataclay/proto/backend/backend_pb2.py

This file was deleted.

Loading

0 comments on commit a0ba4d9

Please sign in to comment.