Skip to content

Instantly share code, notes, and snippets.

@ryancurrah
Created March 23, 2025 15:11
Show Gist options
  • Save ryancurrah/d45a5a23cee63a837cd6372d4755e891 to your computer and use it in GitHub Desktop.
Save ryancurrah/d45a5a23cee63a837cd6372d4755e891 to your computer and use it in GitHub Desktop.
wheelutil.go
package wheelutil
import (
"fmt"
"strings"
)
// PlatformArch represents supported platform/arch combinations.
type PlatformArch struct {
OS string
Arch string
}
// WheelName returns the expected wheel filename for given build context.
func WheelName(projectName, version, pythonVersion string, plat PlatformArch, purePython bool) (string, error) {
pyTag := formatPythonTag(pythonVersion)
if purePython {
// Pure Python wheels are platform independent.
return fmt.Sprintf("%s-%s-%s-none-any.whl", projectName, version, pyTag), nil
}
// Non-pure wheels must be platform-specific.
abiTag, platformTag, err := abiPlatformTag(pythonVersion, plat)
if err != nil {
return "", err
}
return fmt.Sprintf("%s-%s-%s-%s-%s.whl", projectName, version, pyTag, abiTag, platformTag), nil
}
func abiPlatformTag(pythonVersion string, plat PlatformArch) (string, string, error) {
abiTag := formatPythonTag(pythonVersion)
switch plat.OS {
case "linux":
return abiTag, fmt.Sprintf("manylinux_2_31_%s", plat.Arch), nil
case "darwin":
return abiTag, fmt.Sprintf("macosx_13_0_%s", plat.Arch), nil
case "windows":
winArch := plat.Arch
if plat.Arch == "amd64" {
winArch = "win_amd64"
}
return abiTag, winArch, nil
default:
return "", "", fmt.Errorf("unsupported platform: %s", plat.OS)
}
}
func formatPythonTag(pythonVersion string) string {
return fmt.Sprintf("cp%s", strings.ReplaceAll(pythonVersion, ".", ""))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment