Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: In-Place deployment for notebooks without extension #1898

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions bundle/config/mutator/translate_paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"strings"

"github.com/databricks/cli/bundle"
"github.com/databricks/cli/bundle/config"
"github.com/databricks/cli/libs/diag"
"github.com/databricks/cli/libs/dyn"
"github.com/databricks/cli/libs/notebook"
Expand Down Expand Up @@ -117,6 +118,10 @@ func (t *translateContext) rewritePath(
return nil
}

type FileInfoWithVirtualExtension interface {
VirtualExtension() string
}

func (t *translateContext) translateNotebookPath(literal, localFullPath, localRelPath, remotePath string) (string, error) {
nb, _, err := notebook.DetectWithFS(t.b.SyncRoot, filepath.ToSlash(localRelPath))
if errors.Is(err, fs.ErrNotExist) {
Expand All @@ -129,6 +134,18 @@ func (t *translateContext) translateNotebookPath(literal, localFullPath, localRe
return "", ErrIsNotNotebook{localFullPath}
}

if config.IsExplicitlyEnabled(t.b.Config.Presets.InPlaceDeployment) {
stat, err := t.b.SyncRoot.Stat(filepath.ToSlash(localRelPath))
if err != nil {
return "", fmt.Errorf("unable to get file info for %s: %w", localFullPath, err)
}

if i, ok := stat.(FileInfoWithVirtualExtension); ok {
vext := i.VirtualExtension()
return strings.TrimSuffix(remotePath, vext), nil
}
}

// Upon import, notebooks are stripped of their extension.
return strings.TrimSuffix(remotePath, filepath.Ext(localFullPath)), nil
}
Expand Down
7 changes: 7 additions & 0 deletions libs/filer/workspace_files_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ type wsfsFileInfo struct {

// The export format of a notebook. This is not exposed by the SDK.
ReposExportFormat workspace.ExportFormat `json:"repos_export_format,omitempty"`

// Explicitly added file extension of the notebook based on its language
VirtualFileExtension string `json:"virtual_file_extension,omitempty"`
}

func (info wsfsFileInfo) Name() string {
Expand Down Expand Up @@ -88,6 +91,10 @@ func (info wsfsFileInfo) WorkspaceObjectInfo() workspace.ObjectInfo {
return info.ObjectInfo
}

func (info wsfsFileInfo) VirtualExtension() string {
return info.VirtualFileExtension
}

// UnmarshalJSON is a custom unmarshaller for the wsfsFileInfo struct.
// It must be defined for this type because otherwise the implementation
// of the embedded ObjectInfo type will be used.
Expand Down
6 changes: 4 additions & 2 deletions libs/filer/workspace_files_extensions_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func (w *workspaceFilesExtensionsClient) getNotebookStatByNameWithExt(ctx contex
// Modify the stat object path to include the extension. This stat object will be used
// to return the fs.FileInfo object in the stat method.
stat.Path = stat.Path + ext
stat.VirtualFileExtension = ext
return &workspaceFileStatus{
wsfsFileInfo: stat,
nameForWorkspaceAPI: nameWithoutExt,
Expand Down Expand Up @@ -127,6 +128,7 @@ func (w *workspaceFilesExtensionsClient) getNotebookStatByNameWithoutExt(ctx con
// Modify the stat object path to include the extension. This stat object will be used
// to return the fs.DirEntry object in the ReadDir method.
stat.Path = stat.Path + ext
stat.VirtualFileExtension = ext
return &workspaceFileStatus{
wsfsFileInfo: stat,
nameForWorkspaceAPI: name,
Expand Down Expand Up @@ -214,7 +216,7 @@ func (w *workspaceFilesExtensionsClient) ReadDir(ctx context.Context, name strin
return nil, err
}
// Replace the entry with the new entry that includes the extension.
entries[i] = wsfsDirEntry{wsfsFileInfo{ObjectInfo: stat.ObjectInfo}}
entries[i] = wsfsDirEntry{wsfsFileInfo{ObjectInfo: stat.ObjectInfo, VirtualFileExtension: stat.VirtualFileExtension}}
}

// Error if we have seen this path before in the current directory.
Expand Down Expand Up @@ -313,7 +315,7 @@ func (w *workspaceFilesExtensionsClient) Stat(ctx context.Context, name string)
return nil, err
}

return wsfsFileInfo{ObjectInfo: stat.ObjectInfo}, nil
return wsfsFileInfo{ObjectInfo: stat.ObjectInfo, VirtualFileExtension: stat.VirtualFileExtension}, nil
}

return info, err
Expand Down
Loading