moved to separate function

This commit is contained in:
Andrew Nester 2023-08-17 17:50:00 +02:00
parent a9ed5df9fe
commit 476439c48e
No known key found for this signature in database
GPG Key ID: 12BC628A44B7DA57
1 changed files with 34 additions and 25 deletions

View File

@ -53,38 +53,47 @@ func (m *transform) Name() string {
func (m *transform) Apply(ctx context.Context, b *bundle.Bundle) error { func (m *transform) Apply(ctx context.Context, b *bundle.Bundle) error {
wheelTasks := libraries.FindAllWheelTasks(b) wheelTasks := libraries.FindAllWheelTasks(b)
for _, wheelTask := range wheelTasks { for _, wheelTask := range wheelTasks {
taskDefinition := wheelTask.PythonWheelTask err := generateNotebookTrampoline(b, wheelTask)
libraries := wheelTask.Libraries
wheelTask.PythonWheelTask = nil
wheelTask.Libraries = nil
filename, err := generateNotebookWrapper(b, taskDefinition, libraries)
if err != nil { if err != nil {
return err return err
} }
internalDir, err := getInternalDir(b)
if err != nil {
return err
}
internalDirRel, err := filepath.Rel(b.Config.Path, internalDir)
if err != nil {
return err
}
parts := []string{b.Config.Workspace.FilesPath}
parts = append(parts, strings.Split(internalDirRel, string(os.PathSeparator))...)
parts = append(parts, filename)
wheelTask.NotebookTask = &jobs.NotebookTask{
NotebookPath: path.Join(parts...),
}
} }
return nil return nil
} }
func generateNotebookTrampoline(b *bundle.Bundle, wheelTask *jobs.Task) error {
taskDefinition := wheelTask.PythonWheelTask
libraries := wheelTask.Libraries
wheelTask.PythonWheelTask = nil
wheelTask.Libraries = nil
filename, err := generateNotebookWrapper(b, taskDefinition, libraries)
if err != nil {
return err
}
internalDir, err := getInternalDir(b)
if err != nil {
return err
}
internalDirRel, err := filepath.Rel(b.Config.Path, internalDir)
if err != nil {
return err
}
parts := []string{b.Config.Workspace.FilesPath}
parts = append(parts, strings.Split(internalDirRel, string(os.PathSeparator))...)
parts = append(parts, filename)
wheelTask.NotebookTask = &jobs.NotebookTask{
NotebookPath: path.Join(parts...),
}
return nil
}
func getInternalDir(b *bundle.Bundle) (string, error) { func getInternalDir(b *bundle.Bundle) (string, error) {
cacheDir, err := b.CacheDir() cacheDir, err := b.CacheDir()
if err != nil { if err != nil {