pkg-query: support evaluation of complex attributes (lists) #2591
+147
−8
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds support for evaluating complex attributes (multiline variables like dependencies, categories, etc.) within the
pkg query -eevaluation strings.Previously, it was not possible to filter packages based on list-type attributes directly in the query evaluation. This change allows users to perform queries such as finding packages that depend on a specific library or belong to a certain category.
Changes
EXISTS/NOT EXISTSoperators to support list attributes.=and!=).Supported Attributes
The following attributes are now supported in evaluation strings:
%d[nov]: Dependencies (Name, Origin, Version)%r[nov]: Reverse dependencies (Name, Origin, Version)%C: Categories%L: Licenses%B: Required shared libraries%b: Provided shared libraries%A[tv]: Annotations (Tag, Value)Example Usage
List packages that depend on
python312:pkg query -e '%dn = "python312"' %o
List packages that do not depend on
curl:pkg query -e '%dn != "curl"' %o
Note
The following attributes were intentionally omitted as their use cases in evaluation strings are unclear:
%F)%S,%D)%O)%U,%G)