Skip to content

Commit

Permalink
fix: support python packages that have "added support" syntax (#52)
Browse files Browse the repository at this point in the history
* fix: support python packages that have "added support" syntax

* chore: disable `dupl` check on tests
  • Loading branch information
G-Rath committed Mar 10, 2022
1 parent b42b034 commit 91a2340
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ issues:
- path: _test\.go
linters:
- goerr113
- dupl
- path: main.go
linters:
- gochecknoglobals
2 changes: 2 additions & 0 deletions detector/parsers/fixtures/pip/with-added-support.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
twisted[http2]==20.3.0
# via scrapy
6 changes: 5 additions & 1 deletion detector/parsers/parse-requirements-txt.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,16 @@ func parseLine(line string) PackageDetails {
}

return PackageDetails{
Name: name,
Name: cleanupRequirementName(name),
Version: version,
Ecosystem: PipEcosystem,
}
}

func cleanupRequirementName(name string) string {
return strings.Split(name, "[")[0]
}

func removeComments(line string) string {
var re = regexp.MustCompile(`(^|\s+)#.*$`)

Expand Down
18 changes: 18 additions & 0 deletions detector/parsers/parse-requirements-txt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,3 +262,21 @@ func TestParseRequirementsTxt_FileFormatExample(t *testing.T) {
},
})
}

func TestParseRequirementsTxt_WithAddedSupport(t *testing.T) {
t.Parallel()

packages, err := parsers.ParseRequirementsTxt("fixtures/pip/with-added-support.txt")

if err != nil {
t.Errorf("Got unexpected error: %v", err)
}

expectPackages(t, packages, []parsers.PackageDetails{
{
Name: "twisted",
Version: "20.3.0",
Ecosystem: parsers.PipEcosystem,
},
})
}

0 comments on commit 91a2340

Please sign in to comment.