Skip to content

Commit

Permalink
Use Python version in Go
Browse files Browse the repository at this point in the history
  • Loading branch information
nevillelyh committed Dec 12, 2024
1 parent 529860f commit 19e6f4f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
*.egg-info
.direnv/
.envrc
.idea
/.idea
/dist
/internal/util/version.txt
/python/coglet/_version.py
/uv.lock
__pycache__
python/coglet/_version.py
uv.lock
3 changes: 1 addition & 2 deletions cmd/cog-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/peterbourgon/ff/v4/ffhelp"
"github.com/replicate/go/logging"
"github.com/replicate/go/must"
"github.com/replicate/go/version"
_ "go.uber.org/automaxprocs"

"github.com/replicate/cog-runtime/internal/server"
Expand Down Expand Up @@ -111,7 +110,7 @@ func main() {
os.Exit(1)
}

log.Infow("starting Cog HTTP server", "version", version.Version())
log.Infow("starting Cog HTTP server", "version", util.Version())
ctx, cancel := context.WithCancel(context.Background())
go func() {
ch := make(chan os.Signal, 1)
Expand Down
15 changes: 15 additions & 0 deletions internal/util/util.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package util

import (
"embed"
_ "embed"
"encoding/base32"
"fmt"
"os"
Expand Down Expand Up @@ -58,3 +60,16 @@ func JoinLogs(logs []string) string {
}
return r
}

// Wildcard match in case version.txt is not generated yet
//
//go:embed *
var embedFS embed.FS

func Version() string {
bs, err := embedFS.ReadFile("version.txt")
if err != nil {
return "0.0.0+unknown"
}
return strings.TrimSpace(string(bs))
}
19 changes: 19 additions & 0 deletions script/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

# Build binaries

set -euo pipefail

base_dir="$(git rev-parse --show-toplevel)"

cd "$base_dir"
python -m build

# Export Python version to Go
python -c 'import coglet; print(coglet.__version__)' > internal/util/version.txt

for os in darwin linux; do
for arch in amd64 arm64; do
CGO_ENABLED=0 GOOS=$os GOARCH=$arch go build -o dist/cog-server-$os-$arch ./cmd/cog-server
done
done

0 comments on commit 19e6f4f

Please sign in to comment.