Skip to content
This repository has been archived by the owner on Nov 23, 2021. It is now read-only.

Commit

Permalink
python: improve name and version parsing (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcoops authored Oct 3, 2021
1 parent 84b19bb commit 11a51fb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
6 changes: 6 additions & 0 deletions deplist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ func BuildWant() []Dependency {
"cotyledon",
"Flask",
"kuryr-lib",
"docutils",
"python-dateutil",
"unittest2",
"cryptography",
}

Expand Down Expand Up @@ -274,6 +277,9 @@ func BuildWant() []Dependency {
deps = append(deps, d)
}

end = len(deps) - 2 // get the cryptography ver
deps[end].Version = "0.5.1"

end = len(deps) - 1 // get the cryptography ver
deps[end].Version = "2.3.0"

Expand Down
14 changes: 12 additions & 2 deletions internal/scan/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,24 @@ func GetPythonDeps(path string) (map[string]string, error) {
line := scanner.Text()

// skip comments
if strings.HasPrefix(line, "#") || line == "" {
// and editable? https://github.com/pypa/pip/issues/4812
if strings.HasPrefix(line, "#") || strings.HasPrefix(line, "-e") || line == "" {
continue
}

// easy case, elasticsearch-curator==5.8.1
// record name and version, only for ==
idx := strings.LastIndex(line, "==")
idx := strings.Index(line, "==")
if idx > 0 {
// test if there's a ';', i.e. unittest2==0.5.1; python_version == '2.6'
colIdx := strings.Index(line, ";")
if colIdx > 0 {
if idx+2 >= colIdx {
continue
}
// truncate line
line = line[:colIdx]
}
gathered[line[:idx]] = line[idx+2:]
continue
}
Expand Down
3 changes: 3 additions & 0 deletions test/testRepo/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@
cotyledon>=1.5.0 # Apache-2.0
Flask!=0.11,>=0.12.3 # BSD
kuryr-lib>=0.5.0 # Apache-2.0
unittest2==0.5.1; python_version == '2.6'
python-dateutil>=2.1,<3.0.0; python_version>="2.7"
docutils>=0.10
cryptography==2.3.0

0 comments on commit 11a51fb

Please sign in to comment.