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

Function build_facets

src/summarycode/facet.py:172–208  ·  view source on GitHub ↗

Return: - a mapping for facet patterns to a list of unique facet names as {pattern: [facet, facet, ...]} - a sorted list of error messages for invalid or unknown facet definitions found in `facets`. The `known` facets set of known facets is used for validation.

(facets, known_facet_names=FACETS)

Source from the content-addressed store, hash-verified

170
171
172def build_facets(facets, known_facet_names=FACETS):
173 """
174 Return:
175 - a mapping for facet patterns to a list of unique facet names as
176 {pattern: [facet, facet, ...]}
177 - a sorted list of error messages for invalid or unknown facet definitions
178 found in `facets`.
179 The `known` facets set of known facets is used for validation.
180 """
181 invalid_facet_definitions = set()
182 facet_patterns = defaultdict(list)
183 for facet_def in facets:
184 facet, _, pattern = facet_def.partition('=')
185 facet = facet.strip().lower()
186 pattern = pattern.strip()
187
188 if not pattern:
189 invalid_facet_definitions.add(
190 'missing <pattern> in "{facet_def}".'.format(**locals()))
191 continue
192
193 if not facet:
194 invalid_facet_definitions.add(
195 'missing <facet> in "{facet_def}".'.format(**locals()))
196 continue
197
198 if facet not in known_facet_names:
199 invalid_facet_definitions.add(
200 'unknown <facet> in "{facet_def}".'.format(**locals()))
201 continue
202
203 facets = facet_patterns[pattern]
204
205 if facet not in facets:
206 facet_patterns[pattern].append(facet)
207
208 return facet_patterns, sorted(invalid_facet_definitions)

Callers 2

validate_facetsFunction · 0.85
process_codebaseMethod · 0.85

Calls 3

addMethod · 0.80
formatMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected