This repository has been archived by the owner on Nov 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* python: add initial code to scan requirements.txt file Signed-off-by: mcoops <[email protected]>
- Loading branch information
Showing
4 changed files
with
111 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package scan | ||
|
||
import ( | ||
"bufio" | ||
"os" | ||
"regexp" | ||
"strings" | ||
) | ||
|
||
// Account for >, <, >=, <=, ==, !=, ~= and * | ||
var /* const */ re = regexp.MustCompile(`[<>!~*]+`) | ||
|
||
func max(x, y int) int { | ||
if x > y { | ||
return x | ||
} | ||
return y | ||
} | ||
|
||
func GetPythonDeps(path string) (map[string]string, error) { | ||
gathered := make(map[string]string) | ||
|
||
file, err := os.Open(path) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
defer file.Close() | ||
|
||
scanner := bufio.NewScanner(file) | ||
|
||
for scanner.Scan() { | ||
line := scanner.Text() | ||
|
||
// skip comments | ||
if strings.HasPrefix(line, "#") || line == "" { | ||
continue | ||
} | ||
|
||
// easy case, elasticsearch-curator==5.8.1 | ||
// record name and version, only for == | ||
idx := strings.LastIndex(line, "==") | ||
if idx > 0 { | ||
gathered[line[:idx]] = line[idx+2:] | ||
continue | ||
} | ||
|
||
// every other permitation just use the name as we can't guarantee | ||
// the version, just grab the name using first occurance | ||
match := re.FindStringIndex(line) | ||
|
||
if match != nil { | ||
gathered[line[:match[0]]] = "" | ||
} | ||
} | ||
|
||
return gathered, nil | ||
} |
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,8 @@ | ||
# The order of packages is significant, because pip processes them in the order | ||
# of appearance. Changing the order has an impact on the overall integration | ||
# process, which may cause wedges in the gate later. | ||
|
||
cotyledon>=1.5.0 # Apache-2.0 | ||
Flask!=0.11,>=0.12.3 # BSD | ||
kuryr-lib>=0.5.0 # Apache-2.0 | ||
cryptography==2.3.0 |