/
Makefile
125 lines (95 loc) · 3.03 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
SHELL := bash
DESTDIR ?=
PREFIX = /usr/local
BINDIR = $(PREFIX)/bin
INSTALL := install -m 0755
INSTALL_PROGRAM := $(INSTALL)
GO ?= go
GOOS := $(shell $(GO) env GOOS)
GOARCH := $(shell $(GO) env GOARCH)
PYTHON ?= python
PYTEST := $(PYTHON) -m pytest
PYRIGHT := $(PYTHON) -m pyright
RUFF := $(PYTHON) -m ruff
default: all
.PHONY: all
all: cog
pkg/dockerfile/embed/cog.whl: python/* python/cog/* python/cog/server/* python/cog/command/*
@echo "Building Python library"
rm -rf dist
$(PYTHON) -m pip install build && $(PYTHON) -m build --wheel
mkdir -p pkg/dockerfile/embed
cp dist/*.whl $@
.PHONY: cog
cog: pkg/dockerfile/embed/cog.whl
$(eval COG_VERSION ?= $(shell git describe --tags --match 'v*' --abbrev=0)+dev)
CGO_ENABLED=0 $(GO) build -o $@ \
-ldflags "-X github.com/replicate/cog/pkg/global.Version=$(COG_VERSION) -X github.com/replicate/cog/pkg/global.BuildTime=$(shell date +%Y-%m-%dT%H:%M:%S%z) -w" \
cmd/cog/cog.go
.PHONY: base-image
base-image: pkg/dockerfile/embed/cog.whl
$(eval COG_VERSION ?= $(shell git describe --tags --match 'v*' --abbrev=0)+dev)
CGO_ENABLED=0 $(GO) build -o $@ \
-ldflags "-X github.com/replicate/cog/pkg/global.Version=$(COG_VERSION) -X github.com/replicate/cog/pkg/global.BuildTime=$(shell date +%Y-%m-%dT%H:%M:%S%z) -w" \
cmd/base-image/baseimage.go
.PHONY: install
install: cog
$(INSTALL_PROGRAM) -d $(DESTDIR)$(BINDIR)
$(INSTALL_PROGRAM) cog $(DESTDIR)$(BINDIR)/cog
.PHONY: uninstall
uninstall:
rm -f $(DESTDIR)$(BINDIR)/cog
.PHONY: clean
clean:
$(GO) clean
rm -rf build dist
rm -f cog
rm -f pkg/dockerfile/embed/cog.whl
.PHONY: test-go
test-go: pkg/dockerfile/embed/cog.whl | check-fmt vet lint-go
$(GO) get gotest.tools/gotestsum
$(GO) run gotest.tools/gotestsum -- -timeout 1200s -parallel 5 ./... $(ARGS)
.PHONY: test-integration
test-integration: cog
cd test-integration/ && $(MAKE) PATH="$(PWD):$(PATH)" test
.PHONY: test-python
test-python:
$(PYTEST) -n auto -vv --cov=python/cog --cov-report term-missing python/tests $(if $(FILTER),-k "$(FILTER)",)
.PHONY: test
test: test-go test-python test-integration
.PHONY: fmt
fmt:
$(GO) run golang.org/x/tools/cmd/goimports -w -d .
.PHONY: generate
generate:
$(GO) generate ./...
.PHONY: vet
vet:
$(GO) vet ./...
.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 .)
.PHONY: lint-go
lint-go:
$(GO) run github.com/golangci/golangci-lint/cmd/golangci-lint run ./...
.PHONY: lint-python
lint-python:
$(RUFF) check python/cog
$(RUFF) format --check python
@$(PYTHON) -c 'import sys; sys.exit("Warning: python >=3.10 is needed (not installed) to pass linting (pyright)") if sys.version_info < (3, 10) else None'
$(PYRIGHT)
.PHONY: lint
lint: lint-go lint-python
.PHONY: mod-tidy
mod-tidy:
$(GO) mod tidy
.PHONY: install-python # install dev dependencies
install-python:
$(PYTHON) -m pip install '.[dev]'
.PHONY: run-docs-server
run-docs-server:
pip install mkdocs-material
sed 's/docs\///g' README.md > ./docs/README.md
cp CONTRIBUTING.md ./docs/
mkdocs serve