Skip to content

Commit

Permalink
fix: check std modules last
Browse files Browse the repository at this point in the history
Performing the check last is more correct and yields better performance,
noticeable on large repositories.

Signed-off-by: Thulio Ferraz Assis <[email protected]>
  • Loading branch information
f0rmiga committed Nov 16, 2021
1 parent 4b403c8 commit a58208c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
9 changes: 1 addition & 8 deletions gazelle/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,6 @@ func (p *python3Parser) parse(pyFilepath string) (*treeset.Set, error) {
continue
}

// Check if the imported module is part of the standard library.
if isStd, err := isStdModule(m); err != nil {
return nil, err
} else if isStd {
continue
}

m.Filepath = relFilepath

modules.Add(m)
Expand Down Expand Up @@ -269,4 +262,4 @@ func annotationsFromComments(comments []comment) *annotations {
func (a *annotations) ignores(module string) bool {
_, ignores := a.ignore[module]
return ignores
}
}
12 changes: 11 additions & 1 deletion gazelle/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,14 @@ func (py *Resolver) Resolve(
} else {
matches := ix.FindRulesByImportWithConfig(c, imp, languageName)
if len(matches) == 0 {
// Check if the imported module is part of the standard library.
if isStd, err := isStdModule(mod); err != nil {
log.Println("ERROR: ", err)
hasFatalError = true
continue MODULE_LOOP
} else if isStd {
continue MODULE_LOOP
}
if cfg.ValidateImportStatements() {
err := fmt.Errorf(
"%[1]q at line %[2]d from %[3]q is an invalid dependency: possible solutions:\n"+
Expand All @@ -187,6 +195,7 @@ func (py *Resolver) Resolve(
)
log.Printf("ERROR: failed to validate dependencies for target %q: %v\n", from.String(), err)
hasFatalError = true
continue MODULE_LOOP
}
}
filteredMatches := make([]resolve.FindResult, 0, len(matches))
Expand Down Expand Up @@ -214,6 +223,7 @@ func (py *Resolver) Resolve(
targetListFromResults(filteredMatches), mod.Name, mod.LineNumber, mod.Filepath)
log.Println("ERROR: ", err)
hasFatalError = true
continue MODULE_LOOP
}
filteredMatches = sameRootMatches
}
Expand Down Expand Up @@ -276,4 +286,4 @@ func convertDependencySetToExpr(set *treeset.Set) bzl.Expr {
deps[it.Index()] = &bzl.StringExpr{Value: dep}
}
return &bzl.ListExpr{List: deps}
}
}

0 comments on commit a58208c

Please sign in to comment.