Skip to content

Commit 24059e6

Browse files
authored
Support all version identifiers as per PEP440 in environment deps (#2522)
## Changes Support all version identifiers as per PEP440 in environment deps ## Why Some customers define their libraries dependencies like below and this should be supported by DABs ``` dependencies: - my_package==1.2.3.dev1 ``` ## Tests Added unit test to cover all the cases <!-- If your PR needs to be included in the release notes for next release, add a separate entry in NEXT_CHANGELOG.md as part of your PR. -->
1 parent 7cb0b45 commit 24059e6

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

NEXT_CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* Include tarballs in releases ([#2515](https://github.com/databricks/cli/pull/2515))
99

1010
### Bundles
11+
* Support all version identifiers as per PEP440 in environment deps ([#2522](https://github.com/databricks/cli/pull/2522))
1112

1213
### API Changes
1314
* Added `databricks genie execute-message-attachment-query` command.

bundle/libraries/local_path.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package libraries
22

33
import (
4+
"fmt"
45
"net/url"
56
"path"
67
"regexp"
@@ -81,13 +82,17 @@ func containsPipFlag(input string) bool {
8182
return re.MatchString(input)
8283
}
8384

85+
// pep440Regex is a regular expression that matches PEP 440 version specifiers.
86+
// https://peps.python.org/pep-0440/#public-version-identifiers
87+
const pep440Regex = `(?P<epoch>\d+!)?(?P<release>\d+(\.\d+)*)(?P<pre>[-_.]?(a|b|rc)\d+)?(?P<post>[-_.]?post\d+)?(?P<dev>[-_.]?dev\d+)?(?P<local>\+[a-zA-Z0-9]+([-_.][a-zA-Z0-9]+)*)?`
88+
8489
// ^[a-zA-Z0-9\-_]+: Matches the package name, allowing alphanumeric characters, dashes (-), and underscores (_).
8590
// \[.*\])?: Optionally matches any extras specified in square brackets, e.g., [security].
86-
// ((==|!=|<=|>=|~=|>|<)\d+(\.\d+){0,2}(\.\*)?): Optionally matches version specifiers, supporting various operators (==, !=, etc.) followed by a version number (e.g., 2.25.1).
91+
// ((==|!=|<=|>=|~=|>|<)\s?pep440Regex): Optionally matches version specifiers, supporting various operators (==, !=, etc.) followed by a version number as per PEP440 spec.
8792
// ,?: Optionally matches a comma (,) at the end of the specifier which is used to separate multiple specifiers.
8893
// There can be multiple version specifiers separated by commas or no specifiers.
8994
// Spec for package name and version specifier: https://pip.pypa.io/en/stable/reference/requirement-specifiers/
90-
var packageRegex = regexp.MustCompile(`^[a-zA-Z0-9\-_]+\s?(\[.*\])?\s?((==|!=|<=|>=|~=|==|>|<)\s?\d+(\.\d+){0,2}(\.\*)?,?)*$`)
95+
var packageRegex = regexp.MustCompile(fmt.Sprintf(`^[a-zA-Z0-9\-_]+\s?(\[.*\])?\s?((==|!=|<=|>=|~=|==|>|<)\s?%s,?)*$`, pep440Regex))
9196

9297
func isPackage(name string) bool {
9398
if packageRegex.MatchString(name) {

bundle/libraries/local_path_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,27 @@ func TestIsLibraryLocal(t *testing.T) {
5656
{path: "s3://mybucket/path/to/package", expected: false},
5757
{path: "dbfs:/mnt/path/to/package", expected: false},
5858
{path: "beautifulsoup4", expected: false},
59+
60+
// Check the possible version specifiers as in PEP 440
61+
// https://peps.python.org/pep-0440/#public-version-identifiers
62+
{path: "beautifulsoup4==4", expected: false},
63+
{path: "beautifulsoup4==4.12", expected: false},
5964
{path: "beautifulsoup4==4.12.3", expected: false},
65+
{path: "beautifulsoup4==4.12.3.dev1", expected: false},
66+
{path: "beautifulsoup4==4.12.3.a1", expected: false},
67+
{path: "beautifulsoup4==4.12.3.rc2", expected: false},
68+
{path: "beautifulsoup4==4.12.3.rc2.dev1", expected: false},
69+
{path: "beautifulsoup4==4.12.3+abc.5", expected: false},
70+
{path: "beautifulsoup4==1!4.12.3", expected: false},
71+
6072
{path: "beautifulsoup4 >= 4.12.3", expected: false},
6173
{path: "beautifulsoup4 < 4.12.3", expected: false},
6274
{path: "beautifulsoup4 ~= 4.12.3", expected: false},
6375
{path: "beautifulsoup4[security, tests]", expected: false},
6476
{path: "beautifulsoup4[security, tests] ~= 4.12.3", expected: false},
6577
{path: "beautifulsoup4>=1.0.0,<2.0.0", expected: false},
6678
{path: "beautifulsoup4>=1.0.0,~=1.2.0,<2.0.0", expected: false},
79+
{path: "beautifulsoup4>=1.0.0+abc.5,~=1.2.0.rc2.dev1,<2.0.0.a1", expected: false},
6780
{path: "https://github.com/pypa/pip/archive/22.0.2.zip", expected: false},
6881
{path: "pip @ https://github.com/pypa/pip/archive/22.0.2.zip", expected: false},
6982
{path: "requests [security] @ https://github.com/psf/requests/archive/refs/heads/main.zip", expected: false},

0 commit comments

Comments
 (0)