Skip to content

Commit

Permalink
migrate to uv and hatchling
Browse files Browse the repository at this point in the history
  • Loading branch information
jmelahman committed Dec 26, 2024
1 parent 73e738b commit c4f8f4a
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 47 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ jobs:
runs-on: ubuntu-latest
environment:
name: release
permissions:
id-token: write
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -42,8 +44,7 @@ jobs:
go-version: stable
cache: false
- uses: astral-sh/setup-uv@v5
- run: uv build --wheel
- run: uvx twine upload dist/*
env:
TWINE_USERNAME: ${{ secrets.TWINE_USERNAME }}
TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
with:
enable-cache: false
- run: uv build
- run: uv publish
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,10 @@ go.work.sum

# env file
.env

# python packaging
dist/
*.egg-info/
*.dist-info/
__pycache__
work
22 changes: 22 additions & 0 deletions hatch_build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import os
import subprocess

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


class GoBinaryBuildHook(BuildHookInterface):
def initialize(self, version, build_data):
build_data["pure_python"] = False
binary_name = self.config["binary_name"]
tag = os.getenv("GITHUB_REF_NAME", "dev")
commit = os.getenv("GITHUB_SHA", "none")

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

build_data["shared_scripts"] = {binary_name: binary_name}

20 changes: 17 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
[build-system]
requires = ["setuptools>=64", "setuptools_scm>=8"]
build-backend = "setuptools.build_meta"
requires = ["hatchling", "hatch-vcs"]
build-backend = "hatchling.build"

[project]
name = "work-bin"
description = "A stupid simple time tracker"
license = {file = "LICENSE"}
authors = [{ name = "Jamison Lahman", email = "[email protected]" }]
readme = "README.md"
requires-python = ">=3.6"
keywords = [
"time-tracker", "time-management", "time",
]
classifiers = [
"Programming Language :: Go",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
]
dynamic = ["version"]

[tool.setuptools_scm]

[project.urls]
Repository = "https://github.com/jmelahman/work"

[tool.hatch.build]
include = ["go.mod", "go.sum", "**/*.go"]

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

[tool.hatch.build.hooks.custom]
binary_name = "work"
39 changes: 0 additions & 39 deletions setup.py

This file was deleted.

0 comments on commit c4f8f4a

Please sign in to comment.