mirror of https://github.com/databricks/cli.git
wip; add 2 digits after seconds; check outpout; use -q
This commit is contained in:
parent
3888654ac6
commit
c8daa445b1
|
@ -158,10 +158,12 @@ func PatchWheel(ctx context.Context, path, outputDir string) (string, error) {
|
|||
// If there's already a local version (after +), strip it off
|
||||
baseVersion := strings.SplitN(version, "+", 2)[0]
|
||||
|
||||
// Create new version by appending the current datetime.
|
||||
dt := time.Now().Format("20060102150405")
|
||||
dt := strings.Replace(time.Now().UTC().Format("20060102150405.00"), ".", "", 1)
|
||||
dt = strings.Replace(dt, ".", "", 1)
|
||||
|
||||
// log.Warnf(ctx, "dt=%s dt1=%s\n", dt, dt1)
|
||||
newVersion := baseVersion + "+" + dt
|
||||
//log.Infof(ctx, "path=%s version=%s newVersion=%s distribution=%s", path, version, newVersion, distribution)
|
||||
// log.Infof(ctx, "path=%s version=%s newVersion=%s distribution=%s", path, version, newVersion, distribution)
|
||||
|
||||
// Patch the METADATA content.
|
||||
newMetadata, err := patchMetadata(metadataContent, newVersion)
|
||||
|
|
|
@ -30,7 +30,6 @@ import (
|
|||
// minimalPythonProject returns a map of file paths to their contents for a minimal Python project.
|
||||
func minimalPythonProject() map[string]string {
|
||||
return map[string]string{
|
||||
// pyproject.toml using modern Python packaging
|
||||
"pyproject.toml": `[project]
|
||||
name = "myproj"
|
||||
version = "0.1.0"
|
||||
|
@ -66,22 +65,13 @@ func writeProjectFiles(baseDir string, files map[string]string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// runCmd runs a command in the given directory and fails the test if it fails
|
||||
func runCmd(t *testing.T, dir, name string, args ...string) {
|
||||
cmd := exec.Command(name, args...)
|
||||
cmd.Dir = dir
|
||||
var out bytes.Buffer
|
||||
cmd.Stdout = &out
|
||||
cmd.Stderr = &out
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
t.Logf("Command failed: %s %s", name, strings.Join(args, " "))
|
||||
t.Logf("Output:\n%s", out.String())
|
||||
t.Fatal(err)
|
||||
out := captureOutput(t, dir, name, args...)
|
||||
if len(out) > 0 {
|
||||
t.Errorf("Output from %s %s:\n%s", name, args, out)
|
||||
}
|
||||
}
|
||||
|
||||
// captureOutput runs a command and returns its output
|
||||
func captureOutput(t *testing.T, dir, name string, args ...string) string {
|
||||
cmd := exec.Command(name, args...)
|
||||
cmd.Dir = dir
|
||||
|
@ -123,8 +113,8 @@ func TestPatchWheel(t *testing.T) {
|
|||
for _, py := range pythonVersions {
|
||||
t.Run(py, func(t *testing.T) {
|
||||
tempDir := t.TempDir()
|
||||
//tempDir, err := os.MkdirTemp("", "pythontestdir")
|
||||
//t.Logf("tempDir=%s", tempDir)
|
||||
// tempDir, err := os.MkdirTemp("", "pythontestdir")
|
||||
// t.Logf("tempDir=%s", tempDir)
|
||||
|
||||
// Write minimal Python project files.
|
||||
projFiles := minimalPythonProject()
|
||||
|
@ -132,18 +122,18 @@ func TestPatchWheel(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
runCmd(t, tempDir, "uv", "venv", "--python", py)
|
||||
runCmd(t, tempDir, "uv", "venv", "-q", "--python", py)
|
||||
|
||||
runCmd(t, tempDir, "uv", "build", "--wheel")
|
||||
runCmd(t, tempDir, "uv", "build", "-q", "--wheel")
|
||||
distDir := filepath.Join(tempDir, "dist")
|
||||
origWheel := getWheel(t, distDir)
|
||||
//t.Logf("Found origWheel: %s", origWheel)
|
||||
// t.Logf("Found origWheel: %s", origWheel)
|
||||
|
||||
patchedWheel, err := PatchWheel(context.Background(), origWheel, distDir)
|
||||
require.NoError(t, err)
|
||||
//t.Logf("origWheel=%s patchedWheel=%s", origWheel, patchedWheel)
|
||||
// t.Logf("origWheel=%s patchedWheel=%s", origWheel, patchedWheel)
|
||||
|
||||
runCmd(t, tempDir, "uv", "pip", "install", patchedWheel)
|
||||
runCmd(t, tempDir, "uv", "pip", "install", "-q", patchedWheel)
|
||||
|
||||
pyExec := filepath.Join(tempDir, ".venv", "bin", "python") // XXX Windows
|
||||
cmdOut := captureOutput(t, tempDir, pyExec, "-c", "import myproj; myproj.print_version()")
|
||||
|
@ -151,7 +141,9 @@ func TestPatchWheel(t *testing.T) {
|
|||
if !strings.HasPrefix(version, "0.1.0+20") {
|
||||
t.Fatalf("expected version to start with 0.1.0+20, got %s", version)
|
||||
}
|
||||
//t.Logf("Tested %s: patched version = %s", py, version)
|
||||
// t.Logf("Tested %s: patched version = %s", py, version)
|
||||
|
||||
// TODO: install one more patched wheel (add an option to PatchWheel to add extra to timestamp)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue