Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resources:
pipelines:
abc:
root_path: "foo/bar/doesnotexist"
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

>>> [CLI] bundle validate
Error: stat foo/bar/doesnotexist: no such file or directory

Name: test-bundle
Target: default
Workspace:
User: [USERNAME]
Path: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default

Found 1 error

Exit code: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
errcode trace $CLI bundle validate
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Replace error message from windows
[[Repls]]
Old = "CreateFile foo/bar/doesnotexist: The system cannot find the path specified."
New = "stat foo/bar/doesnotexist: no such file or directory"
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
bundle:
name: pipelines_relative_path_translation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One was removed, but this one was kept. Please keep consistency in mind.


include:
- resources/*.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

>>> [CLI] bundle validate -o json
{
"one_libraries": [
{
"glob": {
"include": "/Workspace/Users/[USERNAME]/.bundle/pipelines_relative_path_translation/default/files/src/pipeline_one/a/b/c/**"
}
}
],
"two_libraries": [
{
"glob": {
"include": "/Workspace/Users/me@company.com/a/b/c/**"
}
}
],
"one_root_path": "/Workspace/Users/[USERNAME]/.bundle/pipelines_relative_path_translation/default/files/src/pipeline_one",
"two_root_path": "/Workspace/Users/me@company.com/src"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
resources:
pipelines:
# relative paths should get translated to remote paths
one:
root_path: "../src/pipeline_one"
libraries:
- glob:
include: "../src/pipeline_one/a/b/c/**"

# absolute paths should remain as-is
two:
root_path: "/Workspace/Users/me@company.com/src"
libraries:
- glob:
include: "/Workspace/Users/me@company.com/a/b/c/**"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
trace $CLI bundle validate -o json | jq '{one_libraries: .resources.pipelines.one.libraries, two_libraries: .resources.pipelines.two.libraries, one_root_path: .resources.pipelines.one.root_path, two_root_path: .resources.pipelines.two.root_path}'
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
bundle:
name: pipelines_root_path_outside_sync_root

resources:
pipelines:
abc:
root_path: ../../../src
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

>>> [CLI] bundle validate
Error: path [TEST_TMP_DIR]/src is not contained in sync root path

Name: pipelines_root_path_outside_sync_root
Target: default
Workspace:
User: [USERNAME]
Path: /Workspace/Users/[USERNAME]/.bundle/pipelines_root_path_outside_sync_root/default

Found 1 error

Exit code: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cd a/b/c

trace $CLI bundle validate
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[[Repls]]
Old = '\\'
New = '/'
2 changes: 1 addition & 1 deletion acceptance/selftest/basic/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Exit code: 7
=== Custom output files - everything starting with out is captured and compared
>>> echo HELLO

=== Custom regex can be specified in [[Repl]] section
=== Custom regex can be specified in [[Repls]] section
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small typo fix.

1234
CUSTOM_NUMBER_REGEX
123456
Expand Down
2 changes: 1 addition & 1 deletion acceptance/selftest/basic/script
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ trace withdir subdir/a/b/c python3 -c 'import os; print(os.getcwd())'
printf "\n=== Custom output files - everything starting with out is captured and compared"
trace echo HELLO > out.hello.txt

printf "\n=== Custom regex can be specified in [[Repl]] section\n"
printf "\n=== Custom regex can be specified in [[Repls]] section\n"
echo 1234
echo 12345
echo 123456
Expand Down
14 changes: 10 additions & 4 deletions bundle/config/mutator/paths/pipeline_paths_visitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,26 @@ func pipelineRewritePatterns() []pipelineRewritePattern {
dyn.Key("resources"),
dyn.Key("pipelines"),
dyn.AnyKey(),
dyn.Key("libraries"),
dyn.AnyIndex(),
)

// Compile list of configuration paths to rewrite.
return []pipelineRewritePattern{
{
pattern: base.Append(dyn.Key("notebook"), dyn.Key("path")),
pattern: base.Append(dyn.Key("libraries"), dyn.AnyIndex(), dyn.Key("notebook"), dyn.Key("path")),
mode: TranslateModeNotebook,
},
{
pattern: base.Append(dyn.Key("file"), dyn.Key("path")),
pattern: base.Append(dyn.Key("libraries"), dyn.AnyIndex(), dyn.Key("file"), dyn.Key("path")),
mode: TranslateModeFile,
},
{
pattern: base.Append(dyn.Key("libraries"), dyn.AnyIndex(), dyn.Key("glob"), dyn.Key("include")),
mode: TranslateModeGlob,
},
{
pattern: base.Append(dyn.Key("root_path")),
mode: TranslateModeDirectory,
},
}
}

Expand Down
8 changes: 8 additions & 0 deletions bundle/config/mutator/paths/pipeline_paths_visitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func TestVisitPipelinePaths(t *testing.T) {
Pipelines: map[string]*resources.Pipeline{
"pipeline0": {
CreatePipeline: pipelines.CreatePipeline{
RootPath: "src",
Libraries: []pipelines.PipelineLibrary{
{
File: &pipelines.FileLibrary{
Expand All @@ -27,6 +28,11 @@ func TestVisitPipelinePaths(t *testing.T) {
Path: "src/foo.py",
},
},
{
Glob: &pipelines.PathPattern{
Include: "a/b/c/**",
},
},
},
},
},
Expand All @@ -38,6 +44,8 @@ func TestVisitPipelinePaths(t *testing.T) {
expected := []dyn.Path{
dyn.MustPathFromString("resources.pipelines.pipeline0.libraries[0].file.path"),
dyn.MustPathFromString("resources.pipelines.pipeline0.libraries[1].notebook.path"),
dyn.MustPathFromString("resources.pipelines.pipeline0.libraries[2].glob.include"),
dyn.MustPathFromString("resources.pipelines.pipeline0.root_path"),
}

assert.ElementsMatch(t, expected, actual)
Expand Down
4 changes: 4 additions & 0 deletions bundle/config/mutator/paths/translation_mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ const (
// TranslateModeDirectory translates a path to a remote directory.
TranslateModeDirectory

// TranslateModeGlob translates a relative glob pattern to a remote glob pattern.
// It does not perform any checks on the glob pattern itself.
TranslateModeGlob

// TranslateModeLocalAbsoluteDirectory translates a path to the local absolute directory path.
// It returns an error if the path does not exist or is not a directory.
TranslateModeLocalAbsoluteDirectory
Expand Down
6 changes: 6 additions & 0 deletions bundle/config/mutator/translate_paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ func (t *translateContext) rewritePath(
interp, err = t.translateFilePath(ctx, input, localPath, localRelPath)
case paths.TranslateModeDirectory:
interp, err = t.translateDirectoryPath(ctx, input, localPath, localRelPath)
case paths.TranslateModeGlob:
interp, err = t.translateGlobPath(ctx, input, localPath, localRelPath)
case paths.TranslateModeLocalAbsoluteDirectory:
interp, err = t.translateLocalAbsoluteDirectoryPath(ctx, input, localPath, localRelPath)
case paths.TranslateModeLocalRelative:
Expand Down Expand Up @@ -230,6 +232,10 @@ func (t *translateContext) translateDirectoryPath(ctx context.Context, literal,
return path.Join(t.remoteRoot, localRelPath), nil
}

func (t *translateContext) translateGlobPath(ctx context.Context, literal, localFullPath, localRelPath string) (string, error) {
return path.Join(t.remoteRoot, localRelPath), nil
}

func (t *translateContext) translateLocalAbsoluteDirectoryPath(ctx context.Context, literal, localFullPath, _ string) (string, error) {
info, err := os.Stat(filepath.FromSlash(localFullPath))
if errors.Is(err, fs.ErrNotExist) {
Expand Down
Loading