4747from go_inspector .plugin import collect_and_parse_symbols
4848from packagedcode .npm import NpmPackageJsonHandler
4949from rust_inspector .binary import collect_and_parse_rust_symbols
50- from summarycode .classify import LEGAL_STARTS_ENDS
5150from source_inspector .symbols_tree_sitter import get_tree
51+ from summarycode .classify import LEGAL_STARTS_ENDS
5252
5353from aboutcode .pipeline import LoopProgress
5454from 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
21522154def 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