Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DX-780: Avoid guessing common words/module names #275

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading