2023-07-25 11:35:08 +00:00
|
|
|
package python
|
|
|
|
|
|
|
|
// TODO: move this package into the libs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"os"
|
2023-08-29 08:26:26 +00:00
|
|
|
"path/filepath"
|
2023-07-25 11:35:08 +00:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/databricks/cli/libs/log"
|
|
|
|
)
|
|
|
|
|
|
|
|
func CleanupWheelFolder(dir string) {
|
|
|
|
// there or not there - we don't care
|
2023-08-29 08:26:26 +00:00
|
|
|
os.RemoveAll(filepath.Join(dir, "__pycache__"))
|
|
|
|
os.RemoveAll(filepath.Join(dir, "build"))
|
2023-07-25 11:35:08 +00:00
|
|
|
eggInfo := FindFilesWithSuffixInPath(dir, ".egg-info")
|
|
|
|
if len(eggInfo) == 0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
for _, f := range eggInfo {
|
|
|
|
os.RemoveAll(f)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func FindFilesWithSuffixInPath(dir, suffix string) []string {
|
|
|
|
f, err := os.Open(dir)
|
|
|
|
if err != nil {
|
|
|
|
log.Debugf(context.Background(), "open dir %s: %s", dir, err)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
entries, err := f.ReadDir(0)
|
|
|
|
if err != nil {
|
|
|
|
log.Debugf(context.Background(), "read dir %s: %s", dir, err)
|
|
|
|
// todo: log
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
files := make([]string, 0)
|
|
|
|
for _, child := range entries {
|
|
|
|
if !strings.HasSuffix(child.Name(), suffix) {
|
|
|
|
continue
|
|
|
|
}
|
2023-08-29 08:26:26 +00:00
|
|
|
files = append(files, filepath.Join(dir, child.Name()))
|
2023-07-25 11:35:08 +00:00
|
|
|
}
|
|
|
|
return files
|
|
|
|
}
|