mirror of https://github.com/databricks/cli.git
Added support for pip options in environment dependencies (#1842)
## Changes Added support for specifying pip options such as `--extra-index-url` and etc. in environments dependencies ``` environments: - environment_key: Default spec: client: "1" dependencies: - --extra-index-url https://foo@bar.com/packages/smth somepackage - json==1.0.0 ``` ## Tests Added regression test --------- Co-authored-by: Pieter Noordhuis <pieter.noordhuis@databricks.com>
This commit is contained in:
parent
eefda8c198
commit
ffdbec87cc
|
@ -699,6 +699,9 @@ func TestTranslatePathJobEnvironments(t *testing.T) {
|
|||
"../dist/env2.whl",
|
||||
"simplejson",
|
||||
"/Workspace/Users/foo@bar.com/test.whl",
|
||||
"--extra-index-url https://name:token@gitlab.com/api/v4/projects/9876/packages/pypi/simple foobar",
|
||||
"foobar --extra-index-url https://name:token@gitlab.com/api/v4/projects/9876/packages/pypi/simple",
|
||||
"https://foo@bar.com/packages/pypi/simple",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -719,6 +722,9 @@ func TestTranslatePathJobEnvironments(t *testing.T) {
|
|||
assert.Equal(t, strings.Join([]string{".", "dist", "env2.whl"}, string(os.PathSeparator)), b.Config.Resources.Jobs["job"].JobSettings.Environments[0].Spec.Dependencies[1])
|
||||
assert.Equal(t, "simplejson", b.Config.Resources.Jobs["job"].JobSettings.Environments[0].Spec.Dependencies[2])
|
||||
assert.Equal(t, "/Workspace/Users/foo@bar.com/test.whl", b.Config.Resources.Jobs["job"].JobSettings.Environments[0].Spec.Dependencies[3])
|
||||
assert.Equal(t, "--extra-index-url https://name:token@gitlab.com/api/v4/projects/9876/packages/pypi/simple foobar", b.Config.Resources.Jobs["job"].JobSettings.Environments[0].Spec.Dependencies[4])
|
||||
assert.Equal(t, "foobar --extra-index-url https://name:token@gitlab.com/api/v4/projects/9876/packages/pypi/simple", b.Config.Resources.Jobs["job"].JobSettings.Environments[0].Spec.Dependencies[5])
|
||||
assert.Equal(t, "https://foo@bar.com/packages/pypi/simple", b.Config.Resources.Jobs["job"].JobSettings.Environments[0].Spec.Dependencies[6])
|
||||
}
|
||||
|
||||
func TestTranslatePathWithComplexVariables(t *testing.T) {
|
||||
|
|
|
@ -57,6 +57,12 @@ func IsLibraryLocal(dep string) bool {
|
|||
}
|
||||
}
|
||||
|
||||
// If the dependency starts with --, it's a pip flag option which is a valid
|
||||
// entry for environment dependencies but not a local path
|
||||
if containsPipFlag(dep) {
|
||||
return false
|
||||
}
|
||||
|
||||
// If the dependency is a requirements file, it's not a valid local path
|
||||
if strings.HasPrefix(dep, "-r") {
|
||||
return false
|
||||
|
@ -70,6 +76,11 @@ func IsLibraryLocal(dep string) bool {
|
|||
return IsLocalPath(dep)
|
||||
}
|
||||
|
||||
func containsPipFlag(input string) bool {
|
||||
re := regexp.MustCompile(`--[a-zA-Z0-9-]+`)
|
||||
return re.MatchString(input)
|
||||
}
|
||||
|
||||
// ^[a-zA-Z0-9\-_]+: Matches the package name, allowing alphanumeric characters, dashes (-), and underscores (_).
|
||||
// \[.*\])?: Optionally matches any extras specified in square brackets, e.g., [security].
|
||||
// ((==|!=|<=|>=|~=|>|<)\d+(\.\d+){0,2}(\.\*)?): Optionally matches version specifiers, supporting various operators (==, !=, etc.) followed by a version number (e.g., 2.25.1).
|
||||
|
|
Loading…
Reference in New Issue