Skip to content

Commit cb93677

Browse files
Added a warning for non exportable types
1 parent 7a84cf1 commit cb93677

File tree

6 files changed

+75
-6
lines changed

6 files changed

+75
-6
lines changed
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11

22
>>> [CLI] workspace export-dir /test-dir [TEST_TMP_DIR]/export
33
Exporting files from /test-dir
4-
Warning: /test-dir/file.py (skipped; file too large)
54

6-
The following files were skipped because they exceed the maximum size limit:
5+
Warnings:
76
- /test-dir/file.py (skipped; file too large)
87

98
Export complete

acceptance/cmd/workspace/export-dir-skip-experiments/out.test.toml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
>>> [CLI] workspace export-dir /test-dir [TEST_TMP_DIR]/export
3+
Exporting files from /test-dir
4+
5+
Warnings:
6+
- /test-dir/experiment (skipped; cannot export MLFLOW_EXPERIMENT)
7+
8+
Export complete
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
mkdir -p "$TEST_TMP_DIR/export"
2+
trace $CLI workspace export-dir /test-dir "$TEST_TMP_DIR/export"
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Local = true
2+
Cloud = false
3+
4+
[Env]
5+
MSYS_NO_PATHCONV = "1"
6+
7+
[[Server]]
8+
Pattern = "GET /api/2.0/workspace/list"
9+
Response.Body = '''
10+
{
11+
"objects": [
12+
{
13+
"path": "/test-dir/experiment",
14+
"object_type": "MLFLOW_EXPERIMENT",
15+
"object_id": 125
16+
}
17+
]
18+
}
19+
'''
20+
21+
[[Server]]
22+
Pattern = "GET /api/2.0/workspace/get-status"
23+
Response.Body = '''
24+
{
25+
"path": "/test-dir",
26+
"object_type": "DIRECTORY",
27+
"object_id": 123
28+
}
29+
'''

cmd/workspace/workspace/export_dir.go

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package workspace
33
import (
44
"context"
55
"errors"
6+
"fmt"
67
"io"
78
"io/fs"
89
"net/http"
@@ -51,6 +52,26 @@ func isFileSizeError(err error) bool {
5152
return false
5253
}
5354

55+
// Object types that cannot be exported via the workspace export API.
56+
// These will be skipped with a warning during export-dir.
57+
var nonExportableTypes = []workspace.ObjectType{
58+
workspace.ObjectTypeLibrary,
59+
workspace.ObjectTypeDashboard,
60+
workspace.ObjectTypeRepo,
61+
// MLFLOW_EXPERIMENT is not defined as a constant in the SDK
62+
workspace.ObjectType("MLFLOW_EXPERIMENT"),
63+
}
64+
65+
// isNonExportable checks if an object type cannot be exported.
66+
func isNonExportable(objectType workspace.ObjectType) bool {
67+
for _, t := range nonExportableTypes {
68+
if objectType == t {
69+
return true
70+
}
71+
}
72+
return false
73+
}
74+
5475
// The callback function exports the file specified at relPath. This function is
5576
// meant to be used in conjunction with fs.WalkDir
5677
func (opts *exportDirOptions) callback(ctx context.Context, workspaceFiler filer.Filer) func(string, fs.DirEntry, error) error {
@@ -77,6 +98,13 @@ func (opts *exportDirOptions) callback(ctx context.Context, workspaceFiler filer
7798
return err
7899
}
79100
objectInfo := info.Sys().(workspace.ObjectInfo)
101+
102+
// Skip non-exportable objects (e.g., MLFLOW_EXPERIMENT, LIBRARY)
103+
if isNonExportable(objectInfo.ObjectType) {
104+
opts.warnings = append(opts.warnings, fmt.Sprintf("%s (skipped; cannot export %s)", sourcePath, objectInfo.ObjectType))
105+
return nil
106+
}
107+
80108
targetPath += notebook.GetExtensionByLanguage(&objectInfo)
81109

82110
// Skip file if a file already exists in path.
@@ -92,9 +120,7 @@ func (opts *exportDirOptions) callback(ctx context.Context, workspaceFiler filer
92120
if err != nil {
93121
// Check if this is a file size limit error
94122
if isFileSizeError(err) {
95-
warning := sourcePath + " (skipped; file too large)"
96-
cmdio.LogString(ctx, "Warning: "+warning)
97-
opts.warnings = append(opts.warnings, warning)
123+
opts.warnings = append(opts.warnings, sourcePath+" (skipped; file too large)")
98124
return nil
99125
}
100126
return err
@@ -162,7 +188,7 @@ func newExportDir() *cobra.Command {
162188
// Print all warnings at the end if any were collected
163189
if len(opts.warnings) > 0 {
164190
cmdio.LogString(ctx, "")
165-
cmdio.LogString(ctx, "The following files were skipped because they exceed the maximum size limit:")
191+
cmdio.LogString(ctx, "Warnings:")
166192
for _, warning := range opts.warnings {
167193
cmdio.LogString(ctx, " - "+warning)
168194
}

0 commit comments

Comments
 (0)