-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A new output format suitable for the tsort utility. #23
Comments
I'm intrigued by the idea of allowing the -l argument to be interpreted. However, I'm confused by your example. What do you expect |
Sorry, that was a mistake, I've fixed it in the main issue text. The correct invocation was
|
Implemented this locally by allowing formatting for -d and -l. I noticed that while it works for core, it fails for extra because there exist packages which have no dependencies, i.e.
In this case, tsort refuses to process the input because there's not a valid edge. I'm not sure this invalidates the patch, but it complicates your use case. |
Yeah, it does make things a bit more complex. It can probably be scripted around but not ideal. This is probably a terrible idea, but perhaps if edit: Of course, by mixing content and structure like this you will basically assume no key or object can be "null" in jshon's case. |
Could it maybe be an idea to just insert the package name itself as a dependency if it contains none? This appears to work with
|
Actually with a bit of thinking, combining ESR's notes on DSVs I've instead used expac to print a nice awk friendly format, such that This can be trivially parsed with p = $1
# If we find that a package contains no dependency, make it a
# dependency of itself to provide tsort a complete graph.
if($2 == ""){
$2 = $1
}
for(i = 0; i <= NF; ++i){
print p, $i
} This appears to work on every repo in Arch Linux but I'm unsure of it's correctness. For science, here is a compressed version of the script I am testing it with: expac -S '%n:%E' -l ':' < <(pacman -Sql extra) | awk -F : '{p=$1; if($2==""){$2=$1}; for(i=0; i<=NF;++i){print p, $i}}' | uniq | tsort > /dev/null If this is valid, this bug can be closed as invalid. |
While awk can be used to circumvent the issue, it would still be nice to have an option like --isempty to replace empty fields. For example, to account for packages without dependency:
Together with the suggested format support for
Alternatively you could do something like |
I'm not clear on what you're suggesting. What would the arg to --isempty be replacing? What is it which is "empty" that would trigger this behavior? |
I think what would be nice is a way to prefix the output, using expac in a pipeline can be awkward due to the format of its output when it comes to multiple items. For example, I'm not really sure how to design this whole thing and I think expac will always be used along with a filter for most uses, so if we could somehow get a column based output such as:
If in the above there turns out to be nothing to satisfy '%E' then it's fine too because even a read loop which as while read -r name dep; do
if [[ ! $dep ]]; then
dep=$name
fi
...
done could easily handle it. Of course the trade-off here is that it assumes But I don't really know exactly how to define a general command-line or approach where this will work, perhaps allowing formatters in An example such as Of course the trade-off here is you now have in-band data, but I've made use of it in some cases because I can guarantee that certain values which I use for sentinels can never be the string "null" which neatly allowed me to skip any real kind of validation which would have being complex and annoying. In the case of |
On a side note, I noticed a while ago you can use
|
I currently have some code which outputs packages along with their dependencies in a format that can be used by
tsort
. However this is slow because it appears I have to runexpac
for each package in the list. E.g.It would be really nice if I could use
expac -Sl '\n%n' '%n %E' "${packages[@]}"
instead where the string-l
accepts is formatter aware, e.g.:However as you can see, the
%n
is inserted literally.This would make for example, doing cycle detection really simple:
The other benefit of this would be to make building associative arrays easier too: (obviously substituting
%n
with the appropriate expansion.)The command-line syntax by repurposing
-l
is perhaps a little less pretty but it does seem to get pretty close to providing this functionality.What are your thoughts?
The text was updated successfully, but these errors were encountered: