wip; add 2 digits after seconds; check outpout; use -q

This commit is contained in:
Denis Bilenko 2025-03-03 20:34:44 +01:00
parent 3888654ac6
commit c8daa445b1
2 changed files with 18 additions and 24 deletions

View File

@ -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 // If there's already a local version (after +), strip it off
baseVersion := strings.SplitN(version, "+", 2)[0] baseVersion := strings.SplitN(version, "+", 2)[0]
// Create new version by appending the current datetime. dt := strings.Replace(time.Now().UTC().Format("20060102150405.00"), ".", "", 1)
dt := time.Now().Format("20060102150405") dt = strings.Replace(dt, ".", "", 1)
// log.Warnf(ctx, "dt=%s dt1=%s\n", dt, dt1)
newVersion := baseVersion + "+" + dt 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. // Patch the METADATA content.
newMetadata, err := patchMetadata(metadataContent, newVersion) newMetadata, err := patchMetadata(metadataContent, newVersion)

View File

@ -30,7 +30,6 @@ import (
// minimalPythonProject returns a map of file paths to their contents for a minimal Python project. // minimalPythonProject returns a map of file paths to their contents for a minimal Python project.
func minimalPythonProject() map[string]string { func minimalPythonProject() map[string]string {
return map[string]string{ return map[string]string{
// pyproject.toml using modern Python packaging
"pyproject.toml": `[project] "pyproject.toml": `[project]
name = "myproj" name = "myproj"
version = "0.1.0" version = "0.1.0"
@ -66,22 +65,13 @@ func writeProjectFiles(baseDir string, files map[string]string) error {
return nil 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) { func runCmd(t *testing.T, dir, name string, args ...string) {
cmd := exec.Command(name, args...) out := captureOutput(t, dir, name, args...)
cmd.Dir = dir if len(out) > 0 {
var out bytes.Buffer t.Errorf("Output from %s %s:\n%s", name, args, out)
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)
} }
} }
// captureOutput runs a command and returns its output
func captureOutput(t *testing.T, dir, name string, args ...string) string { func captureOutput(t *testing.T, dir, name string, args ...string) string {
cmd := exec.Command(name, args...) cmd := exec.Command(name, args...)
cmd.Dir = dir cmd.Dir = dir
@ -123,8 +113,8 @@ func TestPatchWheel(t *testing.T) {
for _, py := range pythonVersions { for _, py := range pythonVersions {
t.Run(py, func(t *testing.T) { t.Run(py, func(t *testing.T) {
tempDir := t.TempDir() tempDir := t.TempDir()
//tempDir, err := os.MkdirTemp("", "pythontestdir") // tempDir, err := os.MkdirTemp("", "pythontestdir")
//t.Logf("tempDir=%s", tempDir) // t.Logf("tempDir=%s", tempDir)
// Write minimal Python project files. // Write minimal Python project files.
projFiles := minimalPythonProject() projFiles := minimalPythonProject()
@ -132,18 +122,18 @@ func TestPatchWheel(t *testing.T) {
t.Fatal(err) 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") distDir := filepath.Join(tempDir, "dist")
origWheel := getWheel(t, distDir) origWheel := getWheel(t, distDir)
//t.Logf("Found origWheel: %s", origWheel) // t.Logf("Found origWheel: %s", origWheel)
patchedWheel, err := PatchWheel(context.Background(), origWheel, distDir) patchedWheel, err := PatchWheel(context.Background(), origWheel, distDir)
require.NoError(t, err) 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 pyExec := filepath.Join(tempDir, ".venv", "bin", "python") // XXX Windows
cmdOut := captureOutput(t, tempDir, pyExec, "-c", "import myproj; myproj.print_version()") 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") { if !strings.HasPrefix(version, "0.1.0+20") {
t.Fatalf("expected version to start with 0.1.0+20, got %s", version) 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)
}) })
} }
} }