Skip to content

Commit

Permalink
replace setuptools with hatchling
Browse files Browse the repository at this point in the history
  • Loading branch information
jmelahman committed Dec 26, 2024
1 parent d6d4882 commit 9f11ea5
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 20 deletions.
24 changes: 7 additions & 17 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,18 @@ jobs:
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/checkout@v4
with:
persist-credentials: false
fetch-depth: 0
- name: Dependencies
uses: daaku/gh-action-apt-install@v4
- uses: daaku/gh-action-apt-install@v4
with:
packages: libasound2-dev
- name: Set up Go
uses: actions/setup-go@v5
- uses: actions/setup-go@v5
with:
go-version: stable
cache: false
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
- uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: "~> v2"
Expand All @@ -46,8 +42,7 @@ jobs:
with:
persist-credentials: false
fetch-depth: 0
- name: Dependencies
uses: daaku/gh-action-apt-install@v4
- uses: daaku/gh-action-apt-install@v4
with:
packages: libasound2-dev
- uses: actions/setup-go@v5
Expand All @@ -56,10 +51,5 @@ jobs:
cache: false
- name: Install the latest version of uv
uses: astral-sh/setup-uv@v5
- name: Build
run: uv build --wheel
- name: Upload
run: uvx twine upload dist/*
env:
TWINE_USERNAME: ${{ secrets.TWINE_USERNAME }}
TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
- run: uv build --wheel
- run: uv publish
18 changes: 18 additions & 0 deletions hatch_build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import os
import subprocess

from hatchling.builders.hooks.plugin.interface import BuildHookInterface


class GoBinaryBuildHook(BuildHookInterface):
def initialize(self, version, build_data):
binary_name = self.config["binary_name"]

if not os.path.exists(binary_name):
print(f"Building Go binary '{binary_name}'...")
subprocess.check_call(
["go", "build", f"-ldflags=-X main.version={version} -s -w", "-o", binary_name],
env={"GOOS": "linux", "GOARCH": "amd64", **os.environ},
)

build_data["artifacts"].append(binary_name)
16 changes: 13 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
[build-system]
requires = ["setuptools>=64", "setuptools_scm>=8"]
build-backend = "setuptools.build_meta"
requires = ["hatchling", "hatch-vcs"]
build-backend = "hatchling.build"

[project]
name = "nature-sounds"
description = "A nature sounds player for the command-line"
license = {file = "LICENSE"}
authors = [{ name = "Jamison Lahman", email = "[email protected]" }]
readme = "README.md"
requires-python = ">=3.6"
classifiers = [
Expand All @@ -15,5 +16,14 @@ classifiers = [
]
dynamic = ["version"]

[tool.setuptools_scm]
[tool.hatch.build]
include = ["go.mod", "go.sum", "main.go"]

[tool.hatch.version]
source = "vcs"

[tool.hatch.build.hooks.custom]
binary_name = "nature-sounds"

[tool.hatch.plugins.build.hooks.custom]
path = "hooks.py"

0 comments on commit 9f11ea5

Please sign in to comment.