Skip to content
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
9 changes: 8 additions & 1 deletion src/main/kotlin/app/extractors/PythonExtractor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class PythonExtractor : ExtractorInterface {
val evaluator by lazy {
ExtractorInterface.getLibraryClassifier(LANGUAGE_NAME)
}
val MULTI_IMPORT_TO_LIB =
ExtractorInterface.getMultipleImportsToLibraryMap(LANGUAGE_NAME)
}

override fun extract(files: List<DiffFile>): List<CommitStats> {
Expand All @@ -35,7 +37,12 @@ class PythonExtractor : ExtractorInterface {
}
}

return imports.toList()
var libraries = imports.map { MULTI_IMPORT_TO_LIB.getOrDefault(it, it) }
.filter { !it.endsWith("pb")}.toMutableList()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is that hardcoded? It's dirty

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean?

if (libraries.size < imports.size) {
libraries.add("protobuf")
}
return libraries

}

Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/data/imports/python.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cv2:opencv
cv:opencv
10 changes: 10 additions & 0 deletions src/test/kotlin/test/tests/extractors/ExtractorTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,14 @@ class ExtractorTest : Spek({
assertExtractsImport(lib, line2, CppExtractor())
}
}

given("import cv2 or cv") {
it("imports opencv") {
val lib = "opencv"
val line1 = "import cv2"
assertExtractsImport(lib, line1, PythonExtractor())
val line2 = "import cv"
assertExtractsImport(lib, line2, PythonExtractor())
}
}
})