From 7e94b81d46d6ffa9d67e9399b047d6e3494e9b3e Mon Sep 17 00:00:00 2001 From: Nick Stenning Date: Sun, 20 Oct 2024 15:04:08 +0000 Subject: [PATCH 1/3] Upgrade to Go 1.23 --- .tool-versions | 2 +- Makefile | 10 ++++++---- go.mod | 4 +++- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.tool-versions b/.tool-versions index 2f1d3539f9..c26965041d 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1 +1 @@ -golang 1.22.6 +golang 1.23.2 diff --git a/Makefile b/Makefile index e7d25afcf1..033b71d120 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,8 @@ GO ?= go # goreleaser v2.3.0 requires go 1.23; PR #1950 is where we're doing that. For # now, pin to v2.2.0 GORELEASER := $(GO) run github.com/goreleaser/goreleaser/v2@v2.2.0 +GOIMPORTS := $(GO) run golang.org/x/tools/cmd/goimports@latest +GOLINT := $(GO) run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.61.0 PYTHON ?= python TOX := $(PYTHON) -Im tox @@ -78,7 +80,7 @@ test: test-go test-python test-integration .PHONY: fmt fmt: - $(GO) run golang.org/x/tools/cmd/goimports -w -d . + $(GO) run golang.org/x/tools/cmd/goimports@latest -w -d . .PHONY: generate generate: @@ -90,12 +92,12 @@ vet: pkg/dockerfile/embed/.wheel .PHONY: check-fmt check-fmt: - $(GO) run golang.org/x/tools/cmd/goimports -d . - @test -z $$($(GO) run golang.org/x/tools/cmd/goimports -l .) + $(GOIMPORTS) -d . + @test -z $$($(GOIMPORTS) -l .) .PHONY: lint lint: pkg/dockerfile/embed/.wheel check-fmt vet - $(GO) run github.com/golangci/golangci-lint/cmd/golangci-lint run ./... + $(GOLINT) run ./... $(TOX) run --installpkg $(COG_WHEEL) -e lint,typecheck-pydantic2 .PHONY: run-docs-server diff --git a/go.mod b/go.mod index 009302ace2..5d1ca914bd 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,8 @@ module github.com/replicate/cog -go 1.22 +go 1.23 + +toolchain go1.23.2 require ( github.com/anaskhan96/soup v1.2.5 From 97a9714b34586b6155fa503beee98a00b3117792 Mon Sep 17 00:00:00 2001 From: Nick Stenning Date: Sun, 20 Oct 2024 15:09:01 +0000 Subject: [PATCH 2/3] Upgrade golangci-lint and address new warnings... ...one of which was a bona fide bug! --- .golangci.yaml | 2 +- pkg/cli/push.go | 16 ++++++++-------- pkg/config/compatibility.go | 2 -- pkg/predict/input.go | 1 - tools/compatgen/main.go | 2 +- 5 files changed, 10 insertions(+), 13 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index 4a33bc6abf..66ef0d06ae 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -22,8 +22,8 @@ run: linters: disable-all: true enable: + - copyloopvar - errcheck - - exportloopref - gocritic - gosec - govet diff --git a/pkg/cli/push.go b/pkg/cli/push.go index a48a3c8fe9..3a6463a071 100644 --- a/pkg/cli/push.go +++ b/pkg/cli/push.go @@ -68,14 +68,14 @@ func push(cmd *cobra.Command, args []string) error { err = docker.Push(imageName) if err != nil { if strings.Contains(err.Error(), "NAME_UNKNOWN") { - return fmt.Errorf("Unable to find existing Replicate model for %s. " + - "Go to replicate.com and create a new model before pushing." + - "\n\n" + - "If the model already exists, you may be getting this error " + - "because you're not logged in as owner of the model. " + - "This can happen if you did `sudo cog login` instead of `cog login` " + - "or `sudo cog push` instead of `cog push`, " + - "which causes Docker to use the wrong Docker credentials." + + return fmt.Errorf("Unable to find existing Replicate model for %s. "+ + "Go to replicate.com and create a new model before pushing."+ + "\n\n"+ + "If the model already exists, you may be getting this error "+ + "because you're not logged in as owner of the model. "+ + "This can happen if you did `sudo cog login` instead of `cog login` "+ + "or `sudo cog push` instead of `cog push`, "+ + "which causes Docker to use the wrong Docker credentials.", imageName) } return fmt.Errorf("Failed to push image: %w", err) diff --git a/pkg/config/compatibility.go b/pkg/config/compatibility.go index 4f7fc7620e..fdbaaadf88 100644 --- a/pkg/config/compatibility.go +++ b/pkg/config/compatibility.go @@ -300,7 +300,6 @@ func torchGPUPackage(ver string, cuda string) (name, cpuVersion, findLinks, extr // that is at most as high as the requested cuda version var latest *TorchCompatibility for _, compat := range TorchCompatibilityMatrix { - compat := compat if !version.Matches(compat.TorchVersion(), ver) || compat.CUDA == nil { continue } @@ -349,7 +348,6 @@ func torchvisionGPUPackage(ver, cuda string) (name, cpuVersion, findLinks, extra // most as high as the requested cuda version var latest *TorchCompatibility for _, compat := range TorchCompatibilityMatrix { - compat := compat if compat.TorchvisionVersion() != ver || compat.CUDA == nil { continue } diff --git a/pkg/predict/input.go b/pkg/predict/input.go index 113111eba8..6576571711 100644 --- a/pkg/predict/input.go +++ b/pkg/predict/input.go @@ -44,7 +44,6 @@ func NewInputs(keyVals map[string][]string) Inputs { func NewInputsWithBaseDir(keyVals map[string]string, baseDir string) Inputs { input := Inputs{} for key, val := range keyVals { - val := val if strings.HasPrefix(val, "@") { val = filepath.Join(baseDir, val[1:]) input[key] = Input{File: &val} diff --git a/tools/compatgen/main.go b/tools/compatgen/main.go index 826c39a7ec..b91e75396d 100644 --- a/tools/compatgen/main.go +++ b/tools/compatgen/main.go @@ -61,6 +61,6 @@ func main() { rootCmd.Flags().StringVarP(&output, "output", "o", "", "Output flag (optional)") if err := rootCmd.Execute(); err != nil { - console.Fatalf(err.Error()) + console.Fatal(err.Error()) } } From 6dae01ae79ee0303504d26a9366bc4d9c2785cca Mon Sep 17 00:00:00 2001 From: Nick Stenning Date: Sun, 20 Oct 2024 15:12:45 +0000 Subject: [PATCH 3/3] Bump goreleaser now we're on 1.23 --- Makefile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 033b71d120..d930da4a0d 100644 --- a/Makefile +++ b/Makefile @@ -7,9 +7,7 @@ BINDIR = $(PREFIX)/bin INSTALL := install -m 0755 GO ?= go -# goreleaser v2.3.0 requires go 1.23; PR #1950 is where we're doing that. For -# now, pin to v2.2.0 -GORELEASER := $(GO) run github.com/goreleaser/goreleaser/v2@v2.2.0 +GORELEASER := $(GO) run github.com/goreleaser/goreleaser/v2@v2.3.2 GOIMPORTS := $(GO) run golang.org/x/tools/cmd/goimports@latest GOLINT := $(GO) run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.61.0