Skip to content

Commit bd486aa

Browse files
committed
Add comments, fix style
Signed-off-by: Jono Yang <[email protected]>
1 parent cd8a6c5 commit bd486aa

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

scanpipe/pipelines/deploy_to_develop.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,10 @@ def map_rust(self):
233233

234234
@optional_step("Python")
235235
def map_python(self):
236-
"""Map binaries from Python packages to their sources using dwarf paths and symbols."""
236+
"""
237+
Map binaries from Python packages to their sources using dwarf paths and
238+
symbols.
239+
"""
237240
d2d.map_python_pyx_to_binaries(project=self.project, logger=self.log)
238241

239242
def match_directories_to_purldb(self):

scanpipe/pipes/d2d.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@
4747
from go_inspector.plugin import collect_and_parse_symbols
4848
from packagedcode.npm import NpmPackageJsonHandler
4949
from rust_inspector.binary import collect_and_parse_rust_symbols
50-
from summarycode.classify import LEGAL_STARTS_ENDS
5150
from source_inspector.symbols_tree_sitter import get_tree
51+
from summarycode.classify import LEGAL_STARTS_ENDS
5252

5353
from aboutcode.pipeline import LoopProgress
5454
from scanpipe import pipes
@@ -1946,7 +1946,9 @@ def map_elfs_binaries_with_symbols(project, logger=None):
19461946
)
19471947

19481948
# Collect source symbols from elf related source files
1949-
elf_from_resources = from_resources.filter(extension__in=[".c", ".cpp", ".h", ".pyx", ".pxd"])
1949+
elf_from_resources = from_resources.filter(
1950+
extension__in=[".c", ".cpp", ".h", ".pyx", ".pxd"]
1951+
)
19501952

19511953
map_binaries_with_symbols(
19521954
project=project,
@@ -2151,7 +2153,11 @@ def _map_javascript_symbols(to_resource, javascript_from_resources, logger):
21512153

21522154
def map_python_pyx_to_binaries(project, logger=None):
21532155
"""Map ELF binaries to their sources in ``project``."""
2154-
from_resources = project.codebaseresources.files().from_codebase().filter(extension__endswith=".pyx")
2156+
from_resources = (
2157+
project.codebaseresources.files()
2158+
.from_codebase()
2159+
.filter(extension__endswith=".pyx")
2160+
)
21552161
to_resources = (
21562162
project.codebaseresources.files().to_codebase().has_no_relation().elfs()
21572163
)
@@ -2165,14 +2171,23 @@ def map_python_pyx_to_binaries(project, logger=None):
21652171
logger(f"Error parsing binary symbols at: {resource.location_path!r} {e!r}")
21662172

21672173
for resource in from_resources:
2174+
# open Cython source file, create AST, parse it for function definitions
2175+
# and save them in a list
21682176
tree, _ = get_tree(resource.location)
2169-
function_definitions = [node for node in tree.root_node.children if node.type == "function_definition"]
2177+
function_definitions = [
2178+
node
2179+
for node in tree.root_node.children
2180+
if node.type == "function_definition"
2181+
]
21702182
identifiers = []
21712183
for node in function_definitions:
21722184
for child in node.children:
21732185
if child.type == "identifier":
21742186
identifiers.append(child.text.decode())
21752187

2188+
# Find matching to/ resource by checking to see which to/ resource's
2189+
# extra_data field contains function definitions found from Cython
2190+
# source files
21762191
identifiers_qs = Q()
21772192
for identifier in identifiers:
21782193
identifiers_qs |= Q(extra_data__icontains=identifier)

0 commit comments

Comments
 (0)