Skip to content

Commit

Permalink
Avoid guessing common words/module names (#275)
Browse files Browse the repository at this point in the history
  • Loading branch information
blast-hardcheese committed Jul 26, 2024
1 parent 91c21f5 commit 5af79fa
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
56 changes: 56 additions & 0 deletions internal/backends/python/common_words.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
account
app
build
cache
command
commands
common
config
core
custom
daemon
demo
deploy
dev
edit
editor
example
examples
install
job
library
local
log
mail
mailer
main
menus
mode
model
models
public
run
sample
samples
schema
server
service
services
session
settings
setup
tasks
test
testapp
tester
testing
testproject
tests
tools
tree
unit
user
util
utilities
utils
web
15 changes: 14 additions & 1 deletion internal/backends/python/grab.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package python

import (
"context"
_ "embed"
"os"
"strings"

Expand All @@ -11,6 +12,11 @@ import (
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
)

var (
//go:embed common_words.txt
common_words_bytes []byte
)

var importsQuery = `
(module
[(import_statement
Expand Down Expand Up @@ -309,13 +315,20 @@ func filterImports(ctx context.Context, foundPkgs map[string]bool, testPypiMap f
//nolint:ineffassign,wastedassign,staticcheck
span, ctx := tracer.StartSpanFromContext(ctx, "python.grab.filterImports")
defer span.Finish()
// filter out stdlib/python internal modules
common_words := make(map[string]bool)
for _, word := range strings.Split(string(common_words_bytes), "\n") {
common_words[word] = true
}
// filter out stdlib/python internal modules, common words
for pkg := range foundPkgs {
// First path component
mod := strings.Split(pkg, ".")[0]
if internalModules[mod] {
delete(foundPkgs, pkg)
}
if common_words[mod] {
delete(foundPkgs, pkg)
}
}

pkgs := map[string][]api.PkgName{}
Expand Down

0 comments on commit 5af79fa

Please sign in to comment.