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

Function parse_apkbuild_text

src/packagedcode/alpine.py:745–781  ·  view source on GitHub ↗

Return a PackageData object from an APKBUILD text context or None. Only consider variables with a name listed in the ``names`` set. If ``strict`` is True, raise ApkbuildParseFailure error if any attribute value cannot be fully resolved for shell variables.

(text, datasource_id, package_type, strict=False, package_only=False)

Source from the content-addressed store, hash-verified

743
744
745def parse_apkbuild_text(text, datasource_id, package_type, strict=False, package_only=False):
746 """
747 Return a PackageData object from an APKBUILD text context or None. Only
748 consider variables with a name listed in the ``names`` set.
749
750 If ``strict`` is True, raise ApkbuildParseFailure error if any attribute
751 value cannot be fully resolved for shell variables.
752 """
753 if not text:
754 return
755
756 variables, errors = get_apkbuild_variables(text=text)
757 unresolved = [
758 v for v in variables
759 if not v.is_resolved()
760 and v.name in ESSENTIAL_APKBUILD_VARIABLES
761 ]
762
763 if strict and unresolved:
764 raise ApkbuildParseFailure(
765 f'Failed to parse APKBUILD: {text}\n\n'
766 f'variables: {variables}\n\n'
767 f'unresolved: {unresolved}\n\n'
768 f'errors: {errors}',
769 )
770 variables = ((v.name, v.value,) for v in variables)
771 package = build_package_data(
772 variables,
773 datasource_id=datasource_id,
774 package_type=package_type,
775 package_only=package_only,
776 )
777
778 if package and unresolved:
779 unresolved = [v.to_dict() for v in unresolved]
780 package.extra_data['apkbuild_variable_resolution_errors'] = unresolved
781 return package
782
783
784def parse_pkginfo(location):

Callers 1

parse_apkbuildFunction · 0.85

Calls 5

get_apkbuild_variablesFunction · 0.85
is_resolvedMethod · 0.80
build_package_dataFunction · 0.70
to_dictMethod · 0.45

Tested by

no test coverage detected