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

Function dump_skinny_rule

etc/scripts/licenses/buildrules.py:227–256  ·  view source on GitHub ↗

Return a string that dumps the ``rule`` Rule in the input format used by this tool. Add a comment with the ``error_message`` to the metadata if any.

(rule, error_messages=())

Source from the content-addressed store, hash-verified

225
226
227def dump_skinny_rule(rule, error_messages=()):
228 """
229 Return a string that dumps the ``rule`` Rule in the input format used by
230 this tool. Add a comment with the ``error_message`` to the metadata if any.
231 """
232 metadata = rule.to_dict()
233 if error_messages:
234 # add missing metadata for sanity
235 if "license_expression" not in metadata:
236 m = {"license_expression": None}
237 m.update(metadata)
238 metadata = m
239
240 if "notes" not in metadata:
241 metadata["notes"] = None
242
243 if "referenced_filenames" not in metadata:
244 metadata["referenced_filenames"] = None
245
246 msgs = "\n".join(f"# {m}" for m in error_messages)
247 end_delimiter = f"{msgs}\n---"
248 else:
249 end_delimiter = "---"
250
251 return frontmatter.dumps_frontmatter(
252 content=rule.text,
253 metadata=metadata,
254 template=SKINNY_RULE_TEMPLATE,
255 start_delimiter=start_delimiter,
256 end_delimiter=end_delimiter)
257
258
259@click.command()

Callers 1

Calls 3

to_dictMethod · 0.45
updateMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected