MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / _parse

Function _parse

src/packagedcode/recognize.py:71–164  ·  view source on GitHub ↗

Yield parsed PackageData objects from ``location``. Raises Exceptions on errors. Use the provided ``datafile_handlers`` list of DatafileHandler classes. Default to use application packages

(
    location,
    application=True,
    system=False,
    compiled=False,
    package_only=False,
)

Source from the content-addressed store, hash-verified

69
70
71def _parse(
72 location,
73 application=True,
74 system=False,
75 compiled=False,
76 package_only=False,
77):
78 """
79 Yield parsed PackageData objects from ``location``. Raises Exceptions on errors.
80
81 Use the provided ``datafile_handlers`` list of DatafileHandler classes.
82 Default to use application packages
83 """
84
85 package_path = as_posixpath(location)
86 package_patterns = get_cache()
87
88 has_patterns = application or system or package_only
89 assert has_patterns or compiled
90 if package_only or (application and system):
91 package_matcher = package_patterns.all_package_matcher
92 elif application:
93 package_matcher = package_patterns.application_package_matcher
94 elif system:
95 package_matcher = package_patterns.system_package_matcher
96
97 matched_patterns = []
98 if has_patterns:
99 matched_patterns = package_matcher.match(package_path)
100
101 all_handler_ids = []
102 for matched_pattern in matched_patterns:
103 regex, _match = matched_pattern
104 handler_ids = package_patterns.handler_by_regex.get(regex.pattern)
105 if TRACE:
106 logger_debug(f'_parse:.handler_ids: {handler_ids}')
107
108 all_handler_ids.extend([
109 handler_id
110 for handler_id in handler_ids
111 if handler_id not in all_handler_ids
112 ])
113
114 datafile_handlers = [
115 HANDLER_BY_DATASOURCE_ID.get(handler_id)
116 for handler_id in all_handler_ids
117 ]
118
119 if not datafile_handlers:
120 if compiled:
121 datafile_handlers.extend(PACKAGE_IN_COMPILED_DATAFILE_HANDLERS)
122 elif TRACE:
123 logger_debug(f'_parse: no package datafile detected at {package_path}')
124
125 for handler in datafile_handlers:
126 if TRACE:
127 logger_debug(f'_parse:.is_datafile: {handler}')
128

Callers 1

recognize_package_dataFunction · 0.70

Calls 7

as_posixpathFunction · 0.90
get_cacheFunction · 0.90
matchMethod · 0.80
logger_debugFunction · 0.70
getMethod · 0.65
is_datafileMethod · 0.45
parseMethod · 0.45

Tested by

no test coverage detected