This can be simplified a lot:

- a package cannot have several dependencies with the same target (see how they are defined), so you will never have several packages with the same target and the same source, so using an array of versions is useless (and the version is defined outside the loop anyway)
- you don't use the pretty version in the template at all