Skip to content

Commit f77931a

Browse files
committed
feat: Add ./hack/build-tag.sh script to dynamically build a released tag
1 parent 063cae9 commit f77931a

File tree

7 files changed

+66
-11
lines changed

7 files changed

+66
-11
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/.idea

hack/build-tag.sh

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
DIR=$(cd $(dirname $0) && pwd)
6+
cd $DIR/..
7+
8+
PYTHON_STANDALONE_VERSION=$1
9+
PYTHON_VERSION=$2
10+
11+
if [ "$PYTHON_STANDALONE_VERSION" = "" ]; then
12+
echo "missing python-standalone version"
13+
exit 1
14+
fi
15+
16+
if [ "$PYTHON_VERSION" = "" ]; then
17+
echo "missing python version"
18+
exit 1
19+
fi
20+
21+
if [ ! -z "$(git status --porcelain)" ]; then
22+
echo "working directory is dirty!"
23+
exit 1
24+
fi
25+
26+
go run ./python/generate --python-standalone-version=$PYTHON_STANDALONE_VERSION --python-version $PYTHON_VERSION
27+
go run ./pip/generate
28+
29+
echo "checking out temporary branch"
30+
git checkout $(git rev-parse HEAD)
31+
git add -f python/internal/data
32+
git add -f pip/internal/data
33+
git commit -m "added python $PYTHON_VERSION from python-standalone $PYTHON_STANDALONE_VERSION"
34+
git tag -f v0.0.0-$PYTHON_VERSION-$PYTHON_STANDALONE_VERSION
35+
git checkout -
File renamed without changes.

pip/internal/data/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*
2+
!embed.go
3+
!.gitignore

python/internal/generate/main.go python/generate/main.go

+20-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"flag"
45
"fmt"
56
"github.com/gobwas/glob"
67
"github.com/klauspost/compress/zstd"
@@ -11,14 +12,15 @@ import (
1112
"net/http"
1213
"os"
1314
"path/filepath"
15+
"strings"
1416
"sync"
1517
)
1618

17-
// versions taken from https://github.com/indygreg/python-build-standalone/releases/
18-
const (
19-
pythonVersionBase = "3.10"
20-
pythonVersionFull = "3.10.9"
21-
pythonStandaloneVersion = "20230116"
19+
var (
20+
pythonStandaloneVersion = flag.String("python-standalone-version", "", "specify the python-standalone version. Check https://github.com/indygreg/python-build-standalone/releases/ for available options.")
21+
pythonVersion = flag.String("python-version", "", "specify the python version.")
22+
23+
pythonVersionBase string
2224
)
2325

2426
var archMapping = map[string]string{
@@ -57,6 +59,17 @@ var keepWinPatterns = []glob.Glob{
5759
var downloadLock sync.Mutex
5860

5961
func main() {
62+
flag.Parse()
63+
64+
if *pythonVersion == "" || *pythonStandaloneVersion == "" {
65+
log.Fatal("missing flags")
66+
}
67+
68+
log.Infof("python-standalone-version=%s", *pythonStandaloneVersion)
69+
log.Infof("python-version=%s", *pythonVersion)
70+
71+
pythonVersionBase = strings.Join(strings.Split(*pythonVersion, ".")[0:2], ".")
72+
6073
targetPath := "./python/internal/data"
6174

6275
var wg sync.WaitGroup
@@ -135,9 +148,9 @@ func download(osName, arch, dist string) string {
135148
log.Errorf("arch %s not supported", arch)
136149
os.Exit(1)
137150
}
138-
fname := fmt.Sprintf("cpython-%s+%s-%s-%s.tar.zst", pythonVersionFull, pythonStandaloneVersion, pythonArch, dist)
151+
fname := fmt.Sprintf("cpython-%s+%s-%s-%s.tar.zst", *pythonVersion, *pythonStandaloneVersion, pythonArch, dist)
139152
downloadPath := filepath.Join(os.TempDir(), "python-download", fname)
140-
downloadUrl := fmt.Sprintf("https://github.com/indygreg/python-build-standalone/releases/download/%s/%s", pythonStandaloneVersion, fname)
153+
downloadUrl := fmt.Sprintf("https://github.com/indygreg/python-build-standalone/releases/download/%s/%s", *pythonStandaloneVersion, fname)
141154

142155
if _, err := os.Stat(downloadPath); err == nil {
143156
log.Infof("skipping download of %s", downloadUrl)

python/internal/data/.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# we ignore these here, but the build-tag.sh script will force-add these anyway
2+
darwin-amd64
3+
darwin-arm64
4+
linux-amd64
5+
linux-arm64
6+
windows-amd64
7+
embed_*.go

python/internal/data/dummy.go

-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,3 @@ package data
44
// This file is really just a dummy. The release process will remove this file and generate some read embedded files
55
// and commit these into a temporary branch and then tag it. This is to avoid clogging up the main branch with too many
66
// binary files, which would be a very bad experience when pulling in go-embed-python as a dependency.
7-
8-
func init() {
9-
panic("You can not use the main branch of go-embed-python as a Go dependency, as this branch does not contain the necessary Python distributions. Please use a tagged release of go-embed-python instead.")
10-
}

0 commit comments

Comments
 (0)