Skip to content

Commit

Permalink
added trim for values after colon
Browse files Browse the repository at this point in the history
  • Loading branch information
ankk13 committed Jul 8, 2021
1 parent 8a0bcb5 commit 8f18007
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
17 changes: 8 additions & 9 deletions pkg/python/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ import (
)

const commentRune string = "#"
const endColon string = ";"

func Parse(r io.Reader) ([]types.Library, error) {
scanner := bufio.NewScanner(r)
var libs []types.Library
for scanner.Scan() {
line := scanner.Text()
stripAllSpaces(&line)
stripComments(&line)
line = strings.ReplaceAll(line, " ", "")
line = rStripByKey(line, commentRune)
line = rStripByKey(line, endColon)
s := strings.Split(line, "==")
if len(s) != 2 {
continue
Expand All @@ -34,12 +36,9 @@ func Parse(r io.Reader) ([]types.Library, error) {
return libs, nil
}

func stripComments(line *string) {
if pos := strings.IndexAny(*line, commentRune); pos >= 0 {
*line = strings.TrimRightFunc((*line)[:pos], unicode.IsSpace)
func rStripByKey(line string, key string) string {
if pos := strings.IndexAny(line, key); pos >= 0 {
line = strings.TrimRightFunc((line)[:pos], unicode.IsSpace)
}
}

func stripAllSpaces(line *string) {
*line = strings.ReplaceAll(*line, " ", "")
return line
}
1 change: 1 addition & 0 deletions pkg/python/parse_testcase.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ var (

requirementsOperator = []types.Library{
{"Django", "2.3.4"},
{"SomeProject", "5.4"},
}
)
5 changes: 4 additions & 1 deletion pkg/python/testdata/requirements_operator.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
keyring >= 4.1.1 # Minimum version 4.1.1
coverage != 3.5 # Version Exclusion. Anything except version 3.5
Mopidy-Dirble ~= 1.1 # Compatible release. Same as >= 1.1, == 1.*
Django == 2.3.4
Django == 2.3.4
SomeProject ==5.4 ; python_version < '3.8'
numpyNew; sys_platform == 'win32'
numpy >= 3.4.1; sys_platform == 'win32'

0 comments on commit 8f18007

Please sign in to comment.