-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathExternalDependencies.ql
More file actions
44 lines (40 loc) · 1.42 KB
/
ExternalDependencies.ql
File metadata and controls
44 lines (40 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/**
* @deprecated
* @name External dependencies
* @description Count the number of dependencies that a Python source file has on external packages.
* @kind treemap
* @treemap.warnOn highValues
* @metricType externalDependency
* @id py/external-dependencies
*/
import python
import semmle.python.dependencies.TechInventory
/*
* These two columns encode four logical columns:
*
* 1. Python source file where the dependency originates
* 2. Package Object, ideally referring to a PyPI or similar externally provided package
* 3. Version of that package Object, if known
* 4. Number of dependencies from the source file to the package
*
* Ideally this query would therefore return three columns,
* but this would require changing the dashboard database schema
* and dashboard extractor.
*
* The first column (the Python source file) is prepended with a '/'
* so that the file path matches the path used for the file in the
* dashboard database, which is implicitly relative to the source
* archive location.
*/
predicate src_package_count(File sourceFile, ExternalPackage package, int total) {
total =
strictcount(AstNode src |
dependency(src, package) and
src.getLocation().getFile() = sourceFile
)
}
from File sourceFile, int total, string entity, ExternalPackage package
where
src_package_count(sourceFile, package, total) and
entity = munge(sourceFile, package)
select entity, total order by total desc