mirror of https://github.com/databricks/cli.git
fix re-patching and add test
This commit is contained in:
parent
552920dfe4
commit
b4273f9624
|
@ -185,12 +185,9 @@ func PatchWheel(ctx context.Context, path, outputDir string) (string, error) {
|
|||
metadataSize := len(newMetadata)
|
||||
|
||||
// Compute the new dist-info directory prefix.
|
||||
newDistInfoPrefix := ""
|
||||
if idx := strings.LastIndex(oldDistInfoPrefix, "-"); idx != -1 {
|
||||
base := oldDistInfoPrefix[:idx]
|
||||
newDistInfoPrefix = base + "-" + newVersion + ".dist-info/"
|
||||
} else {
|
||||
return "", fmt.Errorf("unexpected dist-info directory format: %s", oldDistInfoPrefix)
|
||||
newDistInfoPrefix := strings.Replace(oldDistInfoPrefix, wheelInfo.Version, newVersion, 1)
|
||||
if newDistInfoPrefix == oldDistInfoPrefix {
|
||||
return "", fmt.Errorf("unexpected dist-info directory format: %s (version=%s)", oldDistInfoPrefix, wheelInfo.Version)
|
||||
}
|
||||
|
||||
recordReader, err := recordFile.Open()
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
@ -120,11 +121,9 @@ func TestPatchWheel(t *testing.T) {
|
|||
distDir := filepath.Join(tempDir, "dist")
|
||||
origWheel := getWheel(t, distDir)
|
||||
|
||||
// First patch
|
||||
patchedWheel, err := PatchWheel(context.Background(), origWheel, distDir)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Get file info of the patched wheel
|
||||
patchedInfo, err := os.Stat(patchedWheel)
|
||||
require.NoError(t, err)
|
||||
patchedTime := patchedInfo.ModTime()
|
||||
|
@ -141,11 +140,19 @@ func TestPatchWheel(t *testing.T) {
|
|||
require.Equal(t, patchedTime, patchedInfo2.ModTime(), "File was recreated when it shouldn't have been")
|
||||
|
||||
runCmd(t, tempDir, "uv", "pip", "install", "-q", patchedWheel)
|
||||
|
||||
// Verify the installed version matches what we expect
|
||||
verifyVersion(t, tempDir, patchedWheel)
|
||||
|
||||
// TODO: install one more patched wheel (add an option to PatchWheel to add extra to timestamp)
|
||||
newTime := patchedInfo.ModTime().Add(10 * time.Millisecond)
|
||||
|
||||
err = os.Chtimes(origWheel, newTime, newTime)
|
||||
require.NoError(t, err)
|
||||
|
||||
patchedWheel3, err := PatchWheel(context.Background(), origWheel, distDir)
|
||||
require.NoError(t, err)
|
||||
require.Greater(t, patchedWheel3, patchedWheel)
|
||||
|
||||
runCmd(t, tempDir, "uv", "pip", "install", "-q", patchedWheel3)
|
||||
verifyVersion(t, tempDir, patchedWheel3)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue