-
Notifications
You must be signed in to change notification settings - Fork 107
New hidden install-pipelines-cli
command that creates pipelines
symlink to databricks
#3009
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
Merged
+172
−1
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
60260b7
New hidden install-dlt command that creates symlink in same PATH as d…
alyssa-db 6750e38
addressed code comments prior to testing
alyssa-db 359a77d
added acceptance tests
alyssa-db d12a848
modified acceptance test PATH to add databricks and helper tools
alyssa-db e3c41fc
Merge branch 'databricks:main' into install-dlt-feat
alyssa-db ca3d09b
made dlt path be based on executable
alyssa-db d168e96
added acceptance test python script, refactored install-dlt
alyssa-db c282769
draft acceptance test and acceptance test DLT setup
alyssa-db e771366
acceptance test logic
alyssa-db 9fac6c7
Merge remote-tracking branch 'upstream/main' into install-dlt-feat
alyssa-db 14b7d31
windows path
alyssa-db be032fa
trying environment variable changes'
alyssa-db 6429b3a
test symlink
alyssa-db 2bf67ef
Merge branch 'main' into install-dlt-feat
alyssa-db 9bf008f
dlt init checker
alyssa-db 8576254
erroring checks
alyssa-db 523c76d
added line for python packages
alyssa-db ce1c01a
Merge branch 'main' into install-dlt-feat
alyssa-db cc6454b
Added json path output and refactoring
alyssa-db 8e020dc
checking windows
alyssa-db 12b1e64
not clean paths windows
alyssa-db 2d8da98
error order
alyssa-db 1da3ff0
removed json, added relative path to tests
alyssa-db be778d6
modified invoke statement
alyssa-db f9dc119
Merge branch 'main' into install-dlt-feat
alyssa-db fb62458
renamed dlt to pipelines
alyssa-db 9156ad5
renamed to install-pipelines-cli
alyssa-db File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package dlt | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// InstallDLTSymlink creates a symlink named 'dlt' pointing to the real databricks binary. | ||
func InstallDLTSymlink() error { | ||
path, err := exec.LookPath("databricks") | ||
alyssa-db marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if err != nil { | ||
return errors.New("databricks CLI not found in PATH") | ||
} | ||
realPath, err := filepath.EvalSymlinks(path) | ||
if err != nil { | ||
return fmt.Errorf("failed to resolve symlink: %w", err) | ||
} | ||
|
||
dir := filepath.Dir(path) | ||
|
||
// Check write permission by trying to create and remove a temp file | ||
testFile := filepath.Join(dir, ".permtest") | ||
alyssa-db marked this conversation as resolved.
Show resolved
Hide resolved
|
||
f, err := os.Create(testFile) | ||
if err != nil { | ||
return fmt.Errorf("no write permission in %s: %w", dir, err) | ||
} | ||
f.Close() | ||
_ = os.Remove(testFile) | ||
|
||
dltPath := filepath.Join(dir, "dlt") | ||
|
||
// Check if 'dlt' already exists | ||
if fi, err := os.Lstat(dltPath); err == nil { | ||
alyssa-db marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if fi.Mode()&os.ModeSymlink != 0 { | ||
target, err := os.Readlink(dltPath) | ||
if err == nil && target == realPath { | ||
return errors.New("dlt already installed") | ||
alyssa-db marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
return fmt.Errorf("cannot create symlink: %q already exists", dltPath) | ||
} else if !os.IsNotExist(err) { | ||
// Some other error occurred while checking | ||
return fmt.Errorf("failed to check if %q exists: %w", dltPath, err) | ||
} | ||
|
||
if err := os.Symlink(realPath, dltPath); err != nil { | ||
return fmt.Errorf("failed to create symlink: %w", err) | ||
alyssa-db marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
return nil | ||
} | ||
|
||
func New() *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "install-dlt", | ||
Short: "Install DLT", | ||
Hidden: true, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
err := InstallDLTSymlink() | ||
if err != nil { | ||
if err.Error() == "dlt already installed" { | ||
alyssa-db marked this conversation as resolved.
Show resolved
Hide resolved
|
||
fmt.Println(err.Error()) | ||
alyssa-db marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return nil | ||
} | ||
return err | ||
} | ||
return nil | ||
}, | ||
} | ||
} | ||
|
||
func NewRoot() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "dlt", | ||
Short: "DLT CLI", | ||
Long: "DLT CLI (stub, to be filled in)", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
_ = cmd.Help() | ||
alyssa-db marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
} | ||
|
||
// Add 'init' stub command (same description as bundle init) | ||
initCmd := &cobra.Command{ | ||
alyssa-db marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Use: "init", | ||
Short: "Initialize a new DLT project in the current directory", | ||
Long: "Initialize a new DLT project in the current directory. This is a stub for future implementation.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fmt.Println("dlt init is not yet implemented. This will initialize a new DLT project in the future.") | ||
}, | ||
} | ||
cmd.AddCommand(initCmd) | ||
|
||
return cmd | ||
} | ||
alyssa-db marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package dlt | ||
alyssa-db marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
import ( | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
"runtime" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
// Add your imports here | ||
|
||
// Add your tests here | ||
|
||
type dltTestEnv struct { | ||
tempDir string | ||
binName string | ||
symlinkName string | ||
databricksPath string | ||
} | ||
|
||
func setupDLTTestEnv(t *testing.T) *dltTestEnv { | ||
tempDir := t.TempDir() | ||
binName := "databricks" | ||
symlinkName := "dlt" | ||
if runtime.GOOS == "windows" { | ||
binName += ".bat" | ||
symlinkName += ".bat" | ||
} | ||
databricksPath := filepath.Join(tempDir, binName) | ||
f, err := os.Create(databricksPath) | ||
assert.NoError(t, err) | ||
f.Close() | ||
err = os.Chmod(databricksPath, 0o755) | ||
assert.NoError(t, err) | ||
|
||
oldPath := os.Getenv("PATH") | ||
os.Setenv("PATH", tempDir+string(os.PathListSeparator)+oldPath) | ||
t.Cleanup(func() { os.Setenv("PATH", oldPath) }) | ||
|
||
return &dltTestEnv{ | ||
tempDir: tempDir, | ||
binName: binName, | ||
symlinkName: symlinkName, | ||
databricksPath: databricksPath, | ||
} | ||
} | ||
|
||
func TestInstallDLTSymlink(t *testing.T) { | ||
env := setupDLTTestEnv(t) | ||
|
||
err := InstallDLTSymlink() | ||
assert.NoError(t, err) | ||
dltSymlink := filepath.Join(env.tempDir, env.symlinkName) | ||
_, err = os.Lstat(dltSymlink) | ||
assert.NoError(t, err, "symlink was not created") | ||
} | ||
|
||
func TestDLTSymlinkRunsInit(t *testing.T) { | ||
env := setupDLTTestEnv(t) | ||
|
||
var err error | ||
var script string | ||
if os.PathSeparator == '\\' { | ||
script = "@echo off\necho databricks called with: %*\n" | ||
} else { | ||
script = "#!/bin/sh\necho databricks called with: $@\n" | ||
} | ||
|
||
// Overwrite the dummy 'databricks' binary as a shell/batch script that prints args | ||
err = os.WriteFile(env.databricksPath, []byte(script), 0o755) | ||
assert.NoError(t, err) | ||
|
||
// Create the symlink | ||
err = InstallDLTSymlink() | ||
assert.NoError(t, err) | ||
|
||
// Run the symlinked binary with 'init' and check it executes without error | ||
dltSymlink := filepath.Join(env.tempDir, env.symlinkName) | ||
cmd := exec.Command(dltSymlink, "init") | ||
cmd.Dir = env.tempDir | ||
output, err := cmd.CombinedOutput() | ||
assert.NoErrorf(t, err, "failed to run dlt init: output: %s", string(output)) | ||
|
||
// Check the output is as expected | ||
assert.Contains(t, string(output), "databricks", "unexpected output: got %q, want substring containing %q", string(output), "databricks") | ||
assert.Contains(t, string(output), "init", "unexpected output: got %q, want substring containing %q", string(output), "databricks") | ||
} | ||
|
||
func TestInstallDLTSymlink_AlreadyExists(t *testing.T) { | ||
env := setupDLTTestEnv(t) | ||
dltPath := filepath.Join(env.tempDir, env.symlinkName) | ||
err := os.WriteFile(dltPath, []byte("not a symlink"), 0o644) | ||
assert.NoError(t, err) | ||
err = InstallDLTSymlink() | ||
assert.Error(t, err) | ||
assert.Contains(t, err.Error(), "already exists", "expected error about symlink already existing, got: %v", err) | ||
} | ||
|
||
func TestInstallDLTSymlink_AlreadyInstalled(t *testing.T) { | ||
env := setupDLTTestEnv(t) | ||
realPath, err := filepath.EvalSymlinks(env.databricksPath) | ||
assert.NoError(t, err) | ||
dltPath := filepath.Join(env.tempDir, env.symlinkName) | ||
err = os.Symlink(realPath, dltPath) | ||
assert.NoError(t, err) | ||
|
||
err = InstallDLTSymlink() | ||
assert.Error(t, err) | ||
assert.EqualError(t, err, "dlt already installed") | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.