Skip to content

Commit 15d6636

Browse files
committed
claude cooked
1 parent b1ce4f9 commit 15d6636

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

tools/gonyx/hatch_build.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,45 @@
22

33
import os
44
import subprocess
5+
from typing import Any
56

67
import manygo
7-
from hatchling.builders.hooks.plugin import interface
8+
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
89

910

10-
class GoBinaryBuildHook(interface.BuildHookInterface):
11-
def initialize(self, version, build_data) -> None: # noqa: ANN001, ARG002
11+
class CustomBuildHook(BuildHookInterface):
12+
"""Build hook to compile the Go binary and include it in the wheel."""
13+
14+
def initialize(self, version: Any, build_data: Any) -> None:
15+
"""Build the Go binary before packaging."""
1216
build_data["pure_python"] = False
17+
18+
# Set platform tag for cross-compilation
1319
goos = os.getenv("GOOS")
1420
goarch = os.getenv("GOARCH")
1521
if goos and goarch:
16-
build_data["tag"] = "py3-none-" + manygo.get_platform_tag(goos=goos, goarch=goarch) # type: ignore[invalid-argument-type]
17-
binary_name = self.config["binary_name"]
18-
tag = os.getenv("GITHUB_REF_NAME", "dev").lstrip("gonyx/")
22+
build_data["tag"] = "py3-none-" + manygo.get_platform_tag(
23+
goos=goos, goarch=goarch
24+
)
25+
else:
26+
build_data["infer_tag"] = True
27+
28+
# Get config and environment
29+
binary_name = self.config.get("binary_name", "gonyx")
1930
commit = os.getenv("GITHUB_SHA", "none")
2031

32+
# Build the Go binary if it doesn't exist
2133
if not os.path.exists(binary_name):
2234
print(f"Building Go binary '{binary_name}'...")
2335
subprocess.check_call( # noqa: S603
2436
[
2537
"go",
2638
"build",
27-
f"-ldflags=-X main.version={tag} -X main.commit={commit} -s -w",
39+
f"-ldflags=-X main.version={version} -X main.commit={commit} -s -w",
2840
"-o",
2941
binary_name,
3042
],
3143
)
3244

33-
build_data["shared_scripts"] = {binary_name: binary_name}
45+
# Include the binary in the wheel
46+
build_data["force_include"][binary_name] = binary_name

tools/gonyx/pyproject.toml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,16 @@ dynamic = ["version"]
2424
Repository = "https://github.com/onyx-dot-app/onyx"
2525

2626
[tool.hatch.build]
27-
include = ["go.mod", "go.sum", "main.go"]
27+
include = ["go.mod", "go.sum", "main.go", "cmd/**/*.go"]
28+
artifacts = ["gonyx"]
2829

2930
[tool.hatch.version]
3031
source = "vcs"
31-
tag-pattern = "gonyx/v(?P<version>\\d+\\.\\d+\\.\\d+)"
3232

33-
[tool.hatch.build.hooks.custom]
33+
[tool.hatch.version.raw-options]
34+
root = "../.."
35+
tag_regex = "^gonyx/v(?P<version>[vV]?\\d+(?:\\.\\d+){0,2}[^\\+]*)(?:\\+.*)?$"
36+
37+
[tool.hatch.build.targets.wheel.hooks.custom]
38+
path = "hatch_build.py"
3439
binary_name = "gonyx"

0 commit comments

Comments
 (0)