-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make
pydabs/venv_path
optional (#1687)
## Changes Make `pydabs/venv_path` optional. When not specified, CLI detects the Python interpreter using `python.DetectExecutable`, the same way as for `artifacts`. `python.DetectExecutable` works correctly if a virtual environment is activated or `python3` is available on PATH through other means. Extract the venv detection code from PyDABs into `libs/python/detect`. This code will be used when we implement the `python/venv_path` section in `databricks.yml`. ## Tests Unit tests and manually --------- Co-authored-by: Pieter Noordhuis <[email protected]>
- Loading branch information
Showing
6 changed files
with
128 additions
and
24 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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,46 @@ | ||
package python | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"runtime" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestDetectVEnvExecutable(t *testing.T) { | ||
dir := t.TempDir() | ||
interpreterPath := interpreterPath(dir) | ||
|
||
err := os.Mkdir(filepath.Dir(interpreterPath), 0755) | ||
require.NoError(t, err) | ||
|
||
err = os.WriteFile(interpreterPath, []byte(""), 0755) | ||
require.NoError(t, err) | ||
|
||
err = os.WriteFile(filepath.Join(dir, "pyvenv.cfg"), []byte(""), 0755) | ||
require.NoError(t, err) | ||
|
||
executable, err := DetectVEnvExecutable(dir) | ||
|
||
assert.NoError(t, err) | ||
assert.Equal(t, interpreterPath, executable) | ||
} | ||
|
||
func TestDetectVEnvExecutable_badLayout(t *testing.T) { | ||
dir := t.TempDir() | ||
|
||
_, err := DetectVEnvExecutable(dir) | ||
|
||
assert.Errorf(t, err, "can't find %q, check if virtualenv is created", interpreterPath(dir)) | ||
} | ||
|
||
func interpreterPath(venvPath string) string { | ||
if runtime.GOOS == "windows" { | ||
return filepath.Join(venvPath, "Scripts", "python3.exe") | ||
} else { | ||
return filepath.Join(venvPath, "bin", "python3") | ||
} | ||
} |