mirror of https://github.com/databricks/cli.git
do not return error from readMetadataAndRecord; make parse() work only on filenames (without path)
This commit is contained in:
parent
6a7fae08ba
commit
d54d093ecf
|
@ -2,7 +2,6 @@ package patchwheel
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -16,8 +15,7 @@ type WheelInfo struct {
|
||||||
// ParseWheelFilename parses a wheel filename and extracts its components.
|
// ParseWheelFilename parses a wheel filename and extracts its components.
|
||||||
// Wheel filenames follow the pattern: {distribution}-{version}-{python_tag}-{abi_tag}-{platform_tag}.whl
|
// Wheel filenames follow the pattern: {distribution}-{version}-{python_tag}-{abi_tag}-{platform_tag}.whl
|
||||||
func ParseWheelFilename(filename string) (*WheelInfo, error) {
|
func ParseWheelFilename(filename string) (*WheelInfo, error) {
|
||||||
base := filepath.Base(filename)
|
parts := strings.Split(filename, "-")
|
||||||
parts := strings.Split(base, "-")
|
|
||||||
if len(parts) < 5 || !strings.HasSuffix(parts[len(parts)-1], ".whl") {
|
if len(parts) < 5 || !strings.HasSuffix(parts[len(parts)-1], ".whl") {
|
||||||
return nil, fmt.Errorf("invalid wheel filename format: %s", filename)
|
return nil, fmt.Errorf("invalid wheel filename format: %s", filename)
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,10 +24,10 @@ const (
|
||||||
// readMetadataAndRecord scans the zip file for files matching the patterns
|
// readMetadataAndRecord scans the zip file for files matching the patterns
|
||||||
// "*.dist-info/METADATA" and "*.dist-info/RECORD". If multiple are found, it picks
|
// "*.dist-info/METADATA" and "*.dist-info/RECORD". If multiple are found, it picks
|
||||||
// the first one encountered.
|
// the first one encountered.
|
||||||
func readMetadataAndRecord(r *zip.ReadCloser) (metadataFile, recordFile *zip.File, oldDistInfoPrefix string, err error) {
|
func readMetadataAndRecord(r *zip.ReadCloser) (metadataFile, recordFile *zip.File, oldDistInfoPrefix string) {
|
||||||
for _, f := range r.File {
|
for _, f := range r.File {
|
||||||
// Use filepath.Match to filter files in a .dist-info directory.
|
matched, _ := filepath.Match("*.dist-info/METADATA", f.Name)
|
||||||
if matched, _ := filepath.Match("*.dist-info/METADATA", f.Name); matched {
|
if matched {
|
||||||
if metadataFile == nil {
|
if metadataFile == nil {
|
||||||
metadataFile = f
|
metadataFile = f
|
||||||
// Determine the old dist-info directory prefix.
|
// Determine the old dist-info directory prefix.
|
||||||
|
@ -35,16 +35,15 @@ func readMetadataAndRecord(r *zip.ReadCloser) (metadataFile, recordFile *zip.Fil
|
||||||
oldDistInfoPrefix = f.Name[:i+1]
|
oldDistInfoPrefix = f.Name[:i+1]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if matched, _ := filepath.Match("*.dist-info/RECORD", f.Name); matched {
|
continue
|
||||||
if recordFile == nil {
|
}
|
||||||
recordFile = f
|
|
||||||
}
|
matched, _ = filepath.Match("*.dist-info/RECORD", f.Name)
|
||||||
|
if matched && recordFile == nil {
|
||||||
|
recordFile = f
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if metadataFile == nil || recordFile == nil {
|
return metadataFile, recordFile, oldDistInfoPrefix
|
||||||
return nil, nil, "", errors.New("wheel missing required METADATA or RECORD")
|
|
||||||
}
|
|
||||||
return metadataFile, recordFile, oldDistInfoPrefix, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseMetadata scans the METADATA content for the "Version:" and "Name:" fields.
|
// parseMetadata scans the METADATA content for the "Version:" and "Name:" fields.
|
||||||
|
@ -136,7 +135,8 @@ func PatchWheel(ctx context.Context, path, outputDir string) (string, error) {
|
||||||
}
|
}
|
||||||
wheelMtime := fileInfo.ModTime().UTC()
|
wheelMtime := fileInfo.ModTime().UTC()
|
||||||
|
|
||||||
wheelInfo, err := ParseWheelFilename(path)
|
filename := filepath.Base(path)
|
||||||
|
wheelInfo, err := ParseWheelFilename(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
@ -177,9 +177,13 @@ func PatchWheel(ctx context.Context, path, outputDir string) (string, error) {
|
||||||
}
|
}
|
||||||
defer r.Close()
|
defer r.Close()
|
||||||
|
|
||||||
metadataFile, recordFile, oldDistInfoPrefix, err := readMetadataAndRecord(r)
|
metadataFile, recordFile, oldDistInfoPrefix := readMetadataAndRecord(r)
|
||||||
if err != nil {
|
if metadataFile == nil {
|
||||||
return "", err
|
return "", fmt.Errorf("wheel %s missing METADATA file", path)
|
||||||
|
}
|
||||||
|
|
||||||
|
if recordFile == nil {
|
||||||
|
return "", fmt.Errorf("wheel %s missing RECORD file", path)
|
||||||
}
|
}
|
||||||
|
|
||||||
metadataContent, err := readFile(metadataFile)
|
metadataContent, err := readFile(metadataFile)
|
||||||
|
|
Loading…
Reference in New Issue