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)
| 743 | |
| 744 | |
| 745 | def 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 | |
| 784 | def parse_pkginfo(location): |
no test coverage detected